Skip to content

Commit

Permalink
Merge pull request danielgerlag#1271 from michalkrzych/bugfix/1270-de…
Browse files Browse the repository at this point in the history
…serialisation-duplication

danielgerlag#1270 Fixed list items deserialization duplication
  • Loading branch information
danielgerlag authored Aug 2, 2024
2 parents a761d78 + cb7a692 commit b70eccc
Showing 1 changed file with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ namespace WorkflowCore.Persistence.EntityFramework
{
internal static class ExtensionMethods
{
private static JsonSerializerSettings SerializerSettings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All };
private static JsonSerializerSettings SerializerSettings = new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.All,
ObjectCreationHandling = ObjectCreationHandling.Replace
};

internal static PersistedWorkflow ToPersistable(this WorkflowInstance instance, PersistedWorkflow persistable = null)
{
if (persistable == null)
persistable = new PersistedWorkflow();
if (persistable == null)
persistable = new PersistedWorkflow();

persistable.Data = JsonConvert.SerializeObject(instance.Data, SerializerSettings);
persistable.Description = instance.Description;
Expand All @@ -25,19 +29,19 @@ internal static PersistedWorkflow ToPersistable(this WorkflowInstance instance,
persistable.WorkflowDefinitionId = instance.WorkflowDefinitionId;
persistable.Status = instance.Status;
persistable.CreateTime = instance.CreateTime;
persistable.CompleteTime = instance.CompleteTime;
persistable.CompleteTime = instance.CompleteTime;

foreach (var ep in instance.ExecutionPointers)
{
var persistedEP = persistable.ExecutionPointers.FindById(ep.Id);

if (persistedEP == null)
{
persistedEP = new PersistedExecutionPointer();
persistedEP.Id = ep.Id ?? Guid.NewGuid().ToString();
persistable.ExecutionPointers.Add(persistedEP);
}
}

persistedEP.StepId = ep.StepId;
persistedEP.Active = ep.Active;
persistedEP.SleepUntil = ep.SleepUntil;
Expand Down Expand Up @@ -83,7 +87,7 @@ internal static PersistedWorkflow ToPersistable(this WorkflowInstance instance,

internal static PersistedExecutionError ToPersistable(this ExecutionError instance)
{
var result = new PersistedExecutionError();
var result = new PersistedExecutionError();
result.ErrorTime = instance.ErrorTime;
result.Message = instance.Message;
result.ExecutionPointerId = instance.ExecutionPointerId;
Expand All @@ -94,7 +98,7 @@ internal static PersistedExecutionError ToPersistable(this ExecutionError instan

internal static PersistedSubscription ToPersistable(this EventSubscription instance)
{
PersistedSubscription result = new PersistedSubscription();
PersistedSubscription result = new PersistedSubscription();
result.SubscriptionId = new Guid(instance.Id);
result.EventKey = instance.EventKey;
result.EventName = instance.EventName;
Expand All @@ -106,7 +110,7 @@ internal static PersistedSubscription ToPersistable(this EventSubscription insta
result.ExternalToken = instance.ExternalToken;
result.ExternalTokenExpiry = instance.ExternalTokenExpiry;
result.ExternalWorkerId = instance.ExternalWorkerId;

return result;
}

Expand Down Expand Up @@ -152,7 +156,7 @@ internal static WorkflowInstance ToWorkflowInstance(this PersistedWorkflow insta

foreach (var ep in instance.ExecutionPointers)
{
var pointer = new ExecutionPointer();
var pointer = new ExecutionPointer();

pointer.Id = ep.Id;
pointer.StepId = ep.StepId;
Expand Down

0 comments on commit b70eccc

Please sign in to comment.