/// <summary> /// Return true if the edge could be traversed, false otherwise. /// This valutation is done having the previous node (filled) /// </summary> /// <param name="previousNode"></param> /// <returns>Control </returns> internal bool VerifyPrecondition(WFnode previousNode) { if (EdgeLabelInterpreter.InterpretPreconditions(previousNode.Value, preconditions.DocumentElement)) { return(true); } return(false); }
private string informativeIsValid() { /*Every node is valid...itself*/ foreach (WFnode wnd in connectionGraph.Nodes) { if (!wnd.isValid) { try { return("The editor you are using pass me some invalid datas for node " + wnd.Name); } catch { return("The editor you are using pass me some invalid datas for a node"); } } } if (!findInitialAndFinalNodes()) { return("No Initial node or no recognized final nodes in workflow"); } /*Initial should be really initial*/ if (connectionGraph.GetIncomingEdges(initialNode).Count != 0) { return("Initial node has incoming edges"); } /*Each node should be reached from initial node*/ Stack <WFnode> stack = new Stack <WFnode>(); HashSet <WFnode> visited = new HashSet <WFnode>(); HashSet <WFnode> nodeInStack = new HashSet <WFnode>(); stack.Push(initialNode); nodeInStack.Add(initialNode); visited.Add(initialNode); WFnode popped = null; while (stack.Count > 0) { WFnode top = stack.Peek(); List <WFnode> lst = connectionGraph.getOutcomingNodes(top); if (lst.Count > 0) { if (popped != null) { int num = lst.IndexOf(popped); if (num + 1 < lst.Count) { if (nodeInStack.Contains(lst[num + 1])) { return("Workflow contains cycle"); } nodeInStack.Add(lst[num + 1]); stack.Push(lst[num + 1]); visited.Add(lst[num + 1]); } else { popped = stack.Pop(); nodeInStack.Remove(popped); } } else { if (stack.Contains(lst[0])) { return("Workflow contains cycle"); } nodeInStack.Add(lst[0]); stack.Push(lst[0]); visited.Add(lst[0]); } } else { popped = stack.Pop(); nodeInStack.Remove(popped); } } if (visited.Count != connectionGraph.Nodes.Count) { return("Not all nodes could be reached from initial node"); } try { XmlSchemaSet resSchema = new XmlSchemaSet(); resSchema.Add(Fields.FieldsManager.FieldTypesXSD); foreach (WFnode nd in connectionGraph.Nodes) { resSchema.Add(nd.GetNodeSchemasWithoutBaseTypes()); } resSchema.Compile(); } catch (Exception err) { return("Problems with nodes schemas:\n\n" + err.Message); } /*Verify edge precondition*/ foreach (WFedgeLabel edg in connectionGraph.Edges) { var tr = connectionGraph.GetConnectingNodes(edg); if (!EdgeLabelInterpreter.VerifyPreconditionsCorrectness(tr.SecondMember.GetNodeSchemas(), XmlConvert.EncodeLocalName(tr.SecondMember.NodeTypeName), edg.GetPrecondition().FirstChild)) { return("The edge between " + XmlConvert.EncodeLocalName(tr.SecondMember.NodeTypeName) + " and " + XmlConvert.EncodeLocalName(tr.ThirdMember.NodeTypeName) + " contains wrong preconditions"); } } return(null); }