Beispiel #1
0
        public virtual async Task <Deployment> BuildAsync()
        {
            var model     = BpmnModel.FromBytes(this.modelData, this.disableModelValidations);
            var processes = model.Processes;

            if (processes.Count == 0)
            {
                throw new DeploymentException("The BPMN model does not contains any processes.");
            }

            var keys = processes.Select(x => x.Id);

            var prevProcessDefinitions = await this.deploymentManager.CreateDefinitionQuery()
                                         .FetchLatestVersionOnly()
                                         .SetKeyAny(keys)
                                         .ListAsync();

            var prevProcessDefinitionMap = prevProcessDefinitions.ToDictionary(x => x.Key);

            //New deployment.
            var deployment = new Deployment();

            deployment.Name     = name;
            deployment.Model    = new ByteArray(modelData);
            deployment.Created  = Clock.Now;
            deployment.Category = this.category;
            deployment.Memo     = this.memo;
            deployment.TenantId = this.tenantId;

            ProcessDefinition prevProcessDefinition = null;

            foreach (var bpmnProcess in processes)
            {
                if (!bpmnProcess.IsExecutable)
                {
                    throw new DeploymentException($"The process '{bpmnProcess.Id}' is not executabe.");
                }

                prevProcessDefinition = null;
                if (prevProcessDefinitionMap.Count > 0)
                {
                    prevProcessDefinitionMap.TryGetValue(bpmnProcess.Id, out prevProcessDefinition);
                }

                var procDef = this.CreateProcessDefinition(deployment, bpmnProcess, prevProcessDefinition);
                procDef.HasDiagram = model.HasDiagram(bpmnProcess.Id);

                deployment.ProcessDefinitions.Add(procDef);

                this.InitializeEventsAndScheduledJobs(procDef, bpmnProcess, prevProcessDefinition);
            }

            await this.session.SaveAsync(deployment);

            await this.session.FlushAsync();

            return(deployment);
        }
Beispiel #2
0
        public virtual BpmnModel GetBpmnModel(int deploymentId)
        {
            BpmnModel model = null;

            if (!modelCache.ContainsKey(deploymentId))
            {
                var query = this.session.Deployments.Where(x => x.Id == deploymentId)
                            .Select(x => x.Model.Value);

                var bytes = query.SingleOrDefault();
                model = BpmnModel.FromBytes(bytes);
            }

            return(modelCache.GetOrAdd(deploymentId, (id) => model));
        }