/// <summary> /// Initializes a new instance of the <see cref="ProcessRuntimeEnvironment"/> class. /// </summary> /// <param name="propertySet">The property set.</param> public ProcessRuntimeEnvironment( IProcessRuntime runtime, IPropertySetCollection propertySet) { ProcessRuntime = runtime; PropertySet = propertySet; }
/// <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> /// Unfreeze the process /// </summary> /// <param name="processRuntimeId"></param> /// <param name="runtime"></param> /// <param name="nextStep"></param> /// <param name="collection"></param> /// <returns></returns> public override bool TryUnfreeze(Guid processRuntimeId, out IProcessRuntime runtime, out StepRuntime nextStep, out IPropertySetCollection collection) { runtime = null; collection = null; nextStep = null; using (var ctx = new ProcessDbContext()) { var rtp = ctx.Process.Find(processRuntimeId); if (rtp == null) { return(false); } var definition = JsonConvert.DeserializeObject <ProcessDefinition>(rtp.ProcessDefinition.JsonProcessDefinition); definition.Id = rtp.ProcessDefinition.Id; collection = rtp.PropertyCollection.Deserialize(); if (!string.IsNullOrEmpty(rtp.NextStepId)) { StepDefinition stepDef = definition.Steps.Single(s => s.StepId == rtp.NextStepId); StepDefinitionId sid = new StepDefinitionId(stepDef.Id, stepDef.StepId); LinkDefinition[] links = definition.Links.Where(l => l.Source == sid).ToArray(); nextStep = new StepRuntime(stepDef, links.Select(l => new LinkRuntime(l)).ToArray()); } runtime = Create(rtp.Id, definition, rtp.SuspendedStepId, (ProcessStateEnum)rtp.Status); } return(true); }
/// <summary> /// Create Persistent Schema Elements /// </summary> /// <param name="collection"></param> /// <param name="schemaElements"></param> /// <param name="dataElements"></param> public static void CreatePersistentSchemaElements(this IPropertySetCollection collection, out List <PersistentSchemaElement> schemaElements, out List <PersistentPropertyElement> dataElements) { schemaElements = new List <PersistentSchemaElement>(); dataElements = new List <PersistentPropertyElement>(); foreach (var schema in collection.Schemas.Schemas) { SchemaJsonSerializationVisitor visitor = new SchemaJsonSerializationVisitor(); schema.Value.Accept(visitor); PersistentSchemaElement se = new PersistentSchemaElement { SchemaName = schema.Key, SchemaType = visitor.SchemaType.ToString(), SchemaBody = visitor.JsonValue, SerializationHint = (int)visitor.Hint }; schemaElements.Add(se); } foreach (string k in collection.Keys) { PersistentPropertyElement element = new PersistentPropertyElement { Name = k }; ValueSerializationTarget target = new ValueSerializationTarget(element); collection.Schemas.GetSchema(k).Serializer.Serialize(collection[k], target); dataElements.Add(element); } }
public void TestUpdatePropertyCollection() { PropertySchemaSet schemaSet = new PropertySchemaSet(new PropertySchemaFactory()); DateTime date = DateTime.Today; PropertySetCollection collection = new PropertySetCollection(schemaSet); collection.Add("v_int", new IntSchema()); collection.Add("v_string", new StringSchema()); collection.Add("v_date", new DateTimeSchema()); PropertySetPersistenceService persistenceService = new PropertySetPersistenceService(); Guid id = Guid.NewGuid(); persistenceService.SaveCollection(id, collection); IPropertySetCollection retrieved = persistenceService.FindCollection(id); Assert.IsNotNull(retrieved); Assert.IsNull(retrieved.Get <int?>("v_int")); Assert.AreEqual(DateTime.MinValue, retrieved.Get <DateTime?>("v_date")); Assert.IsNull(retrieved.Get <string>("v_string")); retrieved.Set("v_int", (int?)100); retrieved.Set("v_string", "hello"); retrieved.Set("v_date", (DateTime?)DateTime.Today); persistenceService.SaveCollection(id, retrieved); IPropertySetCollection retrieved1 = persistenceService.FindCollection(id); Assert.IsNotNull(retrieved1); Assert.AreEqual(100, retrieved1.Get <int?>("v_int")); Assert.AreEqual(DateTime.Today, retrieved1.Get <DateTime?>("v_date")); Assert.AreEqual("hello", retrieved1.Get <string>("v_string")); }
public void TestContainsKey() { IPropertySetCollection collection = GetCollection(); collection["key"] = "value"; Assert.IsTrue(collection.ContainsKey("key")); Assert.IsFalse(collection.ContainsKey("key1")); }
public void RemoveKeyValuePair() { KeyValuePair <string, object> item = new KeyValuePair <string, object>("1", "1"); IPropertySetCollection collection = GetCollection(); collection["1"] = 1; Assert.AreEqual(1, collection.Count); }
public void TestAddNullValueNoSchema() { IPropertySetCollection collection = GetCollection(); collection.Add("key", null); object value = collection.Get <object>("key"); Assert.IsNull(value); }
public void TestAddValue() { IPropertySetCollection collection = GetCollection(); collection.Add("key", "value"); object v = collection["key"]; Assert.IsNotNull(v); Assert.AreEqual("value", v); }
public void TestContainsKvPair() { KeyValuePair <string, object> item = new KeyValuePair <string, object>("key", "value"); IPropertySetCollection collection = GetCollection(); collection.Add(item); Assert.IsTrue(collection.Contains(item)); collection["key"] = "1"; Assert.IsFalse(collection.Contains(item)); }
public void TestCollectionCount() { IPropertySetCollection collection = GetCollection(); collection["1"] = 1; collection["2"] = 2; collection["3"] = 3; collection["4"] = 4; Assert.AreEqual(4, collection.Count); }
public void TestAddValueTypePropertyNoDefaultValueNotAllowNullWithValue() { IPropertySetCollection collection = GetCollection(); collection.Add("key", 100, new IntSchema()); int?value = collection.Get <int?>("key"); Assert.IsNotNull(value); Assert.AreEqual(100, value); }
public void TestAddStringValueNoSchema() { IPropertySetCollection collection = GetCollection(); collection.Add("key", "val"); string value = collection.Get <string>("key"); Assert.IsNotNull(value); Assert.AreEqual("val", value); }
public void TestAddStringPropertyNoDefaultValueNotAllowNullWithValue() { IPropertySetCollection collection = GetCollection(); collection.Add("key", "value", new StringSchema()); string value = collection.Get <string>("key"); Assert.IsNotNull(value); Assert.AreEqual("value", value); }
public void TestAddValueTypePropertyNoDefaultValueAllowNull() { IPropertySetCollection collection = GetCollection(); collection.Add("key", new IntSchema { AllowNull = true }); int?value = collection.Get <int?>("key"); Assert.IsFalse(value.HasValue); }
public void TestAddKeyValuePair() { KeyValuePair <string, object> item = new KeyValuePair <string, object>("key", "value"); IPropertySetCollection collection = GetCollection(); collection.Add(item); string s = collection.Get <string>("key"); Assert.IsNotNull(s); Assert.AreEqual("value", s); }
public ProcessRuntimeMemento(Guid id, Guid porcessDefinitionId, int processDefinitionVersion, IPropertySetCollection variables, Guid stepId, ProcessStateEnum status) { Id = id; PorcessDefinitionId = porcessDefinitionId; ProcessDefinitionVersion = processDefinitionVersion; Variables = variables; StepId = stepId; Status = status; }
public void TestSetNullValueNoSchema() { IPropertySetCollection collection = GetCollection(); collection["key"] = null; object value = collection.Get <object>("key"); Assert.IsNull(value); value = collection["key"]; Assert.IsNull(value); }
public void TestAddStringPropertyNoDefaultValueNotAllowNull() { IPropertySetCollection collection = GetCollection(); Assert.Throws <ArgumentException>(() => { collection.Add("key", new StringSchema { AllowNull = false }); }); }
public void TestAddStringPropertyNoDefaultValueAllowNull() { IPropertySetCollection collection = GetCollection(); collection.Add("key", new StringSchema { AllowNull = true }); string value = collection.Get <string>("key"); Assert.IsNull(value); }
/// <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(); } }
public void TestAddStringOutsideOfTheirAllowedValuesViaDictionary() { IPropertySetCollection collection = GetCollection(); collection.Add("key", new StringSchema { AllowNull = true, PossibleValues = new[] { "one", "two", "tree" } }); Assert.Throws <PropertyValidationException>(() => { collection.Set("key", "1"); }); }
public void TestStringSchemaValidationFailMaxValue() { IPropertySetCollection collection = GetCollection(); collection.Add("key", new StringSchema { AllowNull = true, MaxLength = 10, MinLength = 5 }); Assert.Throws <PropertyValidationException>(() => { collection.Set("key", "123456789012345"); }); }
public void TestAddValueTypeOutsideOfTheSetOfAllowedValuesViaDictionary() { IPropertySetCollection collection = GetCollection(); collection.Add("key", new IntSchema { AllowNull = true, PossibleValues = new int?[] { 2, 3, 4 } }); Assert.Throws <PropertyValidationException>(() => { collection.Set("key", (int?)1); }); }
public void TestValueTypeSchemaValidationFailMaxValue() { IPropertySetCollection collection = GetCollection(); collection.Add("key", new IntSchema { AllowNull = true, MaxValue = 10, MinValue = 5 }); Assert.Throws <PropertyValidationException>(() => { collection.Set("key", (int?)11); }); }
public void TestTryGetValue() { IPropertySetCollection collection = GetCollection(); collection.Add("key", "value"); object v; Assert.IsTrue(collection.TryGetValue("key", out v)); Assert.IsNotNull(v); Assert.AreEqual("value", v); Assert.IsFalse(collection.TryGetValue("key1", out v)); Assert.IsNull(v); }
/// <summary> /// Instantiate new process runtime /// </summary> /// <param name="pd"></param> /// <param name="collection"></param> /// <returns></returns> public virtual IProcessRuntime Create(ProcessDefinition pd, IPropertySetCollection collection) { IEnumerable <LinkRuntime> linkRuntimes = pd.Links.Select(ld => new LinkRuntime(ld)); IEnumerable <StepRuntime> stepRuntimes = pd.Steps.Select(sd => new StepRuntime(sd, linkRuntimes.Where(l => l.SourceStepId == sd.Id).ToArray())); IEnumerable <VariableRuntime> varRuntimes = pd.Variables.Select(vd => new VariableRuntime(vd)).ToList(); IEnumerable <TagRuntime> tagRuntimes = pd.Tags.Select(t => new TagRuntime(t)).ToList(); foreach (VariableDefinition variableDefinition in pd.Variables) { variableDefinition.SetupVariable(collection); } return(new ProcessRuntime(Guid.NewGuid(), linkRuntimes, stepRuntimes, varRuntimes, tagRuntimes)); }
public void TestSetStringValueNoSchema() { IPropertySetCollection collection = GetCollection(); collection["key"] = "val"; string value = collection.Get <string>("key"); Assert.IsNotNull(value); Assert.AreEqual("val", value); value = collection["key"] as string; Assert.IsNotNull(value); Assert.AreEqual("val", value); }
public void TestSValueTypeGetValueViaDictionary() { IPropertySetCollection collection = GetCollection(); collection.Add("key", new IntSchema { AllowNull = true }); collection.Set("key", (int?)100); object value = collection["key"]; Assert.IsNotNull(value); Assert.AreEqual(100, value); }
public void TestValueTypeSchemaValidationSuccess() { IPropertySetCollection collection = GetCollection(); collection.Add("key", new IntSchema { AllowNull = true, MaxValue = 10, MinValue = 5 }); collection.Set("key", (int?)6); int?value = collection.Get <int>("key"); Assert.IsNotNull(value); Assert.AreEqual(6, value); }