internal static PersistedExecutionError ToPersistable(this ExecutionError instance)
        {
            var result = new PersistedExecutionError();

            result.ErrorTime          = instance.ErrorTime;
            result.Message            = instance.Message;
            result.ExecutionPointerId = instance.ExecutionPointerId;
            result.WorkflowId         = instance.WorkflowId;

            return(result);
        }
Esempio n. 2
0
        internal static PersistedWorkflow ToPersistable(this WorkflowInstance instance, PersistedWorkflow persistable = null)
        {
            if (persistable == null)
            {
                persistable = new PersistedWorkflow();
            }

            persistable.Data                 = JsonConvert.SerializeObject(instance.Data, SerializerSettings);
            persistable.Description          = instance.Description;
            persistable.InstanceId           = new Guid(instance.Id);
            persistable.NextExecution        = instance.NextExecution;
            persistable.Version              = instance.Version;
            persistable.WorkflowDefinitionId = instance.WorkflowDefinitionId;
            persistable.Status               = instance.Status;
            persistable.CreateTime           = instance.CreateTime;
            persistable.CompleteTime         = instance.CompleteTime;

            foreach (var ep in instance.ExecutionPointers)
            {
                var persistedEP = persistable.ExecutionPointers.FirstOrDefault(x => x.Id == ep.Id);

                if (persistedEP == null)
                {
                    persistedEP = new PersistedExecutionPointer();
                    persistable.ExecutionPointers.Add(persistedEP);
                }

                persistedEP.Id              = ep.Id ?? Guid.NewGuid().ToString();
                persistedEP.StepId          = ep.StepId;
                persistedEP.Active          = ep.Active;
                persistedEP.SleepUntil      = ep.SleepUntil;
                persistedEP.PersistenceData = JsonConvert.SerializeObject(ep.PersistenceData, SerializerSettings);
                persistedEP.StartTime       = ep.StartTime;
                persistedEP.EndTime         = ep.EndTime;
                persistedEP.StepName        = ep.StepName;
                persistedEP.EventName       = ep.EventName;
                persistedEP.EventKey        = ep.EventKey;
                persistedEP.EventPublished  = ep.EventPublished;
                persistedEP.ConcurrentFork  = ep.ConcurrentFork;
                persistedEP.PathTerminator  = ep.PathTerminator;
                persistedEP.EventData       = JsonConvert.SerializeObject(ep.EventData, SerializerSettings);

                foreach (var attr in ep.ExtensionAttributes)
                {
                    var persistedAttr = persistedEP.ExtensionAttributes.FirstOrDefault(x => x.AttributeKey == attr.Key);
                    if (persistedAttr == null)
                    {
                        persistedAttr = new PersistedExtensionAttribute();
                        persistedEP.ExtensionAttributes.Add(persistedAttr);
                    }

                    persistedAttr.AttributeKey   = attr.Key;
                    persistedAttr.AttributeValue = JsonConvert.SerializeObject(attr.Value, SerializerSettings);
                }

                foreach (var err in ep.Errors)
                {
                    var persistedErr = persistedEP.Errors.FirstOrDefault(x => x.Id == err.Id);
                    if (persistedErr == null)
                    {
                        persistedErr           = new PersistedExecutionError();
                        persistedErr.Id        = err.Id ?? Guid.NewGuid().ToString();
                        persistedErr.ErrorTime = err.ErrorTime;
                        persistedErr.Message   = err.Message;
                        persistedEP.Errors.Add(persistedErr);
                    }
                }
            }

            return(persistable);
        }