示例#1
0
        //解析xml 生成ProcessDefinitionEntity
        protected internal override IList <ProcessDefinitionEntity> TransformDefinitions(DeploymentEntity deployment, ResourceEntity resource, Core.Model.Properties properties)
        {
            byte[] bytes = resource.Bytes;
            System.IO.MemoryStream inputStream = new System.IO.MemoryStream(bytes);

            BpmnParse bpmnParse = bpmnParser.CreateBpmnParse().SourceInputStream(inputStream).Deployment(deployment).SetName(resource.Name);

            if (!deployment.IsValidatingSchema)
            {
                bpmnParse.SchemaResource = null;
            }
            //执行实际解析
            bpmnParse.Execute();

            //TODO 解析后续行为
            if (!properties.Contains(JobDeclarationsProperty))
            {
                properties.Set(JobDeclarationsProperty, new Dictionary <string, IList <IJobDeclaration> >());
            }
            var oldProperties = properties.Get(JobDeclarationsProperty);

            foreach (var item in bpmnParse.GetJobDeclarations())
            {
                oldProperties[item.Key] = item.Value;
            }
            //foreach (var item in oldProperties)
            //{
            //    bpmnParse.JobDeclarations[item.Key] = item.Value;
            //}
            //properties.Set<string, IList<IJobDeclaration>>(JobDeclarationsProperty, bpmnParse.JobDeclarations);

            return(bpmnParse.ProcessDefinitions);
        }
        private BpmnParse CreateBpmnParseFromResource(BpmnDeploymentHelper helper, IResourceEntity resource)
        {
            string       resourceName = resource.Name;
            MemoryStream inputStream  = new MemoryStream(resource.Bytes);
            var          changed      = helper.AddCamundaNamespace(inputStream);

            if (changed.Item1)
            {
                resource.Bytes = changed.Item2.ToArray();
                inputStream    = changed.Item2;
            }
            ;
            inputStream.Seek(0, SeekOrigin.Begin);

            BpmnParse bpmnParse = bpmnParser.CreateParse().SourceInputStream(inputStream).SetSourceSystemId(resourceName).SetName(resourceName);

            bpmnParse.Deployment = deployment;

            if (deploymentSettings != null)
            {
                // Schema validation if needed
                if (deploymentSettings.ContainsKey(Cmd.DeploymentSettingsFields.IS_BPMN20_XSD_VALIDATION_ENABLED))
                {
                    bpmnParse.ValidateSchema = Convert.ToBoolean(deploymentSettings[Cmd.DeploymentSettingsFields.IS_BPMN20_XSD_VALIDATION_ENABLED]);
                }

                // Process validation if needed
                if (deploymentSettings.ContainsKey(Cmd.DeploymentSettingsFields.IS_PROCESS_VALIDATION_ENABLED))
                {
                    bpmnParse.ValidateProcess = Convert.ToBoolean(deploymentSettings[Cmd.DeploymentSettingsFields.IS_PROCESS_VALIDATION_ENABLED]);
                }
            }
            else
            {
                // On redeploy, we assume it is validated at the first deploy
                bpmnParse.ValidateSchema  = false;
                bpmnParse.ValidateProcess = false;
            }

            bpmnParse.Execute();
            return(bpmnParse);
        }