/// <summary> /// This method return the representation of all edge in the workflow for WFeditor /// </summary> /// <returns>All edge in the workflow</returns> public XmlDocument GetEdgesForWFE() { XmlDocument rsult = new XmlDocument(); XmlElement allEdges = rsult.CreateElement("EDGES", ""); rsult.AppendChild(allEdges); foreach (WFedgeLabel edgeId in connectionGraph.Edges) { WFedgeLabel edgeValue = edgeId; Triple <WFedgeLabel, WFnode, WFnode> edgeInfos = connectionGraph.GetConnectingNodes(edgeId); XmlElement singleEdgeNode = rsult.CreateElement("EDGE"); XmlAttribute aFrom = rsult.CreateAttribute("from"); XmlAttribute aTo = rsult.CreateAttribute("to"); aFrom.Value = XmlConvert.EncodeLocalName(edgeInfos.SecondMember.NodeTypeName); aTo.Value = XmlConvert.EncodeLocalName(edgeInfos.ThirdMember.NodeTypeName); singleEdgeNode.Attributes.Append(aFrom); singleEdgeNode.Attributes.Append(aTo); /*Appending preconditions and actions*/ singleEdgeNode.AppendChild(rsult.ImportNode(edgeValue.GetEntireDescription().DocumentElement, true)); allEdges.AppendChild(singleEdgeNode); } return(rsult); }
/// <summary> /// This method return the representation of all edge in the workflow /// </summary> /// <returns>All edge in the workflow</returns> public XmlDocument GetEdges() { XmlDocument rsult = new XmlDocument(); XmlElement allEdges = rsult.CreateElement("EDGES", ""); var attr = rsult.CreateAttribute("workflowName"); attr.Value = editedWf.WorkflowName.FromNotEncodedRender2XmlValue(); allEdges.Attributes.Append(attr); rsult.AppendChild(allEdges); /*Add initial edge*/ XmlElement initialEdgeElement = rsult.CreateElement("EDGE"); XmlAttribute initialEdgeTo = rsult.CreateAttribute("to"); initialEdgeTo.Value = XmlConvert.EncodeLocalName(editedWf.initialNode.NodeTypeName); initialEdgeElement.Attributes.Append(initialEdgeTo); allEdges.AppendChild(initialEdgeElement); foreach (WFedgeLabel edgeId in editedWf.connectionGraph.Edges) { WFedgeLabel edgeValue = edgeId; Triple <WFedgeLabel, WFnode, WFnode> edgeInfos = editedWf.connectionGraph.GetConnectingNodes(edgeId); XmlElement singleEdgeNode = rsult.CreateElement("EDGE"); XmlAttribute aFrom = rsult.CreateAttribute("from"); XmlAttribute aTo = rsult.CreateAttribute("to"); aFrom.Value = XmlConvert.EncodeLocalName(edgeInfos.SecondMember.NodeTypeName); aTo.Value = XmlConvert.EncodeLocalName(edgeInfos.ThirdMember.NodeTypeName); singleEdgeNode.Attributes.Append(aFrom); singleEdgeNode.Attributes.Append(aTo); /*Appending preconditions and actions*/ singleEdgeNode.AppendChild(rsult.ImportNode(edgeValue.GetEntireDescription().DocumentElement, true)); allEdges.AppendChild(singleEdgeNode); } /*Adding edges for final nodes*/ foreach (WFnode finalNd in editedWf.finalNodes) { XmlElement singleEdgeNode = rsult.CreateElement("EDGE"); XmlAttribute aFrom = rsult.CreateAttribute("from"); aFrom.Value = XmlConvert.EncodeLocalName(finalNd.NodeTypeName); singleEdgeNode.Attributes.Append(aFrom); allEdges.AppendChild(singleEdgeNode); } return(rsult); }
/// <summary> /// Remove an edge from the workflow. /// </summary> /// <param name="id">the edge to remove</param> public void RemoveEdge(WFedgeLabel id) { var rs = connectionGraph.GetConnectingNodes(id); connectionGraph.RemoveEdge(rs.SecondMember, rs.ThirdMember); id.EdgeModified -= ed_EdgeModified; string info; if ((info = informativeIsValid()) != null) { OnWorkflowInvalidationEvent(new WorkflowValidationEventArgs(info, false)); } }
/// <summary> /// Adds the edge edge between nodes from and to. Throws ArgumentException if a node doesnt'exist. /// </summary> /// <param name="edge">the edge to add</param> /// <param name="from">the starting node of edge</param> /// <param name="to">the target node of edge</param> public void AddEdge(WFedgeLabel edge, WFnode from, WFnode to) { if (!(connectionGraph.ContainsNode(from) && connectionGraph.ContainsNode(to))) { throw new ArgumentException("Starting/Target node not inserted in workflow or removed."); } connectionGraph.AddEdge(from, to, edge); edge.EdgeModified += ed_EdgeModified; string info; if ((info = informativeIsValid()) != null) { OnWorkflowInvalidationEvent(new WorkflowValidationEventArgs(info, false)); } }
/// <summary> /// Transit from one state to another, after consider the event verified and which edge verify precondition /// </summary> /// <param name="evt">The event verified</param> /// <param name="data">The actual node</param> /// <param name="handler">Validation Handler</param> /// <returns></returns> public ActionResult ComputeNewStatus(WFeventType evt, XmlDocument data, ValidationEventHandler handler) { if (evt == WFeventType.TRYGOON) { actualState.Value = data.DocumentElement; if (actualState.Validate(handler)) { if (editedWf.finalNodes.Contains(actualState)) { /*Save data */ finalDocument.Push(actualState); actualState = null; return(new ActionResult(true)); } /*Compute new status*/ List <WFedgeLabel> edges = editedWf.connectionGraph.GetOutgoingEdges(actualState); edges.Sort((x, y) => x.Priority - y.Priority); foreach (WFedgeLabel edgeIdToEval in edges) { //COMMENTATO PER SICUREZZA DI FUNZIONAMENTO WFedgeLabel edgeToEval = edgeIdToEval; if (edgeToEval.VerifyPrecondition(actualState)) { /*Save data */ finalDocument.Push(actualState); //aggiunto controllo sullo stack di rollback (vuoto / non vuoto) if (rollbackWFnodes.Count != 0) { WFnode rollbackNode = rollbackWFnodes.Pop(); //recupero sia il WFnode che la sua istanza dal top dei 2 stack WFedgeLabel rollbackEdge = editedWf.connectionGraph.GetEdge(actualState, rollbackNode); if (edgeIdToEval != rollbackEdge) { rollbackWFnodes = new Stack <WFnode>(); actualState = editedWf.connectionGraph.GetDestination(actualState, edgeIdToEval); } else { actualState = rollbackNode; } } else { actualState = editedWf.connectionGraph.GetDestination(actualState, edgeIdToEval); } return(new ActionResult(true)); } } Debug.WriteLine("Not avery edges precondition is satisfied"); return(new ActionResult(false)); } else { actualState.Value = null; } Debug.WriteLine("Passed node is not valid! Validation failed"); return(new ActionResult(false)); } else if (evt == WFeventType.ROLLBACK) { if (IsInitialState()) { Debug.WriteLine("Cannot rollback from initial node!"); return(new ActionResult(false)); } if (actualState != null) { rollbackWFnodes.Push(actualState); } actualState = finalDocument.Pop(); return(new ActionResult(true)); } return(new ActionResult(false)); }