public void ToXml(string bpmnFile) { try { string root = AppDomain.CurrentDomain.BaseDirectory; string docFile = Path.Combine(new string[] { root, "resources", "samples", bpmnFile }); var bxc = new BpmnXMLConverter(); BpmnModel model = bxc.ConvertToBpmnModel(docFile); byte[] data = bxc.ConvertToXML(model); string xml = Encoding.UTF8.GetString(data); BpmnModel temp = bxc.ConvertToBpmnModel(new XMLStreamReader(new MemoryStream(data))); } catch (Exception ex) { } }
public Task <ActionResult <BpmnModel> > GetBpmnModel(string id) { BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter(); IList <string> names = repositoryService.GetDeploymentResourceNames(id); Stream resourceStream = repositoryService.GetResourceAsStream(id, names[0]); BpmnModel model = bpmnXMLConverter.ConvertToBpmnModel(new XMLStreamReader(resourceStream)); return(Task.FromResult <ActionResult <BpmnModel> >(new JsonResult(model, new JsonSerializerSettings { TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple, TypeNameHandling = TypeNameHandling.All, ReferenceLoopHandling = ReferenceLoopHandling.Ignore }))); }
public string Copy(string id, bool fullCopy) { IList <string> names = repositoryService.GetDeploymentResourceNames(id); Stream resourceStream = repositoryService.GetResourceAsStream(id, names[0]); if (fullCopy) { resourceStream.Seek(0, SeekOrigin.Begin); byte[] data = new byte[resourceStream.Length]; resourceStream.Read(data, 0, data.Length); return(new UTF8Encoding(false).GetString(data)); } BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter(); BpmnModel model = bpmnXMLConverter.ConvertToBpmnModel(new XMLStreamReader(resourceStream)); //return bpmnXMLConverter.convertToXML(model); return(null); }
public virtual BpmnParse Execute() { try { ProcessEngineConfigurationImpl processEngineConfiguration = Context.ProcessEngineConfiguration; BpmnXMLConverter converter = new BpmnXMLConverter(); bool enableSafeBpmnXml = false; string encoding = null; if (processEngineConfiguration != null) { enableSafeBpmnXml = processEngineConfiguration.EnableSafeBpmnXml; encoding = processEngineConfiguration.XmlEncoding; } if (!(encoding is null)) { bpmnModel = converter.ConvertToBpmnModel(streamSource, validateSchema, enableSafeBpmnXml, encoding); } else { bpmnModel = converter.ConvertToBpmnModel(streamSource, validateSchema, enableSafeBpmnXml); } // XSD validation goes first, then process/semantic validation if (validateProcess) { IProcessValidator processValidator = processEngineConfiguration.ProcessValidator; if (processValidator == null) { logger.LogWarning("Process should be validated, but no process validator is configured on the process engine configuration!"); } else { IList <ValidationError> validationErrors = processValidator.Validate(bpmnModel); if (validationErrors != null && validationErrors.Count > 0) { StringBuilder warningBuilder = new StringBuilder(); StringBuilder errorBuilder = new StringBuilder(); foreach (ValidationError error in validationErrors) { if (error.Warning) { warningBuilder.Append(error.ToString()); warningBuilder.Append("\n"); } else { errorBuilder.Append(error.ToString()); errorBuilder.Append("\n"); } } // Throw exception if there is any error if (validationErrors.Any(x => x.Warning == false)) { logger.LogError($"Following errors encounted during process validation:\r\n{errorBuilder.ToString()}"); throw new ActivitiValidationException(validationErrors); } // Write out warnings (if any) if (warningBuilder.Length > 0) { logger.LogWarning($"Following warnings encountered during process validation: {warningBuilder.ToString()}"); } } } } bpmnModel.SourceSystemId = sourceSystemId; bpmnModel.EventSupport = new ActivitiEventSupport(); // Validation successful (or no validation) // Attach logic to the processes (eg. map ActivityBehaviors to bpmn model elements) ApplyParseHandlers(); // Finally, process the diagram interchange info ProcessDI(); }