protected virtual PersistentPropertyCollection UpdateOrCreatePropertyCollection(Guid collectionId, ProcessDbContext ctx, List <PersistentSchemaElement> schemaElements, List <PersistentPropertyElement> dataElements) { PersistentPropertyCollection persistancePropertyCollection = ctx.PropertySet.Find(collectionId); if (persistancePropertyCollection == null) { ctx.PropertySet.Add(persistancePropertyCollection = new PersistentPropertyCollection { Id = collectionId, Schemas = schemaElements, Elements = dataElements }); } else { schemaElements.ForEach( s => persistancePropertyCollection.Schemas.FirstOrDefault(c => c.SchemaName == s.SchemaName)? .CopyFrom(s)); dataElements.ForEach( e => persistancePropertyCollection.Elements.FirstOrDefault(c => c.Name == e.Name)?.CopyFrom(e)); } return(persistancePropertyCollection); }
/// <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)); }
private static PersistentPropertyCollection CreatePersistentPropertyCollection(IProcessRuntime runtime, IPropertySetCollection collection) { List <PersistentSchemaElement> schemaElements; List <PersistentPropertyElement> dataElements; collection.CreatePersistentSchemaElements(out schemaElements, out dataElements); PersistentPropertyCollection persistedCollection = new PersistentPropertyCollection { Id = runtime.Id, Version = 1, Elements = dataElements, Schemas = schemaElements }; return(persistedCollection); }