/// <summary> /// Create and persist runtime processor /// </summary> /// <param name="pd"></param> /// <param name="collection"></param> /// <returns></returns> /// <exception cref="NotImplementedException"></exception> public override IProcessRuntime Create(ProcessDefinition pd, IPropertySetCollection collection) { IProcessRuntime runtime = base.Create(pd, collection); Md5CalcVisitor visitor = new Md5CalcVisitor(); pd.Accept(visitor); string md5 = visitor.CalculateMd5(); using (var ctx = new ProcessDbContext()) { var pdList = ctx.ProcessDefinition .Where(p => p.FlowId == pd.FlowId && p.Md5 == md5).ToList(); if (pdList.Count() != 1) { throw new ArgumentException($"Process definition is not persisted."); } // save or update the collection PersistentPropertyCollection persistedCollection = _propertySepPersistenceService.SaveCollection(ctx, runtime.Id, collection); ProcessRuntimePersistence rtp = new ProcessRuntimePersistence { Id = runtime.Id, SuspendedStepId = runtime.LastExecutedStep?.StepId, Status = (int)runtime.State, LastUpdated = DateTime.UtcNow, PropertyCollection = persistedCollection, ProcessDefinition = pdList.ElementAt(0) }; ctx.Process.Add(rtp); ctx.SaveChanges(); } return(new ProcessRuntimePersistenProxy(runtime, this)); }
public override void Freeze(IProcessRuntime runtime, IPropertySetCollection collection) { using (var ctx = new ProcessDbContext()) { ProcessRuntimePersistence persistence = ctx.Process.Find(runtime.Id); if (persistence == null) { throw new ArgumentException("Invalid Workflow Id:" + runtime.Id.ToString()); } _propertySepPersistenceService.SaveCollection(ctx, runtime.Id, collection); persistence.Status = (int)runtime.State; persistence.LastUpdated = DateTime.UtcNow; persistence.SuspendedStepId = runtime.SuspendedInStep?.StepId; ctx.SaveChanges(); } }
protected virtual void OnExecute(IProcessRuntime runtime, Tuple <ExecutionResult, StepRuntime> result, IProcessRuntimeEnvironment env) { using (var ctx = new ProcessDbContext()) { ProcessRuntimePersistence persistence = ctx.Process.Find(runtime.Id); if (persistence == null) { throw new ArgumentException("Invalid Workflow Id:" + runtime.Id); } _propertySepPersistenceService.SaveCollection(ctx, runtime.Id, env.PropertySet); persistence.Status = (int)runtime.State; persistence.LastUpdated = DateTime.UtcNow; persistence.SuspendedStepId = runtime.SuspendedInStep?.StepId; persistence.NextStepId = runtime.State == ProcessStateEnum.Completed? null: result.Item2?.StepId; ctx.SaveChanges(); } }