protected internal virtual IProcessInstance InstantiateProcess(CommandContext commandContext,
                                                                       CorrelationHandlerResult correlationResult)
        {
            var             processDefinitionEntity = correlationResult.ProcessDefinitionEntity;
            ActivityImpl    messageStartEvent       = (ActivityImpl)processDefinitionEntity.FindActivity(correlationResult.StartEventActivityId);
            ExecutionEntity processInstance         = (ExecutionEntity)processDefinitionEntity.CreateProcessInstance(Builder.BusinessKey, messageStartEvent);

            processInstance.Start(Builder.PayloadProcessInstanceVariables);

            return(processInstance);
        }
Example #2
0
        public virtual IProcessInstance Execute(CommandContext commandContext)
        {
            var                     processEngineConfiguration = context.Impl.Context.ProcessEngineConfiguration;
            DeploymentCache         deploymentCache            = processEngineConfiguration.DeploymentCache;
            ProcessDefinitionEntity processDefinition          =
                deploymentCache.FindDeployedProcessDefinitionById(ProcessDefinitionId);

            EnsureUtil.EnsureNotNull("No process definition found for id = '" + ProcessDefinitionId + "'",
                                     "processDefinition", processDefinition);

            foreach (var checker in commandContext.ProcessEngineConfiguration.CommandCheckers)
            {
                checker.CheckCreateProcessInstance(processDefinition);
            }

            ExecutionEntity processInstance = null;

            if (!ReferenceEquals(BusinessKey, null))
            {
                processInstance = (ExecutionEntity)processDefinition.CreateProcessInstance(BusinessKey);
            }
            else
            {
                processInstance = (ExecutionEntity)processDefinition.CreateProcessInstance();
            }

            //if the start event is async, we have to set the variables already here
            //since they are lost after the async continuation otherwise
            if (processDefinition.Initial.AsyncBefore)
            {
                // avoid firing history events
                processInstance.StartContext = new ProcessInstanceStartContext(processInstance.Activity as ActivityImpl);
                FormPropertyHelper.InitFormPropertiesOnScope(Variables, processInstance);
                processInstance.Start();
            }
            else
            {
                processInstance.StartWithFormProperties(Variables);
            }


            return((IProcessInstance)processInstance);
        }