public void TestCursorPositionAfterImport() { var data = new ParsableData("import \"../../../../Test/Data/interface_demo.ceusdl\"\nimport \"../../../../Test/Data/interface_demo2.ceusdl\""); var p = new ImportParser(data); var result = p.Parse(); Console.WriteLine($"Result : {result.Path}"); StringAssert.EndsWith(result.Path, "..\\..\\..\\..\\Test\\Data\\interface_demo.ceusdl"); Assert.AreEqual(1, result?.Content?.Interfaces?.Count); Assert.AreEqual("Semester", result.Content.Interfaces[0].Name); result = p.Parse(); StringAssert.EndsWith(result.Path, "..\\..\\..\\..\\Test\\Data\\interface_demo2.ceusdl"); }
public virtual BpmnModel ConvertToBpmnModel(XMLStreamReader xtr) { BpmnModel model = new BpmnModel { StartEventFormTypes = startEventFormTypes, UserTaskFormTypes = userTaskFormTypes }; try { Process activeProcess = null; IList <SubProcess> activeSubProcessList = new List <SubProcess>(); while (xtr.HasNext()) { // xtr.next(); if (xtr.EndElement && (BpmnXMLConstants.ELEMENT_SUBPROCESS.Equals(xtr.LocalName) || BpmnXMLConstants.ELEMENT_TRANSACTION.Equals(xtr.LocalName) || BpmnXMLConstants.ELEMENT_ADHOC_SUBPROCESS.Equals(xtr.LocalName))) { activeSubProcessList.RemoveAt(activeSubProcessList.Count - 1); } if (!xtr.IsStartElement()) { if (BpmnXMLConstants.ELEMENT_DI_DIAGRAM == xtr.LocalName) { xtr.Skip(); } else { continue; } } if (xtr.IsStartElement() && BpmnXMLConstants.ELEMENT_DEFINITIONS.Equals(xtr.LocalName)) { definitionsParser.Parse(xtr, model); } else if (BpmnXMLConstants.ELEMENT_RESOURCE.Equals(xtr.LocalName)) { resourceParser.Parse(xtr, model); } else if (BpmnXMLConstants.ELEMENT_SIGNAL.Equals(xtr.LocalName)) { signalParser.Parse(xtr, model); } else if (BpmnXMLConstants.ELEMENT_MESSAGE.Equals(xtr.LocalName)) { messageParser.Parse(xtr, model); } else if (BpmnXMLConstants.ELEMENT_ERROR.Equals(xtr.LocalName)) { if (!string.IsNullOrWhiteSpace(xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_ID))) { model.AddError(xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_ID), xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_ERROR_CODE)); } } else if (BpmnXMLConstants.ELEMENT_IMPORT.Equals(xtr.LocalName)) { importParser.Parse(xtr, model); } else if (BpmnXMLConstants.ELEMENT_ITEM_DEFINITION.Equals(xtr.LocalName)) { itemDefinitionParser.Parse(xtr, model); } else if (BpmnXMLConstants.ELEMENT_DATA_STORE.Equals(xtr.LocalName)) { dataStoreParser.Parse(xtr, model); } else if (BpmnXMLConstants.ELEMENT_INTERFACE.Equals(xtr.LocalName)) { interfaceParser.Parse(xtr, model); } else if (BpmnXMLConstants.ELEMENT_IOSPECIFICATION.Equals(xtr.LocalName)) { ioSpecificationParser.ParseChildElement(xtr, activeProcess, model); } else if (BpmnXMLConstants.ELEMENT_PARTICIPANT.Equals(xtr.LocalName)) { participantParser.Parse(xtr, model); } else if (BpmnXMLConstants.ELEMENT_MESSAGE_FLOW.Equals(xtr.LocalName)) { messageFlowParser.Parse(xtr, model); } else if (BpmnXMLConstants.ELEMENT_PROCESS.Equals(xtr.LocalName)) { Process process = processParser.Parse(xtr, model); if (process != null) { activeProcess = process; } } else if (BpmnXMLConstants.ELEMENT_POTENTIAL_STARTER.Equals(xtr.LocalName)) { potentialStarterParser.Parse(xtr, activeProcess); } else if (BpmnXMLConstants.ELEMENT_LANE.Equals(xtr.LocalName)) { laneParser.Parse(xtr, activeProcess, model); } else if (BpmnXMLConstants.ELEMENT_DOCUMENTATION.Equals(xtr.LocalName)) { BaseElement parentElement = null; if (activeSubProcessList.Count > 0) { parentElement = activeSubProcessList[activeSubProcessList.Count - 1]; } else if (activeProcess != null) { parentElement = activeProcess; } documentationParser.ParseChildElement(xtr, parentElement, model); } else if (activeProcess == null && BpmnXMLConstants.ELEMENT_TEXT_ANNOTATION.Equals(xtr.LocalName)) { string elementId = xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_ID); TextAnnotation textAnnotation = (TextAnnotation)(new TextAnnotationXMLConverter()).ConvertXMLToElement(xtr, model); textAnnotation.Id = elementId; model.GlobalArtifacts.Add(textAnnotation); } else if (activeProcess == null && BpmnXMLConstants.ELEMENT_ASSOCIATION.Equals(xtr.LocalName)) { string elementId = xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_ID); Association association = (Association)(new AssociationXMLConverter()).ConvertXMLToElement(xtr, model); association.Id = elementId; model.GlobalArtifacts.Add(association); } else if (BpmnXMLConstants.ELEMENT_EXTENSIONS.Equals(xtr.LocalName)) { extensionElementsParser.Parse(xtr, activeSubProcessList, activeProcess, model); } else if (BpmnXMLConstants.ELEMENT_SUBPROCESS.Equals(xtr.LocalName) || BpmnXMLConstants.ELEMENT_TRANSACTION.Equals(xtr.LocalName) || BpmnXMLConstants.ELEMENT_ADHOC_SUBPROCESS.Equals(xtr.LocalName)) { subProcessParser.Parse(xtr, activeSubProcessList, activeProcess); } else if (BpmnXMLConstants.ELEMENT_COMPLETION_CONDITION.Equals(xtr.LocalName)) { if (activeSubProcessList.Count > 0) { SubProcess subProcess = activeSubProcessList[activeSubProcessList.Count - 1]; if (subProcess is AdhocSubProcess adhocSubProcess) { adhocSubProcess.CompletionCondition = xtr.ElementText; } } } else if (BpmnXMLConstants.ELEMENT_DI_SHAPE.Equals(xtr.LocalName)) { bpmnShapeParser.Parse(xtr, model); } else if (BpmnXMLConstants.ELEMENT_DI_EDGE.Equals(xtr.LocalName)) { bpmnEdgeParser.Parse(xtr, model); } else { if (activeSubProcessList.Count > 0 && BpmnXMLConstants.ELEMENT_MULTIINSTANCE.Equals(xtr.LocalName, StringComparison.CurrentCultureIgnoreCase)) { multiInstanceParser.ParseChildElement(xtr, activeSubProcessList[activeSubProcessList.Count - 1], model); } else if (convertersToBpmnMap.ContainsKey(xtr.LocalName)) { if (activeProcess != null) { BaseBpmnXMLConverter converter = convertersToBpmnMap[xtr.LocalName]; converter.ConvertToBpmnModel(xtr, model, activeProcess, activeSubProcessList); } } } //try //{ // xtr.next(); //} //catch (Exception e) //{ // //LOGGER.debug("Error reading XML document", e); // throw new XMLException("Error reading XML", e); //} } foreach (Process process in model.Processes) { foreach (Pool pool in model.Pools) { if (process.Id.Equals(pool.ProcessRef)) { pool.Executable = process.Executable; } } ProcessFlowElements(process.FlowElements, process); } } catch (Exception e) { log.LogError(e, "Error processing BPMN document"); throw new XMLException("Error processing BPMN document", e); } return(model); }