/// <summary> /// EOrJoin合并时的节点完成方法 /// 根据前置转移上定义的是否强制分支来判断完成合并节点 /// </summary> /// <param name="processInstance">流程实例</param> /// <param name="transitionGUID">转移GUID</param> /// <param name="fromActivity">起始活动</param> /// <param name="fromActivityInstance">起始活动实例</param> /// <param name="runner">运行者</param> /// <param name="session">会话</param> private NodeAutoExecutedResult CompleteAutomaticallyByForcedBranchesCount(ProcessInstanceEntity processInstance, string transitionGUID, ActivityEntity fromActivity, ActivityInstanceEntity fromActivityInstance, WfAppRunner runner, IDbSession session) { NodeAutoExecutedResult result = NodeAutoExecutedResult.CreateGatewayExecutedResult(NodeAutoExecutedStatus.Unknown); IList <TransitionEntity> forcedTransitionList = null; var tokensCountRequired = base.ProcessModel.GetForcedBranchesCountBeforeEOrJoin(GatewayActivity, out forcedTransitionList); if (tokensCountRequired == 0) { result = NodeAutoExecutedResult.CreateGatewayExecutedResult(NodeAutoExecutedStatus.Failed); throw new WfXpdlException("前置转移并没有定义任何的强制分支属性,强制分支数目为零,请重新查看流程图!"); } //根据强制分支的数目和具体分支来完成增强合并节点 var forcedCount = forcedTransitionList.Where(t => t.TransitionGUID == transitionGUID).Count(); if (forcedCount == 0) { //当前执行的分支不是强制分支,直接返回就可以 result = NodeAutoExecutedResult.CreateGatewayExecutedResult(NodeAutoExecutedStatus.NotForcedBrancheWhenEOrJoin); } else if (forcedCount == 1) { result = CompleteAutomaticallyInternal(processInstance, transitionGUID, fromActivity, fromActivityInstance, tokensCountRequired, runner, session); } return(result); }
/// <summary> /// 自动完成 /// </summary> /// <param name="processInstance">流程实例</param> /// <param name="transitionGUID">转移GUID</param> /// <param name="fromActivity">起始活动</param> /// <param name="fromActivityInstance">起始活动实例</param> /// <param name="runner">运行者</param> /// <param name="session">会话</param> /// <returns>网关执行结果</returns> public NodeAutoExecutedResult CompleteAutomaticlly(ProcessInstanceEntity processInstance, string transitionGUID, ActivityEntity fromActivity, ActivityInstanceEntity fromActivityInstance, WfAppRunner runner, IDbSession session) { //插入实例数据 var gatewayActivityInstance = base.CreateActivityInstanceObject(base.GatewayActivity, processInstance, runner); gatewayActivityInstance.GatewayDirectionTypeID = (short)GatewayDirectionEnum.AndSplit; base.InsertActivityInstance(gatewayActivityInstance, session); base.CompleteActivityInstance(gatewayActivityInstance.ID, runner, session); gatewayActivityInstance.ActivityState = (short)ActivityStateEnum.Completed; base.GatewayActivityInstance = gatewayActivityInstance; //写节点转移实例数据 base.InsertTransitionInstance(processInstance, transitionGUID, fromActivityInstance, gatewayActivityInstance, TransitionTypeEnum.Forward, TransitionFlyingTypeEnum.NotFlying, runner, session); NodeAutoExecutedResult result = NodeAutoExecutedResult.CreateGatewayExecutedResult(NodeAutoExecutedStatus.Successed); return result; }
internal static NodeAutoExecutedResult CreateGatewayExecutedResult(NodeAutoExecutedStatus status) { NodeAutoExecutedResult result = new NodeAutoExecutedResult(NodeAutoExecutedStatus.Unknown, "Gateway节点的执行状态未知!"); switch (status) { case NodeAutoExecutedStatus.Successed: result = new NodeAutoExecutedResult(NodeAutoExecutedStatus.Successed, "Gateway节点成功执行!"); break; case NodeAutoExecutedStatus.FallBehindOfXOrJoin: result = new NodeAutoExecutedResult(NodeAutoExecutedStatus.FallBehindOfXOrJoin, "第一个满足条件的节点已经执行,互斥合并节点不能再次被实例化!"); break; default: break; } return(result); }
/// <summary> /// EOrJoin合并时的节点完成方法 /// 前端动态传递要合并的Tokens的数目 /// </summary> /// <param name="processInstance">流程实例</param> /// <param name="transitionGUID">转移GUID</param> /// <param name="fromActivity">起始活动</param> /// <param name="fromActivityInstance">起始活动实例</param> /// <param name="runner">运行者</param> /// <param name="session">会话</param> private NodeAutoExecutedResult CompleteAutomaticallyByTokensCount(ProcessInstanceEntity processInstance, string transitionGUID, ActivityEntity fromActivity, ActivityInstanceEntity fromActivityInstance, WfAppRunner runner, IDbSession session) { NodeAutoExecutedResult result = NodeAutoExecutedResult.CreateGatewayExecutedResult(NodeAutoExecutedStatus.Unknown); if (runner.ControlParameterSheet == null || runner.ControlParameterSheet.EOrJoinTokenPassCount <= 0) { result = NodeAutoExecutedResult.CreateGatewayExecutedResult(NodeAutoExecutedStatus.Failed); throw new WfXpdlException("流程定义错误:强制或合并节点的合并通过数目[EOrJoinTokenPassCount]定义错误或缺失,请查看流程图定义!"); } var tokensCountRequired = runner.ControlParameterSheet.EOrJoinTokenPassCount; result = CompleteAutomaticallyInternal(processInstance, transitionGUID, fromActivity, fromActivityInstance, tokensCountRequired, runner, session); return(result); }
internal static NodeAutoExecutedResult CreateGatewayExecutedResult(NodeAutoExecutedStatus status) { NodeAutoExecutedResult result = new NodeAutoExecutedResult(NodeAutoExecutedStatus.Unknown, "Unknown Gateway executing status!"); switch (status) { case NodeAutoExecutedStatus.Successed: result = new NodeAutoExecutedResult(NodeAutoExecutedStatus.Successed, "Gateway executed successfully!"); break; case NodeAutoExecutedStatus.FallBehindOfXOrJoin: result = new NodeAutoExecutedResult(NodeAutoExecutedStatus.FallBehindOfXOrJoin, "The first matched node has been executed(XOrJoin)!"); break; default: break; } return(result); }
/// <summary> /// 置开始节点为结束状态 /// </summary> /// <param name="processInstance"></param> /// <param name="activityResource"></param> /// <param name="session"></param> /// <returns></returns> private NodeAutoExecutedResult CompleteAutomaticlly(ProcessInstanceEntity processInstance, ActivityResource activityResource, IDbSession session) { //开始节点没前驱信息 var fromActivityInstance = base.CreateActivityInstanceObject(base.Linker.FromActivity, processInstance, activityResource.AppRunner); base.ActivityInstanceManager.Insert(fromActivityInstance, session); base.ActivityInstanceManager.Complete(fromActivityInstance.ID, activityResource.AppRunner, session); fromActivityInstance.ActivityState = (short)ActivityStateEnum.Completed; base.Linker.FromActivityInstance = fromActivityInstance; NodeAutoExecutedResult result = NodeAutoExecutedResult.CreateGatewayExecutedResult(NodeAutoExecutedStatus.Successed); return(result); }
/// <summary> /// EOrJoin合并时的节点完成方法 /// </summary> /// <param name="processInstance">流程实例</param> /// <param name="transitionGUID">转移GUID</param> /// <param name="fromActivity">起始活动</param> /// <param name="fromActivityInstance">起始活动实例</param> /// <param name="runner">运行者</param> /// <param name="session">会话</param> public NodeAutoExecutedResult CompleteAutomaticlly(ProcessInstanceEntity processInstance, string transitionGUID, ActivityEntity fromActivity, ActivityInstanceEntity fromActivityInstance, WfAppRunner runner, IDbSession session) { NodeAutoExecutedResult result = NodeAutoExecutedResult.CreateGatewayExecutedResult(NodeAutoExecutedStatus.Unknown); //根据强制或合并类型来处理 if (GatewayActivity.GatewayJoinPassType == GatewayJoinPassEnum.TokenCountPass) { result = CompleteAutomaticallyByTokensCount(processInstance, transitionGUID, fromActivity, fromActivityInstance, runner, session); } else if (GatewayActivity.GatewayJoinPassType == GatewayJoinPassEnum.ForcedBranchPass) { result = CompleteAutomaticallyByForcedBranchesCount(processInstance, transitionGUID, fromActivity, fromActivityInstance, runner, session); } return(result); }
/// <summary> /// 自动完成 /// </summary> /// <param name="processInstance">流程实例</param> /// <param name="transitionGUID">转移GUID</param> /// <param name="fromActivity">起始活动</param> /// <param name="fromActivityInstance">起始活动实例</param> /// <param name="runner">运行者</param> /// <param name="session">会话</param> /// <returns>网关执行结果</returns> public NodeAutoExecutedResult CompleteAutomaticlly(ProcessInstanceEntity processInstance, string transitionGUID, ActivityEntity fromActivity, ActivityInstanceEntity fromActivityInstance, WfAppRunner runner, IDbSession session) { NodeAutoExecutedResult result = NodeAutoExecutedResult.CreateGatewayExecutedResult(NodeAutoExecutedStatus.Unknown); //XOrJoin合并,直接置为完成状态,因为始终只有一个分支可以得到执行,其它分支被排斥 var gatewayActivityInstance = base.CreateActivityInstanceObject(base.GatewayActivity, processInstance, runner); gatewayActivityInstance.GatewayDirectionTypeID = (short)GatewayDirectionEnum.XOrJoin; base.InsertActivityInstance(gatewayActivityInstance, session); base.CompleteActivityInstance(gatewayActivityInstance.ID, runner, session); gatewayActivityInstance.ActivityState = (short)ActivityStateEnum.Completed; base.GatewayActivityInstance = gatewayActivityInstance; //写节点转移实例数据 base.InsertTransitionInstance(processInstance, transitionGUID, fromActivityInstance, gatewayActivityInstance, TransitionTypeEnum.Forward, TransitionFlyingTypeEnum.NotFlying, runner, session); result = NodeAutoExecutedResult.CreateGatewayExecutedResult(NodeAutoExecutedStatus.Successed); return(result); }
/// <summary> /// 自动完成 /// </summary> /// <param name="processInstance">流程实例</param> /// <param name="transitionGUID">转移GUID</param> /// <param name="fromActivity">起始活动</param> /// <param name="fromActivityInstance">起始活动实例</param> /// <param name="runner">运行者</param> /// <param name="session">会话</param> /// <returns>网关执行结果</returns> public NodeAutoExecutedResult CompleteAutomaticlly(ProcessInstanceEntity processInstance, string transitionGUID, ActivityEntity fromActivity, ActivityInstanceEntity fromActivityInstance, WfAppRunner runner, IDbSession session) { //检查是否有运行中的合并节点实例 ActivityInstanceEntity joinNode = base.ActivityInstanceManager.GetActivityRunning( processInstance.ID, base.GatewayActivity.ActivityGUID, session); int tokensRequired = 0; int tokensHad = 0; if (joinNode == null) { var joinActivityInstance = base.CreateActivityInstanceObject(base.GatewayActivity, processInstance, runner); //计算总需要的Token数目 joinActivityInstance.TokensRequired = GetTokensRequired(processInstance.AppInstanceID, processInstance.ID, base.GatewayActivity); joinActivityInstance.TokensHad = 1; tokensRequired = joinActivityInstance.TokensRequired; //进入运行状态 joinActivityInstance.ActivityState = (short)ActivityStateEnum.Running; joinActivityInstance.GatewayDirectionTypeID = (short)GatewayDirectionEnum.AndJoinMI; //写入默认第一次的预选步骤用户列表 joinActivityInstance.NextStepPerformers = NextStepUtility.SerializeNextStepPerformers(runner.NextActivityPerformers); base.InsertActivityInstance(joinActivityInstance, session); base.InsertTransitionInstance(processInstance, transitionGUID, fromActivityInstance, joinActivityInstance, TransitionTypeEnum.Forward, TransitionFlyingTypeEnum.NotFlying, runner, session); } else { //更新节点的活动实例属性 base.GatewayActivityInstance = joinNode; tokensRequired = base.GatewayActivityInstance.TokensRequired; tokensHad = base.GatewayActivityInstance.TokensHad; //更新Token数目 base.ActivityInstanceManager.IncreaseTokensHad(base.GatewayActivityInstance.ID, runner, session); base.InsertTransitionInstance(processInstance, transitionGUID, fromActivityInstance, joinNode, TransitionTypeEnum.Forward, TransitionFlyingTypeEnum.NotFlying, runner, session); } if ((tokensHad + 1) == tokensRequired) { //如果达到完成节点的Token数,则设置该节点状态为完成 base.CompleteActivityInstance(base.GatewayActivityInstance.ID, runner, session); base.GatewayActivityInstance.ActivityState = (short)ActivityStateEnum.Completed; } NodeAutoExecutedResult result = NodeAutoExecutedResult.CreateGatewayExecutedResult( NodeAutoExecutedStatus.Successed); return(result); }
/// <summary> /// 递归执行节点 /// 1)创建普通节点的任务 /// 2)创建会签节点的任务 /// </summary> /// <param name="fromActivity">起始活动</param> /// <param name="fromActivityInstance">起始活动实例</param> /// <param name="isNotParsedForward">是否跳跃</param> /// <param name="root">根节点</param> /// <param name="conditionKeyValuePair">条件key-value</param> /// <param name="mediatorResult">执行结果的返回列表</param> protected void ContinueForwardCurrentNodeRecurisivly(ActivityEntity fromActivity, ActivityInstanceEntity fromActivityInstance, NextActivityComponent root, IDictionary <string, string> conditionKeyValuePair, Boolean isNotParsedForward, ref List <WfNodeMediatedResult> mediatorResult) { foreach (NextActivityComponent comp in root) { if (comp.HasChildren) { NodeAutoExecutedResult nodeExecutedResult = null; if (XPDLHelper.IsGatewayComponentNode(comp.Activity.ActivityType) == true) { //此节点类型为任务节点:根据fromActivityInstance的类型判断是否可以创建任务 if (fromActivityInstance.ActivityState == (short)ActivityStateEnum.Completed) { //此节点类型为分支或合并节点类型:首先需要实例化当前节点(自动完成) NodeMediatorGateway gatewayNodeMediator = NodeMediatorFactory.CreateNodeMediatorGateway(comp.Activity, this.ActivityForwardContext.ProcessModel, Session); ICompleteGatewayAutomaticlly autoGateway = (ICompleteGatewayAutomaticlly)gatewayNodeMediator; nodeExecutedResult = autoGateway.CompleteAutomaticlly(ActivityForwardContext.ProcessInstance, comp.Transition.TransitionGUID, fromActivity, fromActivityInstance, ActivityForwardContext.ActivityResource.AppRunner, Session); if (nodeExecutedResult.Status == NodeAutoExecutedStatus.Successed) { //遍历后续子节点 ContinueForwardCurrentNodeRecurisivly(gatewayNodeMediator.GatewayActivity, gatewayNodeMediator.GatewayActivityInstance, comp, conditionKeyValuePair, isNotParsedForward, ref mediatorResult); } else { mediatorResult.Add(WfNodeMediatedResult.CreateNodeMediatedResultWithException( WfNodeMediatedFeedback.OrJoinOneBranchHasBeenFinishedWaittingOthers)); LogManager.RecordLog("ContinueForwardCurrentNodeRecurisivlyExeception", LogEventType.Exception, LogPriority.Normal, null, new WfRuntimeException( LocalizeHelper.GetEngineMessage("nodemediator.ContinueForwardCurrentNodeRecurisivly.warn")) ); } } else { //下一步的任务节点没有创建,需给出提示信息 if (IsWaitingOneOfJoin(fromActivity.GatewayDirectionType) == true) { mediatorResult.Add(WfNodeMediatedResult.CreateNodeMediatedResultWithException( WfNodeMediatedFeedback.NeedOtherGatewayBranchesToJoin)); LogManager.RecordLog("NodeMediator.ContinueForwardCurrentNodeRecurisivly.IsWaintingOneOfJoin.Exception", LogEventType.Exception, LogPriority.Normal, null, new WfRuntimeException(LocalizeHelper.GetEngineMessage("nodemediator.ContinueForwardCurrentNodeRecurisivly.waitingothers.warn")) ); } else { mediatorResult.Add(WfNodeMediatedResult.CreateNodeMediatedResultWithException( WfNodeMediatedFeedback.OtherUnknownReasonToDebug)); LogManager.RecordLog("NodeMediator.ContinueForwardCurrentNodeRecurisivly.IsWaintingOneOfJoin.OtherUnknownReason.Exception", LogEventType.Exception, LogPriority.Normal, null, new WfRuntimeException(LocalizeHelper.GetEngineMessage("nodemediator.ContinueForwardCurrentNodeRecurisivly.otherreason.warn")) ); } } } else { mediatorResult.Add(WfNodeMediatedResult.CreateNodeMediatedResultWithException( WfNodeMediatedFeedback.UnknownNodeTypeToWatch)); LogManager.RecordLog("NodeMediator.UnknownType.Exception", LogEventType.Exception, LogPriority.Normal, null, new WfRuntimeException(LocalizeHelper.GetEngineMessage("nodemediator.ContinueForwardCurrentNodeRecurisivly.unknowntype.warn", comp.Activity.ActivityType.ToString())) ); } } else if (comp.Activity.ActivityType == ActivityTypeEnum.TaskNode) //普通任务节点 { //此节点类型为任务节点:根据fromActivityInstance的类型判断是否可以创建任务 if (fromActivityInstance.ActivityState == (short)ActivityStateEnum.Completed) { //创建新任务节点 NodeMediator taskNodeMediator = new NodeMediatorTask(Session); taskNodeMediator.CreateActivityTaskTransitionInstance(comp.Activity, ActivityForwardContext.ProcessInstance, fromActivityInstance, comp.Transition.TransitionGUID, comp.Transition.DirectionType == TransitionDirectionTypeEnum.Loop ? TransitionTypeEnum.Loop : TransitionTypeEnum.Forward, //根据Direction方向确定是否是自身循环 isNotParsedForward == true ? TransitionFlyingTypeEnum.ForwardFlying : TransitionFlyingTypeEnum.NotFlying, ActivityForwardContext.ActivityResource, Session); } else { //下一步的任务节点没有创建,需给出提示信息 if (IsWaitingOneOfJoin(fromActivity.GatewayDirectionType) == true) { mediatorResult.Add(WfNodeMediatedResult.CreateNodeMediatedResultWithException( WfNodeMediatedFeedback.NeedOtherGatewayBranchesToJoin)); LogManager.RecordLog("NodeMediator.TaskNode.NeedOtherGatewayBranchesToJoin.Exception", LogEventType.Exception, LogPriority.Normal, null, new WfRuntimeException(LocalizeHelper.GetEngineMessage("nodemediator.ContinueForwardCurrentNodeRecurisivly.waitingothers.warn")) ); } else { mediatorResult.Add(WfNodeMediatedResult.CreateNodeMediatedResultWithException( WfNodeMediatedFeedback.OtherUnknownReasonToDebug)); LogManager.RecordLog("NodeMediator.TaskNode.NeedOtherGatewayBranchesToJoin.OtherUnkownReaseon.Exception", LogEventType.Exception, LogPriority.Normal, null, new WfRuntimeException(LocalizeHelper.GetEngineMessage("nodemediator.ContinueForwardCurrentNodeRecurisivly.otherreason.warn")) ); } } } else if (comp.Activity.ActivityType == ActivityTypeEnum.SubProcessNode) //子流程节点 { //节点类型为subprocessnode if (fromActivityInstance.ActivityState == (short)ActivityStateEnum.Completed) { //实例化subprocess节点数据 NodeMediator subNodeMediator = new NodeMediatorSubProcess(Session); subNodeMediator.CreateActivityTaskTransitionInstance(comp.Activity, ActivityForwardContext.ProcessInstance, fromActivityInstance, comp.Transition.TransitionGUID, comp.Transition.DirectionType == TransitionDirectionTypeEnum.Loop ? TransitionTypeEnum.Loop : TransitionTypeEnum.Forward, TransitionFlyingTypeEnum.NotFlying, ActivityForwardContext.ActivityResource, Session); } } else if (comp.Activity.ActivityType == ActivityTypeEnum.EndNode) //结束节点 { if (fromActivityInstance.ActivityState == (short)ActivityStateEnum.Completed) { //此节点为完成结束节点,结束流程 var endMediator = NodeMediatorFactory.CreateNodeMediatorEnd(ActivityForwardContext, comp.Activity, Session); endMediator.Linker.ToActivity = comp.Activity; //创建结束节点实例及转移数据 endMediator.CreateActivityTaskTransitionInstance(comp.Activity, ActivityForwardContext.ProcessInstance, fromActivityInstance, comp.Transition.TransitionGUID, TransitionTypeEnum.Forward, TransitionFlyingTypeEnum.NotFlying, ActivityForwardContext.ActivityResource, Session); //执行结束节点中的业务逻辑 endMediator.ExecuteWorkItem(); } else { //结束节点没有创建,需给出提示信息 if (IsWaitingOneOfJoin(fromActivity.GatewayDirectionType) == true) { mediatorResult.Add(WfNodeMediatedResult.CreateNodeMediatedResultWithException( WfNodeMediatedFeedback.NeedOtherGatewayBranchesToJoin)); LogManager.RecordLog("NodeMediator.EndNode.NeedOtherGatewayBranchesToJoin.Exception", LogEventType.Exception, LogPriority.Normal, null, new WfRuntimeException(LocalizeHelper.GetEngineMessage("nodemediator.ContinueForwardCurrentNodeRecurisivly.waitingothers.warn")) ); } else { mediatorResult.Add(WfNodeMediatedResult.CreateNodeMediatedResultWithException( WfNodeMediatedFeedback.OtherUnknownReasonToDebug)); LogManager.RecordLog("NodeMediator.EndNode.NeedOtherGatewayBranchesToJoin.OtherUnkownReaseon.Exception", LogEventType.Exception, LogPriority.Normal, null, new WfRuntimeException(LocalizeHelper.GetEngineMessage("nodemediator.ContinueForwardCurrentNodeRecurisivly.otherreason.warn")) ); } } } else { mediatorResult.Add(WfNodeMediatedResult.CreateNodeMediatedResultWithException( WfNodeMediatedFeedback.UnknownNodeTypeToWatch)); LogManager.RecordLog("NodeMediator.UnkonwNodeType.Exception", LogEventType.Exception, LogPriority.Normal, null, new WfRuntimeException(LocalizeHelper.GetEngineMessage("nodemediator.ContinueForwardCurrentNodeRecurisivly.unknowntype.warn", comp.Activity.ActivityType.ToString())) ); } } }
/// <summary> /// EOrJoin合并时的节点完成方法 /// 内部执行逻辑 /// </summary> /// <param name="processInstance">流程实例</param> /// <param name="transitionGUID">转移GUID</param> /// <param name="fromActivity">起始活动</param> /// <param name="fromActivityInstance">起始活动实例</param> /// <param name="tokensCountRequired">合并要求的Token数目</param> /// <param name="runner">运行者</param> /// <param name="session">会话</param> private NodeAutoExecutedResult CompleteAutomaticallyInternal(ProcessInstanceEntity processInstance, string transitionGUID, ActivityEntity fromActivity, ActivityInstanceEntity fromActivityInstance, int tokensCountRequired, WfAppRunner runner, IDbSession session) { NodeAutoExecutedResult result = NodeAutoExecutedResult.CreateGatewayExecutedResult(NodeAutoExecutedStatus.Unknown); //当前执行的分支就是强制分支 //检查是否有运行中的合并节点实例 ActivityInstanceEntity joinNode = base.ActivityInstanceManager.GetActivityRunning( processInstance.ID, base.GatewayActivity.ActivityGUID, session);; if (joinNode == null) { //第一个分支首次运行 joinNode = base.CreateActivityInstanceObject(base.GatewayActivity, processInstance, runner); //计算总需要的Token数目 joinNode.TokensRequired = tokensCountRequired; joinNode.TokensHad = 1; //进入运行状态 joinNode.ActivityState = (short)ActivityStateEnum.Running; joinNode.GatewayDirectionTypeID = (short)GatewayDirectionEnum.OrJoin; //写入默认第一次的预选步骤用户列表 joinNode.NextStepPerformers = NextStepUtility.SerializeNextStepPerformers(runner.NextActivityPerformers); base.InsertActivityInstance(joinNode, session); base.InsertTransitionInstance(processInstance, transitionGUID, fromActivityInstance, joinNode, TransitionTypeEnum.Forward, TransitionFlyingTypeEnum.NotFlying, runner, session); } else { //更新节点的活动实例属性 joinNode.TokensHad += 1; base.GatewayActivityInstance = joinNode; //更新Token数目 base.ActivityInstanceManager.IncreaseTokensHad(base.GatewayActivityInstance.ID, runner, session); base.InsertTransitionInstance(processInstance, transitionGUID, fromActivityInstance, joinNode, TransitionTypeEnum.Forward, TransitionFlyingTypeEnum.NotFlying, runner, session); } //判断是否到达合并节点的通过Token数目要求 if (joinNode.TokensHad == joinNode.TokensRequired) { //如果达到完成节点的Token数,则设置该节点状态为完成 base.CompleteActivityInstance(base.GatewayActivityInstance.ID, runner, session); base.GatewayActivityInstance.ActivityState = (short)ActivityStateEnum.Completed; //更新其它分支上的待办节点为阻止状态(CanRenewInstance = 0) base.ActivityInstanceManager.UpdateActivityInstanceBlockedBetweenSplitJoin(base.GatewayActivity, base.GatewayActivityInstance, base.ProcessModel, session); result = NodeAutoExecutedResult.CreateGatewayExecutedResult(NodeAutoExecutedStatus.Successed); } else if (joinNode.TokensHad < joinNode.TokensRequired) { result = NodeAutoExecutedResult.CreateGatewayExecutedResult(NodeAutoExecutedStatus.WaitingForOthersJoin); } return(result); }
/// <summary> /// 递归执行节点 /// 1)创建普通节点的任务 /// 2)创建会签节点的任务 /// </summary> /// <param name="fromActivity">起始活动</param> /// <param name="fromActivityInstance">起始活动实例</param> /// <param name="isNotParsedForward">是否跳跃</param> /// <param name="root">根节点</param> /// <param name="conditionKeyValuePair">条件key-value</param> /// <param name="mediatorResult">执行结果的返回列表</param> protected void ContinueForwardCurrentNodeRecurisivly(ActivityEntity fromActivity, ActivityInstanceEntity fromActivityInstance, NextActivityComponent root, IDictionary <string, string> conditionKeyValuePair, Boolean isNotParsedForward, ref List <WfNodeMediatedResult> mediatorResult) { foreach (NextActivityComponent comp in root) { if (comp.HasChildren) { NodeAutoExecutedResult nodeExecutedResult = null; if (XPDLHelper.IsGatewayComponentNode(comp.Activity.ActivityType) == true) { //此节点类型为任务节点:根据fromActivityInstance的类型判断是否可以创建任务 if (fromActivityInstance.ActivityState == (short)ActivityStateEnum.Completed) { //此节点类型为分支或合并节点类型:首先需要实例化当前节点(自动完成) NodeMediatorGateway gatewayNodeMediator = NodeMediatorFactory.CreateNodeMediatorGateway(comp.Activity, this.ActivityForwardContext.ProcessModel, Session); ICompleteAutomaticlly autoGateway = (ICompleteAutomaticlly)gatewayNodeMediator; nodeExecutedResult = autoGateway.CompleteAutomaticlly(ActivityForwardContext.ProcessInstance, comp.Transition.TransitionGUID, fromActivity, fromActivityInstance, ActivityForwardContext.ActivityResource.AppRunner, Session); if (nodeExecutedResult.Status == NodeAutoExecutedStatus.Successed) { //遍历后续子节点 ContinueForwardCurrentNodeRecurisivly(gatewayNodeMediator.GatewayActivity, gatewayNodeMediator.GatewayActivityInstance, comp, conditionKeyValuePair, isNotParsedForward, ref mediatorResult); } else { mediatorResult.Add(WfNodeMediatedResult.CreateNodeMediatedResultWithException( WfNodeMediatedFeedback.OrJoinOneBranchHasBeenFinishedWaittingOthers)); LogManager.RecordLog("递归执行节点方法异常", LogEventType.Exception, LogPriority.Normal, null, new WfRuntimeException( string.Format("第一个满足条件的节点已经被成功执行,此后的节点被阻止在OrJoin类型的节点! 详细状态类型:{0}", nodeExecutedResult.Status.ToString()) )); } } else { //下一步的任务节点没有创建,需给出提示信息 if (IsWaitingOneOfJoin(fromActivity.GatewayDirectionType) == true) { mediatorResult.Add(WfNodeMediatedResult.CreateNodeMediatedResultWithException( WfNodeMediatedFeedback.NeedOtherGatewayBranchesToJoin)); LogManager.RecordLog("递归执行节点方法异常", LogEventType.Exception, LogPriority.Normal, null, new WfRuntimeException("等待其它需要合并的分支!")); } else { mediatorResult.Add(WfNodeMediatedResult.CreateNodeMediatedResultWithException( WfNodeMediatedFeedback.OtherUnknownReasonToDebug)); LogManager.RecordLog("递归执行节点方法异常", LogEventType.Exception, LogPriority.Normal, null, new WfRuntimeException("等待其它需要合并的分支或发生其它类型的异常!")); } } } else if (XPDLHelper.IsIntermediateEventComponentNode(comp.Activity.ActivityType) == true) { //中间事件类型节点,调用外部业务逻辑,然后流程继续向下流转 NodeMediatorEvent eventNodeMediator = NodeMediatorFactory.CreateNodeMediatorEvent(ActivityForwardContext, comp.Activity, this.ActivityForwardContext.ProcessModel, Session); eventNodeMediator.ExecuteWorkItem(); ICompleteAutomaticlly autoEvent = (ICompleteAutomaticlly)eventNodeMediator; nodeExecutedResult = autoEvent.CompleteAutomaticlly(ActivityForwardContext.ProcessInstance, comp.Transition.TransitionGUID, fromActivity, fromActivityInstance, ActivityForwardContext.ActivityResource.AppRunner, Session); if (nodeExecutedResult.Status == NodeAutoExecutedStatus.Successed) { //遍历后续子节点 ContinueForwardCurrentNodeRecurisivly(eventNodeMediator.EventActivity, eventNodeMediator.EventActivityInstance, comp, conditionKeyValuePair, isNotParsedForward, ref mediatorResult); } else { mediatorResult.Add(WfNodeMediatedResult.CreateNodeMediatedResultWithException( WfNodeMediatedFeedback.IntermediateEventFailed)); LogManager.RecordLog("中间事件节点执行方法异常", LogEventType.Exception, LogPriority.Normal, null, new WfRuntimeException(nodeExecutedResult.Status.ToString())); } } else { mediatorResult.Add(WfNodeMediatedResult.CreateNodeMediatedResultWithException( WfNodeMediatedFeedback.UnknownNodeTypeToWatch)); LogManager.RecordLog("递归执行节点方法异常", LogEventType.Exception, LogPriority.Normal, null, new WfRuntimeException(string.Format("XML文件定义了未知的节点类型,执行失败,节点类型信息:{0}", comp.Activity.ActivityType.ToString())) ); } } else if (comp.Activity.ActivityType == ActivityTypeEnum.TaskNode) //普通任务节点 { //此节点类型为任务节点:根据fromActivityInstance的类型判断是否可以创建任务 if (fromActivityInstance.ActivityState == (short)ActivityStateEnum.Completed) { //创建新任务节点 NodeMediator taskNodeMediator = new NodeMediatorTask(Session); taskNodeMediator.CreateActivityTaskTransitionInstance(comp.Activity, ActivityForwardContext.ProcessInstance, fromActivityInstance, comp.Transition.TransitionGUID, comp.Transition.DirectionType == TransitionDirectionTypeEnum.Loop ? TransitionTypeEnum.Loop : TransitionTypeEnum.Forward, //根据Direction方向确定是否是自身循环 isNotParsedForward == true ? TransitionFlyingTypeEnum.ForwardFlying : TransitionFlyingTypeEnum.NotFlying, ActivityForwardContext.ActivityResource, Session); } else { //下一步的任务节点没有创建,需给出提示信息 if (IsWaitingOneOfJoin(fromActivity.GatewayDirectionType) == true) { mediatorResult.Add(WfNodeMediatedResult.CreateNodeMediatedResultWithException( WfNodeMediatedFeedback.NeedOtherGatewayBranchesToJoin)); LogManager.RecordLog("递归执行节点方法异常", LogEventType.Exception, LogPriority.Normal, null, new WfRuntimeException("等待其它需要合并的分支!")); } else { mediatorResult.Add(WfNodeMediatedResult.CreateNodeMediatedResultWithException( WfNodeMediatedFeedback.OtherUnknownReasonToDebug)); LogManager.RecordLog("递归执行节点方法异常", LogEventType.Exception, LogPriority.Normal, null, new WfRuntimeException("等待其它需要合并的分支或发生其它类型的异常!")); } } } else if (comp.Activity.ActivityType == ActivityTypeEnum.MultipleInstanceNode) //多实例会签节点 { //此节点类型为任务节点:根据fromActivityInstance的类型判断是否可以创建任务 if (fromActivityInstance.ActivityState == (short)ActivityStateEnum.Completed) { //创建新多实例节点 NodeMediator mediatorMICreator = new NodeMediatorMICreator(Session); mediatorMICreator.CreateActivityTaskTransitionInstance(comp.Activity, ActivityForwardContext.ProcessInstance, fromActivityInstance, comp.Transition.TransitionGUID, comp.Transition.DirectionType == TransitionDirectionTypeEnum.Loop ? TransitionTypeEnum.Loop : TransitionTypeEnum.Forward, //根据Direction方向确定是否是自身循环 isNotParsedForward == true ? TransitionFlyingTypeEnum.ForwardFlying : TransitionFlyingTypeEnum.NotFlying, ActivityForwardContext.ActivityResource, Session); } else { //下一步的任务节点没有创建,需给出提示信息 if (IsWaitingOneOfJoin(fromActivity.GatewayDirectionType) == true) { mediatorResult.Add(WfNodeMediatedResult.CreateNodeMediatedResultWithException( WfNodeMediatedFeedback.NeedOtherGatewayBranchesToJoin)); LogManager.RecordLog("递归执行节点方法异常", LogEventType.Exception, LogPriority.Normal, null, new WfRuntimeException("等待其它需要合并的分支!")); } else { mediatorResult.Add(WfNodeMediatedResult.CreateNodeMediatedResultWithException( WfNodeMediatedFeedback.OtherUnknownReasonToDebug)); LogManager.RecordLog("递归执行节点方法异常", LogEventType.Exception, LogPriority.Normal, null, new WfRuntimeException("等待其它需要合并的分支或发生其它类型的异常!")); } } } else if (comp.Activity.ActivityType == ActivityTypeEnum.SubProcessNode) //子流程节点 { //节点类型为subprocessnode if (fromActivityInstance.ActivityState == (short)ActivityStateEnum.Completed) { //实例化subprocess节点数据 NodeMediator subNodeMediator = new NodeMediatorSubProcess(Session); subNodeMediator.CreateActivityTaskTransitionInstance(comp.Activity, ActivityForwardContext.ProcessInstance, fromActivityInstance, comp.Transition.TransitionGUID, comp.Transition.DirectionType == TransitionDirectionTypeEnum.Loop ? TransitionTypeEnum.Loop : TransitionTypeEnum.Forward, TransitionFlyingTypeEnum.NotFlying, ActivityForwardContext.ActivityResource, Session); } } else if (comp.Activity.ActivityType == ActivityTypeEnum.EndNode) //结束节点 { if (fromActivityInstance.ActivityState == (short)ActivityStateEnum.Completed) { //此节点为完成结束节点,结束流程 NodeMediator endMediator = new NodeMediatorEnd(ActivityForwardContext, Session); endMediator.Linker.ToActivity = comp.Activity; //创建结束节点实例及转移数据 endMediator.CreateActivityTaskTransitionInstance(comp.Activity, ActivityForwardContext.ProcessInstance, fromActivityInstance, comp.Transition.TransitionGUID, TransitionTypeEnum.Forward, TransitionFlyingTypeEnum.NotFlying, ActivityForwardContext.ActivityResource, Session); //执行结束节点中的业务逻辑 endMediator.ExecuteWorkItem(); } else { //结束节点没有创建,需给出提示信息 if (IsWaitingOneOfJoin(fromActivity.GatewayDirectionType) == true) { mediatorResult.Add(WfNodeMediatedResult.CreateNodeMediatedResultWithException( WfNodeMediatedFeedback.NeedOtherGatewayBranchesToJoin)); LogManager.RecordLog("递归执行节点方法异常", LogEventType.Exception, LogPriority.Normal, null, new WfRuntimeException("等待其它需要合并的分支!")); } else { mediatorResult.Add(WfNodeMediatedResult.CreateNodeMediatedResultWithException( WfNodeMediatedFeedback.OtherUnknownReasonToDebug)); LogManager.RecordLog("递归执行节点方法异常", LogEventType.Exception, LogPriority.Normal, null, new WfRuntimeException("等待其它需要合并的分支或发生其它类型的异常!")); } } } else { mediatorResult.Add(WfNodeMediatedResult.CreateNodeMediatedResultWithException( WfNodeMediatedFeedback.UnknownNodeTypeToWatch)); LogManager.RecordLog("递归执行节点方法异常", LogEventType.Exception, LogPriority.Normal, null, new WfRuntimeException(string.Format("XML文件定义了未知的节点类型,执行失败,节点类型信息:{0}", comp.Activity.ActivityType.ToString())) ); } } }