public virtual IDeploymentBuilder StartForm(string startForm, string bpmnXML)
        {
            lock (syncRoot)
            {
                if (string.IsNullOrWhiteSpace(startForm) == false)
                {
                    deployment.StartForm = startForm;
                }
                else
                {
                    BpmnXMLConverter bpm = new BpmnXMLConverter();

                    using (MemoryStream ms = new MemoryStream())
                    {
                        StreamWriter sw = new StreamWriter(ms);
                        sw.Write(bpmnXML);
                        sw.Flush();
                        ms.Seek(0, SeekOrigin.Begin);
                        XDocument doc = XDocument.Load(ms, LoadOptions.PreserveWhitespace);

                        XElement start = doc.Descendants(XName.Get(BpmnXMLConstants.ELEMENT_PROCESS, BpmnXMLConstants.BPMN2_NAMESPACE))
                                         .Descendants(XName.Get(BpmnXMLConstants.ELEMENT_EVENT_START, BpmnXMLConstants.BPMN2_NAMESPACE))
                                         .FirstOrDefault();

                        if (start != null)
                        {
                            string formKey = start.Attribute(XName.Get(BpmnXMLConstants.ATTRIBUTE_FORM_FORMKEY, BpmnXMLConstants.ACTIVITI_EXTENSIONS_NAMESPACE))?.Value;

                            deployment.StartForm = formKey;
                        }
                    }
                }

                //校验启动表单唯一性
                //if (string.IsNullOrWhiteSpace(deployment.StartForm) == false)
                //{
                //    string procName = VerifyStartForm(deployment.Name, deployment.StartForm);

                //    if (string.IsNullOrWhiteSpace(procName) == false)
                //    {
                //        throw new StartFormUniqueException(procName, deployment.StartForm);
                //    }
                //}

                //if (string.IsNullOrWhiteSpace(deployment.StartForm))
                //{
                //    throw new StartFormNullException(deployment.Name);
                //}
                return(this);
            }
        }
        public virtual IDeploymentBuilder AddBpmnModel(string resourceName, BpmnModel bpmnModel)
        {
            BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter();

            try
            {
                string bpmn20Xml = StringHelper.NewString(bpmnXMLConverter.ConvertToXML(bpmnModel), "UTF-8");
                AddString(resourceName, bpmn20Xml);
            }
            catch (Exception e)
            {
                throw new ActivitiException("Error while transforming BPMN model to xml: not UTF-8 encoded", e);
            }
            return(this);
        }
        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
            })));
        }
Beispiel #4
0
        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 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);
        }
Beispiel #6
0
        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();
            }