/// <summary> /// Save process definition /// </summary> /// <param name="definition"></param> /// <param name="status"></param> /// <param name="version"></param> /// <param name="accounts">Security accounts that have access to the flow</param> public void Create(ProcessDefinition definition, ProcessDefStatusEnum status, int version, params AccountData[] accounts) { Md5CalcVisitor visitor = new Md5CalcVisitor(); definition.Accept(visitor); var accountsList = new List <ProcessDefinitionAccount>(); ProcessDefinitionPersistence pd = new ProcessDefinitionPersistence { Id = definition.Id, FlowId = definition.FlowId, Version = version, Name = definition.Name, Description = definition.Description, LastModified = DateTime.UtcNow, Status = (int)status, Md5 = visitor.CalculateMd5(), JsonProcessDefinition = JsonConvert.SerializeObject(definition), Accounts = accountsList }; try { using (var ctx = new ProcessDbContext()) { SetupAccounts(ctx, ctx.ProcessDefinition.Add(pd), accounts); ctx.SaveChanges(); } } catch (DbUpdateException ex) { throw new ArgumentException(ex.Message); } }
/// <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)); }
/// <summary> /// Create Security Account Records /// </summary> /// <param name="accounts"></param> public void CreateAccounts(params AccountData[] accounts) { using (var ctx = new ProcessDbContext()) { accounts.ToList().ForEach(a => ctx.Accounts.Add(a)); ctx.SaveChanges(); } }
/// <summary> /// Store the collection /// </summary> /// <param name="collectionId"></param> /// <param name="collection"></param> public void SaveCollection(Guid collectionId, IPropertySetCollection collection) { List <PersistentSchemaElement> schemaElements; List <PersistentPropertyElement> dataElements; collection.CreatePersistentSchemaElements(out schemaElements, out dataElements); using (ProcessDbContext ctx = new ProcessDbContext()) { UpdateOrCreatePropertyCollection(collectionId, ctx, schemaElements, dataElements); ctx.SaveChanges(); } }
/// <summary> /// Set or update status /// </summary> /// <param name="id"></param> /// <param name="version"></param> /// <param name="status"></param> public bool SetStatus(Guid id, int version, ProcessDefStatusEnum status) { using (var ctx = new ProcessDbContext()) { ProcessDefinitionPersistence pd = ctx.ProcessDefinition.Find(id, version); if (pd == null) { return(false); } pd.Status = (int)status; pd.LastModified = DateTime.UtcNow; ctx.SaveChanges(); return(true); } }
public void RemoveRoles(Guid id, int version, params AccountData[] accounts) { using (var ctx = new ProcessDbContext()) { ProcessDefinitionPersistence pd = ctx.ProcessDefinition.Find(id, version); if (pd == null) { throw new ArgumentException($"Process Definition id={id} version={version} not found."); } if (accounts != null) { SetupAccounts(ctx, pd, accounts); } ctx.SaveChanges(); } }
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(); } }