//Fetch all the steps using a specified Database Connection Name. //The databaseConnectionName parameter will become a step input. //The step will return an array of step names and the table they connect to public string[] FetchStepsUsingDbConnection(string databaseConnectionName) { //Create the results list to return List<string> stepResultsList = new List<string>(); //Use the ORM to get all FLOW element registrations ElementRegistration[] allFlows = new ORM<ElementRegistration>().Fetch(new WhereCondition[] { new FieldWhereCondition("is_flow", QueryMatchType.Equals, true), }); //Loop through each flow foreach (ElementRegistration reg in allFlows) { //Open the flow Flow flow = FlowEngine.LoadFlowByID(reg.ComponentRegistrationId, false, true); FlowStep currentStep = null; try { //Loop through each step in the current flow foreach (FlowStep step in flow.Steps) { currentStep = step; //If the step is a GetAllStep, Process it if (step.FlowStepType.Equals("GetAllStep`1")) { //Cast the step.WrappedStep into the appropriate step type. GetAllStep<DatabaseTableDefinition> getAllStep = (GetAllStep<DatabaseTableDefinition>) step.WrappedStep; //If the step is on the appropriate connection, add it to the results. if (string.Equals(getAllStep.DBConnectionName, databaseConnectionName)) { stepResultsList.Add("Flow Name: " + flow.Name + " | Step Name: " + step.Name + " | DB Connection Name: " + getAllStep.DBConnectionName + " | Table Name: " + getAllStep.TableName); } } } } catch (Exception ex) { if (flow != null && currentStep != null) { stepResultsList.Add("Failed | Flow Name: " + flow.Name + " | Step Name: " + currentStep.Name); } if (flow != null) { _log.Error(ex, "Error processing steps for Flow: " + flow.Name + " with ID: " + flow.Id); } } } return stepResultsList.ToArray(); }
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"); } } } }