예제 #1
0
        /// <summary>
        /// 执行开始节点
        /// </summary>
        /// <param name="activityExecutionObject"></param>
        /// <param name="processInstance"></param>
        internal override void ExecuteWorkItem()
        {
            try
            {
                //写入流程实例
                ProcessInstanceManager pim = new ProcessInstanceManager();
                pim.Insert(WfExecutionContext.ProcessInstance,
                           this.Session);

                //自动完成开始节点(开始节点不参与Task)
                NodeBase startNode = CreateNewNode(WfExecutionContext.Activity);
                ICompleteAutomaticlly autoStartNode = (ICompleteAutomaticlly)startNode;
                autoStartNode.CompleteAutomaticlly(WfExecutionContext.ProcessInstance,
                                                   null,
                                                   null,
                                                   WfExecutionContext.ActivityResource,
                                                   this.Session);

                //执行开始节点之后的节点集合
                ContinueForwardCurrentNode(startNode,
                                           WfExecutionContext.ActivityResource);
            }
            catch (System.Exception ex)
            {
                throw;
            }
        }
예제 #2
0
        /// <summary>
        /// 递归执行节点
        /// 1)创建普通节点的任务
        /// 2)创建会签节点的任务
        /// </summary>
        /// <param name="fromActivity">起始活动</param>
        /// <param name="fromActivityInstance">起始活动实例</param>
        /// <param name="isJumpforward">是否跳跃</param>
        /// <param name="root">根节点</param>
        /// <param name="conditionKeyValuePair">条件key-value</param>
        protected void ContinueForwardCurrentNodeRecurisivly(ActivityEntity fromActivity,
                                                             ActivityInstanceEntity fromActivityInstance,
                                                             NextActivityComponent root,
                                                             IDictionary <string, string> conditionKeyValuePair,
                                                             Boolean isJumpforward)
        {
            foreach (NextActivityComponent comp in root)
            {
                if (comp.HasChildren)
                {
                    //此节点类型为分支或合并节点类型:首先需要实例化当前节点(自动完成)
                    NodeMediatorGateway gatewayNodeMediator = NodeMediatorGatewayFactory.CreateGatewayNodeMediator(comp.Activity,
                                                                                                                   this.ActivityForwardContext.ProcessModel,
                                                                                                                   Session);

                    ICompleteAutomaticlly autoGateway   = (ICompleteAutomaticlly)gatewayNodeMediator;
                    GatewayExecutedResult gatewayResult = autoGateway.CompleteAutomaticlly(
                        ActivityForwardContext.ProcessInstance,
                        comp.Transition.TransitionGUID,
                        fromActivityInstance,
                        ActivityForwardContext.ActivityResource,
                        Session);

                    if (gatewayResult.Status == GatewayExecutedStatus.Successed)
                    {
                        //遍历后续子节点
                        ContinueForwardCurrentNodeRecurisivly(fromActivity,
                                                              gatewayNodeMediator.GatewayActivityInstance,
                                                              comp,
                                                              conditionKeyValuePair,
                                                              isJumpforward);
                    }
                    else
                    {
                        WfRuntimeException e = new WfRuntimeException("第一个满足条件的节点已经被成功执行,此后的节点被阻止在XOrJoin节点!");
                        LogManager.RecordLog("递归执行节点方法异常", LogEventType.Exception, LogPriority.Normal, null, e);
                    }
                }
                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方向确定是否是自身循环
                                                                              isJumpforward == true ?
                                                                              TransitionFlyingTypeEnum.ForwardFlying : TransitionFlyingTypeEnum.NotFlying,
                                                                              ActivityForwardContext.ActivityResource,
                                                                              Session);
                    }
                    else
                    {
                        //下一步的任务节点没有创建,需给出提示信息
                        if ((fromActivity.GatewayDirectionType | GatewayDirectionEnum.AllJoinType)
                            == GatewayDirectionEnum.AllJoinType)
                        {
                            WfRuntimeException e = new WfRuntimeException("等待其它需要合并的分支!");
                            LogManager.RecordLog("递归执行节点方法异常", LogEventType.Exception, LogPriority.Normal, null, e);
                        }
                    }
                }
                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)        //结束节点
                {
                    //此节点为完成结束节点,结束流程
                    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
                {
                    WfRuntimeException e = new WfRuntimeException(string.Format("XML文件定义了未知的节点类型,执行失败,节点类型信息:{0}",
                                                                                comp.Activity.ActivityType.ToString()));
                    LogManager.RecordLog("递归执行节点方法异常", LogEventType.Exception, LogPriority.Normal, null, e);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// 递归执行节点
        /// </summary>
        /// <param name="root"></param>
        /// <param name="fromNode"></param>
        /// <param name="conditionKeyValuePair"></param>
        protected void ContinueForwardCurrentNodeRecurisivly(NextActivityComponent root,
                                                             NodeBase fromNode,
                                                             IDictionary <string, string> conditionKeyValuePair)
        {
            foreach (NextActivityComponent c in root)
            {
                if (c.HasChildren)
                {
                    //此节点类型为分支或合并节点类型:首先需要实例化当前节点(自动完成)
                    NodeBase gatewayNode = GatewayNodeFactory.CreateNewNode(c.Activity);
                    ICompleteAutomaticlly autoGatewayNode = (ICompleteAutomaticlly)gatewayNode;
                    GatewayExecutedResult gatewayResult   = autoGatewayNode.CompleteAutomaticlly(WfExecutionContext.ProcessInstance,
                                                                                                 c.Transition,
                                                                                                 fromNode.ActivityInstance,
                                                                                                 WfExecutionContext.ActivityResource,
                                                                                                 Session);

                    if (gatewayResult.Status == GatewayExecutedStatus.Successed)
                    {
                        //遍历后续子节点
                        ContinueForwardCurrentNodeRecurisivly(c,
                                                              gatewayNode,
                                                              conditionKeyValuePair);
                    }
                    else
                    {
                        WfExecutedResult workItemExecutedResult = WfExecutedResult.Exception(
                            WfExecutedStatus.FallBehindOfXOrJoin,
                            "第一个满足条件的节点已经被成功执行,此后的节点被阻止在XOrJoin节点!");
                    }
                }
                else if (c.Activity.IsWorkItemNode)
                {
                    //此节点类型为任务节点:根据fromActivityInstance的类型判断是否可以创建任务
                    if (fromNode.ActivityInstance.State == (short)NodeStateEnum.Completed)
                    {
                        //创建新任务节点
                        WorkItem workItem = (WorkItem)WorkItemNodeFactory.CreateNewNode(c.Activity);
                        workItem.CreateActivityTaskAndTransitionInstances(WfExecutionContext.ProcessInstance,
                                                                          fromNode.ActivityInstance,
                                                                          c.Transition,
                                                                          c.Transition.DirectionType == TransitionDirectionTypeEnum.Loop ?
                                                                          TransitionTypeEnum.Loop : TransitionTypeEnum.Forward, //根据Direction方向确定是否是自身循环
                                                                          WfExecutionContext.ActivityResource,
                                                                          Session);

                        //新任务加入队列
                        if (workItem.IsAutomanticWorkItem)
                        {
                            ToDoAutoWorkItemQueue.Enqueue(workItem);
                        }
                    }
                    else
                    {
                        //下一步的任务节点没有创建,需给出提示信息
                        if ((fromNode.Activity.GatewayDirectionType | GatewayDirectionEnum.AllJoinType)
                            == GatewayDirectionEnum.AllJoinType)
                        {
                            WfExecutedResult workItemExecutedResult = WfExecutedResult.Exception(
                                WfExecutedStatus.WaitingForOthersJoin,
                                "等待其它需要合并的分支!");
                        }
                    }
                }
                else if (c.Activity.NodeType == NodeTypeEnum.EndNode)
                {
                    //此节点为完成结束节点,结束流程
                    NodeBase endNode = new EndNode(c.Activity);
                    ICompleteAutomaticlly autoEndNode = (ICompleteAutomaticlly)endNode;
                    autoEndNode.CompleteAutomaticlly(WfExecutionContext.ProcessInstance,
                                                     c.Transition,
                                                     fromNode.ActivityInstance,
                                                     WfExecutionContext.ActivityResource,
                                                     Session);
                }
                else
                {
                    WfExecutedResult workItemExecutedResult = WfExecutedResult.XmlError(
                        string.Format("XML文件定义了未知的节点类型,执行失败,节点类型信息:{0}",
                                      c.Activity.NodeType.ToString()));
                }
            }
        }
예제 #4
0
        /// <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()))
                                         );
                }
            }
        }
예제 #5
0
        /// <summary>
        /// 递归执行节点
        /// 1)创建普通节点的任务
        /// 2)创建会签节点的任务
        /// </summary>
        /// <param name="fromActivity">起始活动</param>
        /// <param name="fromActivityInstance">起始活动实例</param>
        /// <param name="isJumpforward">是否跳跃</param>
        /// <param name="root">根节点</param>
        /// <param name="conditionKeyValuePair">条件key-value</param>
        protected void ContinueForwardCurrentNodeRecurisivly(ActivityEntity fromActivity,
                                                             WfActivityInstance fromActivityInstance,
                                                             NextActivityComponent root,
                                                             Boolean isJumpforward)
        {
            foreach (NextActivityComponent comp in root)
            {
                if (comp.HasChildren)
                {
                    //此节点类型为分支或合并节点类型:首先需要实例化当前节点(自动完成)
                    NodeMediatorGateway gatewayNodeMediator = NodeMediatorGatewayFactory.CreateGatewayNodeMediator(comp.Activity,
                                                                                                                   this.ActivityForwardContext.ProcessModel,
                                                                                                                   AppRunner, _serviceProvider);

                    ICompleteAutomaticlly autoGateway   = (ICompleteAutomaticlly)gatewayNodeMediator;
                    GatewayExecutedResult gatewayResult = autoGateway.CompleteAutomaticlly(
                        ActivityForwardContext.ProcessInstance,
                        comp.Transition.TransitionID,
                        fromActivityInstance);

                    if (gatewayResult.Status == GatewayExecutedStatus.Successed)
                    {
                        //遍历后续子节点
                        ContinueForwardCurrentNodeRecurisivly(fromActivity,
                                                              gatewayNodeMediator.GatewayActivityInstance,
                                                              comp,
                                                              isJumpforward);
                    }
                    else
                    {
                        WfRuntimeException e = new WfRuntimeException("第一个满足条件的节点已经被成功执行,此后的节点被阻止在XOrJoin节点!");
                        _logger.LogError($"第一个满足条件的节点已经被成功执行,此后的节点被阻止在XOrJoin节点!");
                    }
                }
                else if (comp.Activity.ActivityType == ActivityTypeEnum.TaskNode || comp.Activity.ActivityType == ActivityTypeEnum.TimerNode || comp.Activity.ActivityType == ActivityTypeEnum.SignNode)                   //普通任务节点
                {
                    //此节点类型为任务节点:根据fromActivityInstance的类型判断是否可以创建任务
                    if (fromActivityInstance.ActivityState == ActivityStateEnum.Completed.ToString())
                    {
                        //创建新任务节点
                        NodeMediator taskNodeMediator = new NodeMediatorTask(AppRunner, _serviceProvider);
                        taskNodeMediator.CreateActivityTaskTransitionInstance(comp.Activity,
                                                                              ActivityForwardContext.ProcessInstance,
                                                                              fromActivityInstance,
                                                                              comp.Transition.TransitionID,
                                                                              comp.Transition.DirectionType == TransitionDirectionTypeEnum.Loop ?
                                                                              TransitionTypeEnum.Loop : TransitionTypeEnum.Forward, //根据Direction方向确定是否是自身循环
                                                                              isJumpforward == true ?
                                                                              TransitionFlyingTypeEnum.ForwardFlying : TransitionFlyingTypeEnum.NotFlying);
                    }
                    else
                    {
                        //下一步的任务节点没有创建,需给出提示信息
                        if ((fromActivity.GatewayDirectionType | GatewayDirectionEnum.AllJoinType)
                            == GatewayDirectionEnum.AllJoinType)
                        {
                            WfRuntimeException e = new WfRuntimeException("等待其它需要合并的分支!");
                            _logger.LogWarning("等待其它需要合并的分支!");
                        }
                    }
                }
                else if (comp.Activity.ActivityType == ActivityTypeEnum.SubProcessNode)         //子流程节点
                {
                    //节点类型为subprocessnode
                    if (fromActivityInstance.ActivityState == ActivityStateEnum.Completed.ToString())
                    {
                        //实例化subprocess节点数据
                        NodeMediator subNodeMediator = new NodeMediatorSubProcess(AppRunner, _serviceProvider);
                        subNodeMediator.CreateActivityTaskTransitionInstance(comp.Activity,
                                                                             ActivityForwardContext.ProcessInstance,
                                                                             fromActivityInstance,
                                                                             comp.Transition.TransitionID,
                                                                             comp.Transition.DirectionType == TransitionDirectionTypeEnum.Loop ?
                                                                             TransitionTypeEnum.Loop : TransitionTypeEnum.Forward,
                                                                             TransitionFlyingTypeEnum.NotFlying);
                    }
                }
                else if (comp.Activity.ActivityType == ActivityTypeEnum.EndNode)        //结束节点
                {
                    //此节点为完成结束节点,结束流程
                    NodeMediator endMediator = new NodeMediatorEnd(ActivityForwardContext, AppRunner, _serviceProvider);
                    endMediator.Linker.ToActivity = comp.Activity;

                    //创建结束节点实例及转移数据
                    endMediator.CreateActivityTaskTransitionInstance(comp.Activity, ActivityForwardContext.ProcessInstance,
                                                                     fromActivityInstance, comp.Transition.TransitionID, TransitionTypeEnum.Forward,
                                                                     TransitionFlyingTypeEnum.NotFlying);

                    //执行结束节点中的业务逻辑
                    endMediator.ExecuteWorkItem();
                }
                else
                {
                    WfRuntimeException e = new WfRuntimeException(string.Format("XML文件定义了未知的节点类型,执行失败,节点类型信息:{0}",
                                                                                comp.Activity.ActivityType.ToString()));
                    _logger.LogError($"XML文件定义了未知的节点类型,执行失败,节点类型信息:{comp.Activity.ActivityType.ToString()}");
                }
            }
        }