public DecisionsFramework.Design.Flow.FlowStep ConvertStep(ConversionData allConvertData, ConvertedStep stepToConvert) { SystemUserContext suc = new SystemUserContext(); using (UserContextHolder.Register(suc)) { LinkedFlowStep lfs = new LinkedFlowStep(); // Get name of flow to run / id of flow to run. StepInput flowId = stepToConvert.StepProperties.FirstOrDefault(x => x.Name == "EmbeddedFlowId"); //string flowId = flowName.ConstantValue; //foreach (Flow cf in allConvertData.ConvertedFlows) //{ // if (cf.Name == flowName.ConstantValue) // { // flowId = cf.Id; // } //} lfs.RegistrationId = flowId.ConstantValue; return(new FlowStep(lfs)); } }
//Method to execute the specified flow a specified number of times. public void StartFlowExecution() { //Register the user using (UserContextHolder.Register(_userContext)) { //Create a stopwatch and kick it off, logging a guid to identify the batch of flow runs string threadExecutionId = System.Guid.NewGuid().ToString(); Stopwatch outerStopWatch = new Stopwatch(); Log.Error("Starting Thread: " + threadExecutionId + ", number of executions: " + _executions + ",flow: " + _flowId); outerStopWatch.Start(); //Kick off the specified flow executions with the Flow Engine for (int i = 0; i < _executions; i++) { //Create a stopwatch and kick it off, logging a guid to identify the individual flow run string flowExecutionId = System.Guid.NewGuid().ToString(); Stopwatch innerStopWatch = new Stopwatch(); Log.Error("Starting Flow Run: " + flowExecutionId); innerStopWatch.Start(); //Execute the flow with canned data FlowEngine.StartSyncFlow(FlowEngine.GetFlow(_flowId), GetFlowStateData()); //Stop the stopwatch and log how much time it took for the individual flow run innerStopWatch.Stop(); Log.Error("Flow Run " + flowExecutionId + " took: " + innerStopWatch.Elapsed.TotalMilliseconds + " milliseconds."); } //Stop the stopwatch and log how much time it took for the batch of flow runs outerStopWatch.Stop(); Log.Error("Thread: " + threadExecutionId + ", number of executions: " + _executions + ",flow: " + _flowId + ", took " + outerStopWatch.Elapsed.TotalSeconds + " seconds."); } }
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"); } } } }