//进入节点 public void enter(TransitionInstance transitionInstance,Token token) { //当工作项实体已完成并且结点为join且逻辑为or时,不再启动 if (!(_task.NodeType == NodeType.Join && _task.LogicType == LogicType.OR && _model.TaskState == TaskState.Complete.ToString())) this.start(); //更新线实例的到达工作项实例id transitionInstance.setToTaskInstanceId(_model.Id).save(); //设置令牌的工作项实例 token.setTaskInstance(this).save(); this.enterNode(); execute(token); //Token token = executionContext.getToken(); //token.setNode(this); //// remove the transition references from the runtime context //executionContext.setTransition(null); //executionContext.setTransitionSource(null); //// execute the node //if (isAsync) //{ //} //else //{ // execute(executionContext); //} }
//进入节点 public void enter(TransitionInstance transitionInstance, Token token) { //当工作项实体已完成并且结点为join且逻辑为or时,不再启动 if (!(_task.NodeType == NodeType.Join && _task.LogicType == LogicType.OR && _model.TaskState == TaskState.Complete.ToString())) { this.start(); } //更新线实例的到达工作项实例id transitionInstance.setToTaskInstanceId(_model.Id).save(); //设置令牌的工作项实例 token.setTaskInstance(this).save(); this.enterNode(); execute(token); //Token token = executionContext.getToken(); //token.setNode(this); //// remove the transition references from the runtime context //executionContext.setTransition(null); //executionContext.setTransitionSource(null); //// execute the node //if (isAsync) //{ //} //else //{ // execute(executionContext); //} }
//执行节点 public void execute(Token token) { var transitions = _task.LeavingTransitions; var bpmContext = _processInstance.getBpmContext(); switch (_task.NodeType) { case NodeType.Start: break; case NodeType.Task: //IsReturnParent(token.GetTaskInstance()); break; case NodeType.Fork: token.activate(false); var childs = new Dictionary<TransitionInstance,Token>(); foreach (Transition transition in transitions) { var transitionsInstance = transition.createTransitionInstance(this); childs.Add(transitionsInstance, this.createToken().setParent(token).activate(true).save()); } foreach (var child in childs) this.leave(child.Key, child.Value); token.save(); break; case NodeType.Join://属于自动结点,外部不需要调用signal var dataPackageToken = bpmContext.loadDataTokenActiveByTaskInstanceId(_model.Id); var packageToken = loadToken(dataPackageToken).activate(true); //创建或加载并激活package令牌 if (_model.TaskState == TaskState.Complete.ToString())//如果流程已往下走,还有线未到达的情况 { token.setTaskInstance(this).setPackage(packageToken).end().save(); return; } token.activate(false).setTaskInstance(this).setPackage(packageToken).save(); //设置当前token未激活 //处理聚合关系 var packageId = packageToken.getTokenModel().Id; var dataJoinParentTokens = bpmContext.loadDataJoinParentTokensByPackageId(packageId); while (dataJoinParentTokens.Count() > 0) { foreach (var item in dataJoinParentTokens) { var parent = this.loadToken(item).setTaskInstance(this).setPackage(packageToken).save(); bpmContext.updateTokenStateByParentId(parent.getTokenModel().Id, TokenState.Ended); } dataJoinParentTokens = bpmContext.loadDataJoinParentTokensByPackageId(packageId); } //根据逻辑关系判断是否往下流转还是等待 switch (_task.LogicType) { case LogicType.AND: //所有的线都已到达 var arrivedTransitionIds = bpmContext.loadDataArrivedTransitionInstance(_model.Id).Select(x => x.TransitionId); var arrivingTransitionIds = _task.ArrivingTransitions.OfType<Transition>().Select(x => x.GetId()); if (arrivingTransitionIds.Except(arrivedTransitionIds).Count() == 0) { packageToken.signal(); } break; case LogicType.OR: packageToken.signal(); break; case LogicType.XOR: // to do break; case LogicType.DISC: // to do break; } break; //case NodeType.Wait: // break; //case NodeType.End: // token.GetTaskInstance().End(); // token.End(); // _processInstance.End(); // bpmContext.save(token.GetTaskInstance()); // bpmContext.save(token); // bpmContext.save(_processInstance); // IsReturnParent(token.GetTaskInstance()); // break; //case NodeType.Decision: // token.Signal(); // break; //case NodeType.Auto: // token.Signal(); // break; //case NodeType.SubFlow: // if (this.GetTask().IsAutoStart) // { // ProcessInstance piStart = bpmContext.newProcessInstance(this.GetTask().SubFlowName, _processInstance.GetId()); //新增流程实例 // piStart.Start(); // bpmContext.save(piStart); // } // break; default: break; } }
//执行节点 public void execute(Token token) { var transitions = _task.LeavingTransitions; var bpmContext = _processInstance.getBpmContext(); switch (_task.NodeType) { case NodeType.Start: break; case NodeType.Task: //IsReturnParent(token.GetTaskInstance()); break; case NodeType.Fork: token.activate(false); var childs = new Dictionary <TransitionInstance, Token>(); foreach (Transition transition in transitions) { var transitionsInstance = transition.createTransitionInstance(this); childs.Add(transitionsInstance, this.createToken().setParent(token).activate(true).save()); } foreach (var child in childs) { this.leave(child.Key, child.Value); } token.save(); break; case NodeType.Join: //属于自动结点,外部不需要调用signal var dataPackageToken = bpmContext.loadDataTokenActiveByTaskInstanceId(_model.Id); var packageToken = loadToken(dataPackageToken).activate(true); //创建或加载并激活package令牌 if (_model.TaskState == TaskState.Complete.ToString()) //如果流程已往下走,还有线未到达的情况 { token.setTaskInstance(this).setPackage(packageToken).end().save(); return; } token.activate(false).setTaskInstance(this).setPackage(packageToken).save(); //设置当前token未激活 //处理聚合关系 var packageId = packageToken.getTokenModel().Id; var dataJoinParentTokens = bpmContext.loadDataJoinParentTokensByPackageId(packageId); while (dataJoinParentTokens.Count() > 0) { foreach (var item in dataJoinParentTokens) { var parent = this.loadToken(item).setTaskInstance(this).setPackage(packageToken).save(); bpmContext.updateTokenStateByParentId(parent.getTokenModel().Id, TokenState.Ended); } dataJoinParentTokens = bpmContext.loadDataJoinParentTokensByPackageId(packageId); } //根据逻辑关系判断是否往下流转还是等待 switch (_task.LogicType) { case LogicType.AND: //所有的线都已到达 var arrivedTransitionIds = bpmContext.loadDataArrivedTransitionInstance(_model.Id).Select(x => x.TransitionId); var arrivingTransitionIds = _task.ArrivingTransitions.OfType <Transition>().Select(x => x.GetId()); if (arrivingTransitionIds.Except(arrivedTransitionIds).Count() == 0) { packageToken.signal(); } break; case LogicType.OR: packageToken.signal(); break; case LogicType.XOR: // to do break; case LogicType.DISC: // to do break; } break; //case NodeType.Wait: // break; //case NodeType.End: // token.GetTaskInstance().End(); // token.End(); // _processInstance.End(); // bpmContext.save(token.GetTaskInstance()); // bpmContext.save(token); // bpmContext.save(_processInstance); // IsReturnParent(token.GetTaskInstance()); // break; //case NodeType.Decision: // token.Signal(); // break; //case NodeType.Auto: // token.Signal(); // break; //case NodeType.SubFlow: // if (this.GetTask().IsAutoStart) // { // ProcessInstance piStart = bpmContext.newProcessInstance(this.GetTask().SubFlowName, _processInstance.GetId()); //新增流程实例 // piStart.Start(); // bpmContext.save(piStart); // } // break; default: break; } }