public IProcessInstance StartProcessInstance(long processDefinitionId, IDictionary attributeValues = null, string transitionName = null, Relations relations = null) { ProcessInstanceImpl processInstance = null; IOrganisationService organisationService = null; using (ISession session = NHibernateHelper.OpenSession()) { using (var tran = session.BeginTransaction()) { DbSession dbSession = new DbSession(session); ProcessDefinitionImpl processDefinition = myProcessDefinitionService.GetProcessDefinition(processDefinitionId, dbSession); processInstance = new ProcessInstanceImpl(ActorId, processDefinition); processInstanceRepository.Save(processInstance, dbSession);//到這裏應該存了ProcessInstance,RootFlow ExecutionContext executionContext = new ExecutionContext(); //logRepository.CreateLog(); processDefinition.StartState.CheckAccess(attributeValues); attributeService = new AttributeService((FlowImpl)processInstance.RootFlow, dbSession); attributeService.StoreAttributeValue(attributeValues);//儲存傳入的欄位值 attributeService.StoreRole(organisationService.FindActorById(ActorId), (ActivityStateImpl)processDefinition.StartState); //flow的node推進到下一關卡 //flow的actor=解析出來的actor.Id transitionService = new TransitionService(ActorId, dbSession); TransitionImpl transitionTo = transitionService.GetTransition(transitionName, processDefinition.StartState, dbSession); transitionService.ProcessTransition(transitionTo, (FlowImpl)processInstance.RootFlow, dbSession); session.Flush(); tran.Commit(); } } return(processInstance); }
public override object Execute(CommandContext commandContext) { IActivityInstance activityInstanceTree = commandContext.RunWithoutAuthorization(() => (new GetActivityInstanceCmd(processInstanceId)).Execute(commandContext)); ExecutionEntity processInstance = commandContext.ExecutionManager.FindExecutionById(processInstanceId); ProcessDefinitionImpl processDefinition = processInstance.ProcessDefinition; ISet <string> parentScopeIds = CollectParentScopeIdsForActivity(processDefinition, ActivityId); IList <IActivityInstance> childrenForActivity = GetActivityInstancesForActivity(activityInstanceTree, parentScopeIds); foreach (IActivityInstance instance in childrenForActivity) { ActivityInstanceCancellationCmd cmd = new ActivityInstanceCancellationCmd(processInstanceId, instance.Id); cmd.SkipCustomListeners = skipCustomListeners; cmd.SkipIoMappings = skipIoMappings; cmd.Execute(commandContext); } IList <ITransitionInstance> transitionInstancesForActivity = GetTransitionInstancesForActivity(activityInstanceTree, parentScopeIds); foreach (ITransitionInstance instance in transitionInstancesForActivity) { TransitionInstanceCancellationCmd cmd = new TransitionInstanceCancellationCmd(processInstanceId, instance.Id); cmd.SkipCustomListeners = skipCustomListeners; cmd.SkipIoMappings = skipIoMappings; cmd.Execute(commandContext); } return(null); }
public void BuildProcessDefinitionTest() { MyProcessDefinitionBuilder builder = new MyProcessDefinitionBuilder(helloWorld1()); ProcessDefinitionImpl processDefinition = builder.BuildProcessDefinition(); Assert.AreEqual("Hello world 1", processDefinition.Name); Assert.AreEqual("This is the simples process.", processDefinition.Description); Assert.AreEqual(3, processDefinition.Nodes.Count); Assert.IsNotNull(processDefinition.StartState); Assert.AreEqual("start", processDefinition.StartState.Name); Assert.AreEqual(1, processDefinition.StartState.LeavingTransitions.Count); foreach (var node in processDefinition.Nodes) { INode no = node as INode; if (no != null && no.Name == "first activity state") { Assert.AreEqual("this is the first state", no.Description); Assert.AreEqual(1, no.LeavingTransitions.Count); ActivityStateImpl activityState = no as ActivityStateImpl; if (activityState != null) { Assert.IsNotNull(activityState.AssignmentDelegation); Assert.AreEqual("NetBpm.Workflow.Delegation.Impl.Assignment.AssignmentExpressionResolver, NetBpm", activityState.AssignmentDelegation.ClassName); Assert.AreEqual("<cfg><parameter name=\"expression\">processInitiator</parameter></cfg>", activityState.AssignmentDelegation.Configuration); } } } }
/// <summary> /// get the activity that is started by the first instruction, if exists; /// return null if the first instruction is a start-transition instruction /// </summary> protected internal virtual ActivityImpl DetermineFirstActivity(ProcessDefinitionImpl processDefinition, ProcessInstanceModificationBuilderImpl modificationBuilder) { var firstInstruction = modificationBuilder.ModificationOperations[0]; if (firstInstruction is AbstractInstantiationCmd) { var instantiationInstruction = (AbstractInstantiationCmd)firstInstruction; var targetElement = instantiationInstruction.GetTargetElement(processDefinition); EnsureUtil.EnsureNotNull(typeof(NotValidException), "Element '" + instantiationInstruction.TargetElementId + "' does not exist in process " + processDefinition.Id, "targetElement", targetElement); if (targetElement is ActivityImpl) { return((ActivityImpl)targetElement); } if (targetElement is TransitionImpl) { return((ActivityImpl)((TransitionImpl)targetElement).Destination); } } return(null); }
public virtual ValidatingMigrationInstructions generate(ProcessDefinitionImpl sourceProcessDefinition, ProcessDefinitionImpl targetProcessDefinition, bool updateEventTriggers) { ValidatingMigrationInstructions migrationInstructions = new ValidatingMigrationInstructions(); generate(sourceProcessDefinition, targetProcessDefinition, sourceProcessDefinition, targetProcessDefinition, migrationInstructions, updateEventTriggers); return(migrationInstructions); }
public virtual void Generate(ScopeImpl sourceScope, ScopeImpl targetScope, ProcessDefinitionImpl sourceProcessDefinition, ProcessDefinitionImpl targetProcessDefinition, ValidatingMigrationInstructions existingInstructions, bool updateEventTriggers) { var flowScopeInstructions = GenerateInstructionsForActivities((ICollection <ActivityImpl>)sourceScope.Activities, (ICollection <ActivityImpl>)targetScope.Activities, updateEventTriggers, existingInstructions); existingInstructions.AddAll(flowScopeInstructions); var eventScopeInstructions = GenerateInstructionsForActivities(sourceScope.EventActivities, targetScope.EventActivities, updateEventTriggers, existingInstructions); existingInstructions.AddAll(eventScopeInstructions); existingInstructions.FilterWith(MigrationInstructionValidatorsRenamed); foreach (var generatedInstruction in flowScopeInstructions) { if (existingInstructions.Contains(generatedInstruction)) { Generate((ScopeImpl)generatedInstruction.SourceActivity, (ScopeImpl)generatedInstruction.TargetActivity, sourceProcessDefinition, targetProcessDefinition, existingInstructions, updateEventTriggers); } } }
public ProcessInstanceImpl(String actorId, ProcessDefinitionImpl processDefinition) { this._start = DateTime.Now; this._initiatorActorId = actorId; this._processDefinition = processDefinition; this._rootFlow = new FlowImpl(actorId, this); }
public static ProcessDefinitionImpl GetProcessDefinitionToCall(IVariableScope execution, BaseCallableElement callableElement) { var processDefinitionKey = callableElement.GetDefinitionKey(execution); var tenantId = callableElement.GetDefinitionTenantId(execution); DeploymentCache deploymentCache = DeploymentCache; ProcessDefinitionImpl processDefinition = null; if (callableElement.LatestBinding) { processDefinition = deploymentCache.FindDeployedLatestProcessDefinitionByKeyAndTenantId(processDefinitionKey, tenantId); } else if (callableElement.DeploymentBinding) { var deploymentId = callableElement.DeploymentId; processDefinition = deploymentCache.FindDeployedProcessDefinitionByDeploymentAndKey(deploymentId, processDefinitionKey); } else if (callableElement.VersionBinding) { var version = callableElement.GetVersion(execution); processDefinition = deploymentCache.FindDeployedProcessDefinitionByKeyVersionAndTenantId(processDefinitionKey, version, tenantId); } return(processDefinition); }
public ProcessDefinitionImpl GetProcessDefinition(long processDefinitionId, DbSession dbSession) { ProcessDefinitionImpl processDefinition = null; processDefinition = (ProcessDefinitionImpl)repository.GetProcessDefinition(processDefinitionId, null, dbSession); return(processDefinition); }
protected internal override void StartInstance(IActivityExecution execution, IVariableMap variables, string businessKey) { ProcessDefinitionImpl definition = CallableElementUtil.GetProcessDefinitionToCall(execution, CallableElement); IPvmProcessInstance processInstance = execution.CreateSubProcessInstance(definition, businessKey); processInstance.Start(variables); }
protected internal virtual void ValidateMigrationPlan(CommandContext commandContext, MigrationPlanImpl migrationPlan, ProcessDefinitionImpl sourceProcessDefinition, ProcessDefinitionImpl targetProcessDefinition) { var migrationInstructionValidators = commandContext.ProcessEngineConfiguration.MigrationInstructionValidators; var planReport = new MigrationPlanValidationReportImpl(migrationPlan); var validatingMigrationInstructions = WrapMigrationInstructions(migrationPlan, sourceProcessDefinition, targetProcessDefinition, planReport); foreach (var validatingMigrationInstruction in validatingMigrationInstructions.Instructions) { var instructionReport = ValidateInstruction(validatingMigrationInstruction, validatingMigrationInstructions, migrationInstructionValidators); if (instructionReport.HasFailures()) { planReport.AddInstructionReport(instructionReport); } } if (planReport.HasInstructionReports()) { throw Log.FailingMigrationPlanValidation(planReport); } }
protected internal override void triggerCallableElement(CmmnActivityExecution execution, IDictionary <string, object> variables, string businessKey) { ProcessDefinitionImpl definition = getProcessDefinitionToCall(execution, CallableElement); PvmProcessInstance processInstance = execution.createSubProcessInstance(definition, businessKey); processInstance.start(variables); }
public WalkConditionAnonymousInnerClass2(AbstractInstantiationCmd outerInstance, ProcessDefinitionImpl processDefinition, ActivityExecutionTreeMapping mapping, ExecutionEntity ancestorScopeExecution, PvmScope ancestorScope) { this.outerInstance = outerInstance; this.processDefinition = processDefinition; this.mapping = mapping; this.ancestorScopeExecution = ancestorScopeExecution; this.ancestorScope = ancestorScope; }
public ExecutionContextImpl(String actorId, ProcessInstanceImpl processInstance, DbSession dbSession, IOrganisationService organisationComponent) { this._actorId = actorId; this._processInstance = processInstance; this._processDefinition = (ProcessDefinitionImpl)processInstance.ProcessDefinition; this._dbSession = dbSession; this._organisationComponent = organisationComponent; this._assignedFlows = new ArrayList(); }
public ProcessDefinitionBuilder(string processDefinitionId) { if (!_instanceFieldsInitialized) { InitializeInstanceFields(); _instanceFieldsInitialized = true; } ProcessDefinition = new ProcessDefinitionImpl(processDefinitionId); ScopeStack.Push(ProcessDefinition); }
private IAuthorizationHandler GetAuthorizationHandler(ProcessDefinitionImpl processDefinition) { IAuthorizationHandler authorizationHandler = null; DelegationImpl delegation = processDefinition.AuthorizationDelegation; if (delegation != null) { authorizationHandler = (IAuthorizationHandler)delegation.GetDelegate(); } return(authorizationHandler); }
protected internal virtual ScopeImpl GetScopeForActivityInstance(ProcessDefinitionImpl processDefinition, IActivityInstance activityInstance) { var scopeId = activityInstance.ActivityId; if (processDefinition.Id.Equals(scopeId)) { return(processDefinition); } return((ScopeImpl)processDefinition.FindActivity(scopeId)); }
/// <summary> /// Returns the priority which is defined in the given process definition. /// The priority value is identified with the given propertyKey. /// Returns null if the process definition is null or no priority was defined. /// </summary> /// <param name="processDefinition"> the process definition that should contains the priority </param> /// <param name="propertyKey"> the key which identifies the property </param> /// <param name="execution"> the current execution </param> /// <param name="errorMsgHead"> the error message header which is used if the evaluation fails </param> /// <returns> the priority defined in the given process </returns> protected internal virtual long?getProcessDefinedPriority(ProcessDefinitionImpl processDefinition, string propertyKey, ExecutionEntity execution, string errorMsgHead) { if (processDefinition != null) { ParameterValueProvider priorityProvider = (ParameterValueProvider)processDefinition.getProperty(propertyKey); if (priorityProvider != null) { return(evaluateValueProvider(priorityProvider, execution, errorMsgHead)); } } return(null); }
protected internal virtual ValidatingMigrationInstructions WrapMigrationInstructions( IMigrationPlan migrationPlan, ProcessDefinitionImpl sourceProcessDefinition, ProcessDefinitionImpl targetProcessDefinition, MigrationPlanValidationReportImpl planReport) { var validatingMigrationInstructions = new ValidatingMigrationInstructions(); foreach (var migrationInstruction in migrationPlan.Instructions) { var instructionReport = new MigrationInstructionValidationReportImpl(migrationInstruction); var sourceActivityId = migrationInstruction.SourceActivityId; var targetActivityId = migrationInstruction.TargetActivityId; if (!ReferenceEquals(sourceActivityId, null) && !ReferenceEquals(targetActivityId, null)) { IPvmActivity sourceActivity = sourceProcessDefinition.FindActivity(sourceActivityId); IPvmActivity targetActivity = targetProcessDefinition.FindActivity(migrationInstruction.TargetActivityId); if (sourceActivity != null && targetActivity != null) { validatingMigrationInstructions.AddInstruction(new ValidatingMigrationInstructionImpl(sourceActivity, targetActivity, migrationInstruction.UpdateEventTrigger)); } else { if (sourceActivity == null) { instructionReport.AddFailure("Source activity '" + sourceActivityId + "' does not exist"); } if (targetActivity == null) { instructionReport.AddFailure("Target activity '" + targetActivityId + "' does not exist"); } } } else { if (ReferenceEquals(sourceActivityId, null)) { instructionReport.AddFailure("Source activity id is null"); } if (ReferenceEquals(targetActivityId, null)) { instructionReport.AddFailure("Target activity id is null"); } } if (instructionReport.HasFailures()) { planReport.AddInstructionReport(instructionReport); } } return(validatingMigrationInstructions); }
public ProcessDefinitionImpl BuildProcessDefinition() { ProcessDefinition = new ProcessDefinitionImpl(); this.definition(); ProcessDefinition.StartState = start(); ProcessDefinition.EndState = end(); ProcessDefinition.Nodes.Add(ProcessDefinition.StartState); ProcessDefinition.Nodes.Add(ProcessDefinition.EndState); resolveReferences(); return(ProcessDefinition); }
public void DeployProcessArchive(byte[] processArchiveBytes) { ParFile parFile = new ParFile(processArchiveBytes); MyProcessDefinitionBuilder builder = new MyProcessDefinitionBuilder(parFile.ProcessDefinition); ProcessDefinitionImpl processDefinition = builder.BuildProcessDefinition(); using (ISession session = NHibernateHelper.OpenSession()) { DbSession nhSession = new DbSession(session); repository.Save(processDefinition, nhSession); } }
protected internal virtual ISet <string> collectParentScopeIdsForActivity(ProcessDefinitionImpl processDefinition, string activityId) { ISet <string> parentScopeIds = new HashSet <string>(); ScopeImpl scope = processDefinition.findActivity(activityId); while (scope != null) { parentScopeIds.Add(scope.Id); scope = scope.FlowScope; } return(parentScopeIds); }
protected internal virtual ScopeImpl getScopeForActivityInstance(ProcessDefinitionImpl processDefinition, ActivityInstance activityInstance) { string scopeId = activityInstance.ActivityId; if (processDefinition.Id.Equals(scopeId)) { return(processDefinition); } else { return(processDefinition.findActivity(scopeId)); } }
protected internal virtual void initialize() { ExecutionEntity processInstance = commandContext.ExecutionManager.findExecutionById(processInstanceId); this.processDefinition = processInstance.getProcessDefinition(); IList <ExecutionEntity> executions = fetchExecutionsForProcessInstance(processInstance); executions.Add(processInstance); IList <ExecutionEntity> leaves = findLeaves(executions); assignExecutionsToActivities(leaves); }
protected internal virtual void Initialize() { ExecutionEntity processInstance = CommandContext.ExecutionManager.FindExecutionById(ProcessInstanceId); this.ProcessDefinition = processInstance.GetProcessDefinition(); IList <IActivityExecution> executions = FetchExecutionsForProcessInstance(processInstance); executions.Add(processInstance); IList <IActivityExecution> leaves = FindLeaves(executions); AssignExecutionsToActivities(leaves); }
public override Void execute(CommandContext commandContext) { ExecutionEntity processInstance = commandContext.ExecutionManager.findExecutionById(processInstanceId); ProcessDefinitionImpl processDefinition = processInstance.getProcessDefinition(); PvmActivity activity = processDefinition.findActivity(activityId); // forbid instantiation of compensation boundary events if (activity != null && "compensationBoundaryCatch".Equals(activity.getProperty("type"))) { throw new ProcessEngineException("Cannot start before activity " + activityId + "; activity " + "is a compensation boundary event."); } return(base.execute(commandContext)); }
private IAuthorizationHandler GetHandlerFromProcessDefinitionId(Int64 processDefinitionId, DbSession dbSession) { ProcessDefinitionImpl processDefinition = null; ; try { processDefinition = (ProcessDefinitionImpl)dbSession.Load(typeof(ProcessDefinitionImpl), processDefinitionId); } catch (ObjectNotFoundException e) { throw new ArgumentException("couldn't check authorization : process definition with id '" + processDefinitionId + "' does not exist : " + e.Message); } return(GetAuthorizationHandler(processDefinition)); }
public virtual void Insert() { CommandContext commandContext = context.Impl.Context.CommandContext; // add link to execution and deployment ExecutionEntity execution = Execution; if (execution != null) { execution.AddJob(this); ProcessDefinitionImpl processDefinition = execution.ProcessDefinition;//.getProcessDefinition(); this.DeploymentId = processDefinition.DeploymentId; } commandContext.JobManager.InsertJob(this); }
public void ReadProcessDataTest() { XmlElement xmlElement = helloWorld1(); ProcessDefinitionImpl processDefinition = new ProcessDefinitionImpl(); ProcessDefinitionBuildContext processDefinitionBuilder = new ProcessDefinitionBuildContext(processDefinition, null, null); processDefinition.ReadProcessData(xmlElement, processDefinitionBuilder); Assert.AreEqual("Hello world 1", processDefinition.Name); Assert.AreEqual("This is the simples process.", processDefinition.Description); Assert.IsNotNull(processDefinition.StartState); Assert.AreEqual("start", processDefinition.StartState.Name); Assert.IsNotNull(processDefinition.EndState); Assert.AreEqual("end", processDefinition.EndState.Name); //activity-state在Nodes裏面,以後再換掉 }
public FlowImpl(String actorId, ProcessInstanceImpl processInstance) { ProcessDefinitionImpl processDefinition = (ProcessDefinitionImpl)processInstance.ProcessDefinition; this._name = "root"; this._actorId = actorId; this._start = DateTime.Now; this._node = processDefinition.StartState; this._processInstance = processInstance; this._subProcessInstances = null; this._parent = null; this._children = null; this._logs = new ListSet(); this._parentReactivation = true; CreateAttributeInstances(processDefinition.Attributes); }