private void BuildLinkedNodes0(XElement elementCurrent, ref ProcessNode nodeCurrent, IDictionary <string, ProcessNode> nodes, ProcessInstance processInstance) { Console.WriteLine("nodeCurrent: " + nodeCurrent.NodeName + " " + nodeCurrent.NodeType); nodeCurrent.ProcessInstance = processInstance; var seq = NextSequences(elementCurrent, ProcessXML, NS); var nextElements = (seq.Any() ? seq : NextElement(elementCurrent, ProcessXML)); nodeCurrent.NextNodes = new List <ProcessNode>(); foreach (var elementNext in nextElements) { Console.WriteLine("n: " + elementNext.Attribute("id").Value + " " + elementNext.Name.LocalName); var nextNode = nodes[elementNext.Attribute("id").Value]; nodeCurrent.NextNodes.Add(nextNode); if (nextNode.PreviousNodes == null) { nextNode.PreviousNodes = new List <ProcessNode>(); } if (!nextNode.PreviousNodes.Contains(nodeCurrent)) { nextNode.PreviousNodes.Add(nodeCurrent); } BuildLinkedNodes0(elementNext, ref nextNode, nodes, processInstance); } }
void INodeHandler.Execute(ProcessNode processNode, ProcessNode previousNode) { Console.WriteLine(processNode.NodeName + " Executing Sequence"); bool result = true; if (processNode.Expression != null) { Console.WriteLine(processNode.NodeName + " Conditional Sequence"); Console.WriteLine("Condition: " + processNode.Expression); var globals = new Globals(processNode.InputParameters.ToDictionary(e => e.Key, e => e.Value)); try { result = CSharpScript.EvaluateAsync <bool>(processNode.Expression, globals: globals).Result; Console.WriteLine("Condition result: " + result.ToString()); } catch (Exception e) { Console.WriteLine(e.Message); } } if (result) { processNode.Done(); } }
internal void SetOutputParameters(ProcessNode node) { if (OutputParameters == null) { OutputParameters = ImmutableDictionary.Create <string, IImmutableDictionary <string, object> >(); } OutputParameters.Add(node.NodeName, node.OutputParameters); }
public void Execute(ProcessNode processNode, ProcessNode previousNode) { NodeHandler = ProcessInstance.NodeHandlers[NodeType]; if (processNode.InputParameters == null) { processNode.InputParameters = ProcessInstance.InputParameters; } Task = new t.Task(() => NodeHandler.Execute(processNode, previousNode)); Task.Start(); }
public void Serialize1StartNode(ProcessNode nodeStart) { Console.WriteLine("[" + nodeStart.NodeSerialNumber.ToString() + "]" + "\t" + "[" + nodeStart.NodeName + "]" ); Console.Write("IO: "); Serialize1IOParameters(nodeStart.InputParameters); Console.Write(","); Serialize1IOParameters(nodeStart.OutputParameters); }
void INodeHandler.Execute(ProcessNode processNode, ProcessNode previousNode) { Console.WriteLine(processNode.NodeName); sequenceWait.GetOrAdd(processNode, new List <ProcessNode>(processNode.PreviousNodes)); lock (sequenceWait[processNode]) { sequenceWait[processNode].Remove(previousNode); } if (sequenceWait[processNode].Count == 0) { processNode.Done(); } }
public ProcessInstance NewProcessInstance() { var current = ProcessXML.Element(NS + "startEvent"); var node = new ProcessNode(current.Attribute("id").Value, current.Name.LocalName); var nodes = BuildNodes(ProcessXML); var processInstance = new ProcessInstance(this); BuildLinkedNodes(current, ref node, nodes, processInstance); processInstance.Id = Guid.NewGuid().ToString(); processInstance.StartNode = node; processInstance.Nodes = nodes.ToImmutableDictionary(); return(processInstance); }
void INodeHandler.Execute(ProcessNode processNode, ProcessNode previousNode) { Console.WriteLine(processNode.NodeName + " Executing Script"); if (processNode.Expression != null) { Console.WriteLine("Script: " + processNode.Expression); var globals = new Globals(processNode.InputParameters.ToDictionary(e => e.Key, e => e.Value)); try { processNode.OutputParameters = CSharpScript.EvaluateAsync <IDictionary <string, object> >(processNode.Expression, globals: globals) .Result.ToImmutableDictionary(); } catch (Exception e) { Console.WriteLine(e.Message); } } processNode.Done(); }
private void BuildLinkedNodes(XElement current, ref ProcessNode node, IDictionary <string, ProcessNode> nodes, ProcessInstance processInstance) { node.ProcessInstance = processInstance; var seq = NextSequences(current, ProcessXML, NS); var next = (seq.Any() ? seq : NextElement(current, ProcessXML)); node.NextNodes = new List <ProcessNode>(); foreach (var n in next) { var nextNode = nodes[n.Attribute("id").Value]; if (nextNode.PreviousNodes == null) { nextNode.PreviousNodes = new List <ProcessNode>(); } if (!nextNode.PreviousNodes.Contains(node)) { nextNode.PreviousNodes.Add(node); } node.NextNodes.Add(nextNode); BuildLinkedNodes(n, ref nextNode, nodes, processInstance); } }
void INodeHandler.Execute(ProcessNode processNode, ProcessNode previousNode) { Console.WriteLine(processNode.NodeName + " Executing End"); processNode.ProcessInstance.SetOutputParameters(processNode); processNode.Done(); }
void INodeHandler.Execute(ProcessNode processNode, ProcessNode previousNode) { Console.WriteLine(processNode.NodeName + " Executing BusinessRule"); processNode.Done(); }
void INodeHandler.Execute(ProcessNode processNode, ProcessNode previousNode) { Console.WriteLine(processNode.NodeName); processNode.Done(); }
void INodeHandler.Execute(ProcessNode processNode, ProcessNode previousNode) { Console.WriteLine(processNode.NodeName + " Executing Exclusive Gateway (default)"); processNode.Done(); }
private IDictionary <string, ProcessNode> BuildNodes(XElement processXML) { //var nodes = processXML.Elements().ToDictionary(e => e.Attribute("id").Value, e => new ProcessNode(e.Attribute("id").Value, e.Name.LocalName)); var nodes = new Dictionary <string, ProcessNode>(); var elements = processXML.Elements(); Console.WriteLine("elements.Count:\t" + elements.Count().ToString()); foreach (var element in elements) { //Console.WriteLine(element.Name + " " + element.Name.LocalName + " " + element.Value); //var attrs = element.Attributes(); //foreach(var attr in attrs) //{ // Console.WriteLine(attr.Name + " " + attr.Value); //} string name = element.Name.LocalName; switch (name) { case "sequenceFlow": { string targetRef = (element.Attribute("targetRef") != null ? element.Attribute("targetRef").Value : "(null)"); Console.WriteLine("SEQ Supported: " + name + "\t" + element.Attribute("id").Value + "\t" + targetRef); ProcessNode pn = new ProcessNode(element.Attribute("id").Value, name); nodes.Add(element.Attribute("id").Value, pn); break; } case "startEvent": case "endEvent": case "task": case "userTask": case "serviceTask": case "scriptTask": case "businessRuleTask": case "scriptRuleTask": { string targetRef = (element.Attribute("targetRef") != null ? element.Attribute("targetRef").Value : "(null)"); Console.WriteLine("TASK Supported: " + name + "\t" + element.Attribute("id").Value + "\t" + targetRef); ProcessNode pn = new ProcessNode(element.Attribute("id").Value, name); nodes.Add(element.Attribute("id").Value, pn); break; } case "exclusiveGateway": case "inclusiveGateway": { string targetRef = (element.Attribute("targetRef") != null ? element.Attribute("targetRef").Value : "(null)"); Console.WriteLine("GATE Supported: " + name + "\t" + element.Attribute("id").Value + "\t" + targetRef); ProcessNode pn = new ProcessNode(element.Attribute("id").Value, name); nodes.Add(element.Attribute("id").Value, pn); break; } case "property": case "dataAssociation": case "extensionElements": case "participant": case "laneSet": case "messageFlow": case "parallelGateway": case "subProcess": case "callActivity": case "DataObject": case "TextAnnotation": case "assocation": case "dataStoreReference": { Console.WriteLine("Not supported: " + element.Name); break; } default: { Console.WriteLine("Unknown: " + element.Name); break; } } } nodes.Where(e => e.Value.NodeType == "property").Select(e => e.Key).ToList().ForEach(k => nodes.Remove(k)); var scripts = processXML.Elements().Elements(NS + "script") .Select(s => new { id = s.Parent.Attribute("id").Value, expression = s.Value }); foreach (var s in scripts) { nodes[s.id].Expression = s.expression; } var conditionExpressions = processXML.Elements().Elements(NS + "conditionExpression") .Select(c => new { id = c.Parent.Attribute("id").Value, expression = c.Value }); foreach (var c in conditionExpressions) { nodes[c.id].Expression = c.expression; } //Quick fix for zmq example //TODO Proper process var/assignment to node var mapping var taskExpressions = processXML.Elements(NS + "task").Elements(NS + "dataInputAssociation").Elements(NS + "assignment").Elements(NS + "from") .Select(e => new { id = e.Parent.Parent.Parent.Attribute("id").Value, expression = e.Value }); foreach (var e in taskExpressions) { nodes[e.id].Expression = e.expression; } return(nodes); }
public void Serialize1ProcessTemplate() { List <string> keys = new List <string>(); int[] ids = new int[this.Nodes.Count + 1]; foreach (string k in this.Nodes.Keys) { keys.Add(k); } int nIDs = 0; foreach (string k in this.Nodes.Keys) { ids[this.Nodes[k].NodeSerialNumber] = nIDs++; } foreach (string k in this.Nodes.Keys) { ProcessNode n = this.Nodes[k]; if (!NodeTypes.Contains(n.NodeType)) { NodeTypes.Add(n.NodeType); } n.NodeTypeSerialNumber = NodeTypes.IndexOf(n.NodeType); } Console.WriteLine("NodeTypes:\t[" + NodeTypes.Count.ToString() + "]"); foreach (string t in NodeTypes) { Console.WriteLine("[" + NodeTypes.IndexOf(t) + "]" + "\t" + "[" + t + "]" ); } Console.WriteLine("NodeNames:\t[" + this.Nodes.Count.ToString() + "]"); for (int i = 1; i <= this.Nodes.Count; i++) { int id = ids[i]; string k = keys[id]; ProcessNode n = this.Nodes[k]; Console.WriteLine("[" + n.NodeSerialNumber.ToString() + "]" + "\t" + "[" + n.NodeName + "]" ); } Console.WriteLine("NodeCodeGraph:\t[" + this.Nodes.Count.ToString() + "]"); for (int i = 1; i <= this.Nodes.Count; i++) { int id = ids[i]; string k = keys[id]; ProcessNode n = this.Nodes[k]; Console.Write("[" + n.NodeSerialNumber.ToString() + "]" + "\t" + "[" + n.NodeTypeSerialNumber.ToString() + "]" ); Console.Write(","); Console.Write("["); if (n.PreviousNodes != null) { bool firstItem2 = true; foreach (ProcessNode pn in n.PreviousNodes) { if (!firstItem2) { Console.Write(","); } firstItem2 = false; Console.Write(pn.NodeSerialNumber.ToString()); } } Console.Write("]"); Console.Write(","); Console.Write("["); if (n.NextNodes != null) { bool firstItem2 = true; foreach (ProcessNode nn in n.NextNodes) { if (!firstItem2) { Console.Write(","); } firstItem2 = false; Console.Write(nn.NodeSerialNumber.ToString()); } } Console.Write("]"); Console.WriteLine(); } Console.WriteLine("NodeIEO:\t[" + this.Nodes.Count.ToString() + "]"); for (int i = 1; i <= this.Nodes.Count; i++) { int id = ids[i]; string k = keys[id]; ProcessNode n = this.Nodes[k]; //fConsole.Write("Node,IEO: "); Console.Write("[" + n.NodeSerialNumber.ToString() + "]" ); Console.Write(","); Serialize1IOParameters(n.InputParameters); Console.Write(","); Serialize1Expression(n.Expression); Console.Write(","); Serialize1IOParameters(n.OutputParameters); Console.WriteLine(); } }