Exemplo n.º 1
0
        public virtual IList <ValidationError> Execute(ICommandContext commandContext)
        {
            IProcessValidator processValidator = commandContext.ProcessEngineConfiguration.ProcessValidator;

            if (processValidator == null)
            {
                throw new ActivitiException("No process validator defined");
            }

            return(processValidator.Validate(bpmnModel));
        }
Exemplo n.º 2
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();
            }