public void TestSimpleFork() { var eng = new FlowEngine(); countGood = 0; countBad = 0; eng.Start(a => GoodStep(a)) .ContinueWith(a => BadStep(a)) .Where(new TupleList <Func <FlowStep, bool>, Action <FlowStep> > { { a => a.Result.ResultCode == FlowStepResultValues.Success, a => BadStep(a) }, { a => a.Result.ResultCode == FlowStepResultValues.Failed, a => GoodStep(a) } }) .IfAllSuccess(b => GoodStep(b)); Assert.AreEqual(3, countGood); Assert.AreEqual(1, countBad); Assert.AreEqual(countGood + countBad, eng.Steps.Count); Assert.AreEqual(countGood, eng.Steps.Count - countBad); Assert.AreEqual(countBad, eng.Steps.Count - countGood); Assert.IsFalse(eng.AllWasGood()); Assert.IsTrue(eng.SomethingWasWrong()); }
public void TestSimpleFlow() { var eng = new FlowEngine(); countGood = 0; countBad = 0; eng.Start(a => GoodStep(a)) .ContinueWith(a => GoodStep(a)) .ContinueWith(a => GoodStep(a)); Assert.AreEqual(countGood, eng.Steps.Count); Assert.IsTrue(eng.AllWasGood()); }
public void TestCountBad() { var eng = new FlowEngine(); countGood = 0; countBad = 0; eng.Start(a => GoodStep(a)) .ContinueWith(a => BadStep(a)) .ContinueWith(a => GoodStep(a)); Assert.AreEqual(countGood + countBad, eng.Steps.Count); Assert.AreEqual(countGood, eng.Steps.Count - countBad); Assert.AreEqual(countBad, eng.Steps.Count - countGood); Assert.IsFalse(eng.AllWasGood()); Assert.IsTrue(eng.SomethingWasWrong()); }
public void TestSimpleCondition() { var eng = new FlowEngine(); countGood = 0; countBad = 0; eng.Start(a => GoodStep(a)) .ContinueWith(a => BadStep(a)) .IfSuccess(a => GoodStep(a)) // This will never be executed .IfFailed(a => GoodStep(a)); // This will never be executed Assert.AreEqual(1, countGood); Assert.AreEqual(countGood + countBad, eng.Steps.Count); Assert.AreEqual(countGood, eng.Steps.Count - countBad); Assert.AreEqual(countBad, eng.Steps.Count - countGood); Assert.IsFalse(eng.AllWasGood()); Assert.IsTrue(eng.SomethingWasWrong()); }
public void TestRealFlow() { var eng = new FlowEngine(); countGood = 0; countBad = 0; eng.Start(a => GoodStep(a)) .ContinueWith(a => GoodStep(a)) .ContinueWith(a => GoodStep(a)) .ContinueWith(a => { GoodStep(a); eng.Start(b => GoodStep(b)) .IfSuccess(b => GoodStep(b)) .ContinueWith(b => GoodStep(b)); eng.Start(b => GoodStep(b)) .ContinueWith(b => GoodStep(b)); eng.Start(b => GoodStep(b)) .IfSuccess(b => GoodStep(b)); }) .ContinueWith(a => { GoodStep(a); eng.Start(b => GoodStep(b)) .ContinueWith(b => GoodStep(b)) .ContinueWith(b => GoodStep(b)) .ContinueWith(b => GoodStep(b)) .ContinueWith(b => GoodStep(b)); eng.Start(b => GoodStep(b)) .IfSuccess(b => GoodStep(b)) .ContinueWith(b => GoodStep(b)) .ContinueWith(b => GoodStep(b)); eng.Start(b => GoodStep(b)) .IfSuccess(b => GoodStep(b)) .ContinueWith(b => GoodStep(b)) .ContinueWith(b => GoodStep(b)); }); Assert.AreEqual(countGood, eng.Steps.Count); Assert.IsTrue(eng.AllWasGood()); }
public void TestSubFlowAffectingResultOfMainFlow() { var eng = new FlowEngine(); countGood = 0; countBad = 0; eng.Start((a) => { GoodStep(a); }) .IfSuccess((a) => { var seng = new FlowEngine(); GoodStep(a); seng.Start((b) => { BadStep(b); }) .ContinueWith((b) => { GoodStep(b); }) .ContinueWith((b) => { GoodStep(b); }); if (!seng.AllWasGood()) { a.Result.ResultCode = FlowStepResultValues.Failed; //I am affecting the result of the task } }) .IfSuccess((a) => { GoodStep(a); }); Assert.IsFalse(eng.AllWasGood()); Assert.AreEqual(countGood, 4); Assert.AreEqual(countBad, 1); }
private void SetValues(string opcServerUrl, string eventId, BaseTagValueWrapper valuesWrapper) { BaseTagValue[] values = valuesWrapper.Values; using (UserContextHolder.Register(new SystemUserContext())) { Folder configFolder = EntityCache <OPCServerFolderBehaviorData> .GetCache().AllEntities.FirstOrDefault(s => s.Url == opcServerUrl)?.GetEntity() as Folder; if (configFolder == null) { return; } Array.ForEach(values, tagValue => { LOG.Debug($"Value Change: {tagValue.Path} - {TagValueUtils.GetObjectValueFromTag(tagValue)}"); }); // put values in last cache foreach (var v in values) { string key = eventId + "|" + v.Path; BaseTagValue priorValue; OPCEngine.mostRecentValues.TryGetValue(key, out priorValue); OPCEngine.mostRecentValues[key] = v; if (priorValue == null) { OPCEngine.priorValues[key] = v; } else { OPCEngine.priorValues[key] = priorValue; } } OPCEvent opcEvent = opcEventOrm.Fetch(eventId); if (opcEvent == null || opcEvent.Disabled) { return; } bool runIt = false; // see if this event is interested in this change foreach (var v in opcEvent.EventValues) { if (values.FirstOrDefault(changedValue => changedValue.Path == v.PathToValue) != null) { runIt = true; break; } } if (runIt) { try { List <DataPair> inputs = new List <DataPair>(); foreach (var v in opcEvent.EventValues) { string key = eventId + "|" + v.PathToValue; BaseTagValue value = null; OPCEngine.mostRecentValues.TryGetValue(key, out value); inputs.Add(new DataPair(v.Name, value)); BaseTagValue priorvalue = null; OPCEngine.priorValues.TryGetValue(key, out priorvalue); inputs.Add(new DataPair("Last " + v.Name, priorvalue)); } inputs.Add(new DataPair("LastWorkflowRun", opcEvent.LastRun)); // check rule to see if it matches var ruleResult = RuleEngine.RunRule(opcEvent.Rule, inputs.ToArray()); if (ruleResult != null && ruleResult is bool) { if (((bool)ruleResult) == true) { new Log("OPC").Error("Value Changed And Rule Returned True - running flow"); FlowEngine.Start(FlowEngine.LoadFlowByID(opcEvent.Flow, false, true), new FlowStateData(inputs.ToArray())); } else { new Log("OPC").Error("Value Changed But Rule Returned False"); } } else { new Log("OPC").Error("Value Changed But Rule Returned False"); } } catch (Exception except) { new Log("OPC").Error(except, "Error running flow from event"); } } } }