public virtual IProcessInstanceWithVariables Execute(CommandContext commandContext) { var processDefinition = new GetDeployedProcessDefinitionCmd(InstantiationBuilder, false).Execute(commandContext); foreach (var checker in commandContext.ProcessEngineConfiguration.CommandCheckers) { checker.CheckCreateProcessInstance(processDefinition); } var modificationBuilder = InstantiationBuilder.ModificationBuilder; EnsureUtil.EnsureNotEmpty( @"At least one instantiation instruction required (e.g. by invoking startBefore(..), startAfter(..) or startTransition(..))", "instructions", ListExt.ConvertToIlist(modificationBuilder.ModificationOperations)); // instantiate the process var initialActivity = DetermineFirstActivity(processDefinition, modificationBuilder); ExecutionEntity processInstance = (ExecutionEntity)processDefinition.CreateProcessInstance(InstantiationBuilder.BusinessKey, InstantiationBuilder.CaseInstanceId, initialActivity); processInstance.SkipCustomListeners = modificationBuilder.SkipCustomListeners; var variables = modificationBuilder.ProcessVariables; ExecutionVariableSnapshotObserver variablesListener = new ExecutionVariableSnapshotObserver(processInstance); processInstance.StartWithoutExecuting(variables); // prevent ending of the process instance between instructions processInstance.PreserveScope = true; // apply modifications var instructions = modificationBuilder.ModificationOperations; for (var i = 0; i < instructions.Count; i++) { var instruction = instructions[i]; Log.DebugStartingInstruction(processInstance.Id, i, instruction.Describe()); instruction.ProcessInstanceId = processInstance.Id; instruction.SkipCustomListeners = modificationBuilder.SkipCustomListeners; instruction.SkipIoMappings = modificationBuilder.SkipIoMappings; instruction.Execute(commandContext); } if (!processInstance.HasChildren() && processInstance.IsEnded) { // process instance has ended regularly but this has not been propagated yet // due to preserveScope setting processInstance.PropagateEnd(); } return(new ProcessInstanceWithVariablesImpl(processInstance, variablesListener.Variables)); }
public virtual object Execute(CommandContext commandContext) { var processInstanceId = Builder.ProcessInstanceId; IExecutionManager executionManager = commandContext.ExecutionManager; ExecutionEntity processInstance = executionManager.FindExecutionById(processInstanceId); CheckUpdateProcessInstance(processInstance, commandContext); processInstance.PreserveScope = true; var instructions = Builder.ModificationOperations; for (var i = 0; i < instructions.Count; i++) { var instruction = instructions[i]; Log.DebugModificationInstruction(processInstanceId, i + 1, instruction.Describe()); instruction.SkipCustomListeners = Builder.SkipCustomListeners; instruction.SkipIoMappings = Builder.SkipIoMappings; instruction.Execute(commandContext); } processInstance = executionManager.FindExecutionById(processInstanceId); if (!processInstance.HasChildren()) { if (processInstance.Activity == null) { // process instance was cancelled CheckDeleteProcessInstance(processInstance, commandContext); DeletePropagate(processInstance, "Cancellation due to process instance modification", Builder.SkipCustomListeners, Builder.SkipIoMappings); } else if (processInstance.IsEnded) { // process instance has ended regularly processInstance.PropagateEnd(); } } commandContext.OperationLogManager.LogProcessInstanceOperation(LogEntryOperation, processInstanceId, null, null, new List <PropertyChange>() { PropertyChange.EmptyChange }); return(null); }