Ejemplo n.º 1
0
        /// <summary>
        /// 退回操作
        /// </summary>
        /// <param name="runner">执行者</param>
        /// <param name="result">结果对象</param>
        /// <returns>运行时实例对象</returns>
        internal static WfRuntimeManager CreateRuntimeInstanceSendBack(WfAppRunner runner,
                                                                       ref WfExecutedResult result)
        {
            WfRuntimeManager rmins = new WfRuntimeManagerSendBack();

            rmins.WfExecutedResult = result = new WfExecutedResult();

            var aim = new ActivityInstanceManager();
            var runningActivityInstanceList = aim.GetRunningActivityInstanceList(runner.AppInstanceID, runner.ProcessGUID).ToList();

            SendbackOperationTypeEnum sendbackOperation = SendbackOperationTypeEnum.Default;

            //当前没有运行状态的节点存在,流程不存在,或者已经结束或取消
            if (runningActivityInstanceList == null || runningActivityInstanceList.Count() == 0)
            {
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Sendback_NotInRunning;
                result.Message       = "当前没有运行状态的节点存在,流程不存在,或者已经结束或取消";

                return(rmins);
            }

            if (runningActivityInstanceList.Count() == 1)       //如果只有1个运行节点
            {
                var runningNode = runningActivityInstanceList[0];

                var activityType = EnumHelper.ParseEnum <ActivityTypeEnum>(runningNode.ActivityType.ToString());
                if (XPDLHelper.IsSimpleComponentNode(activityType) == false)
                {
                    result.Status        = WfExecutedStatus.Exception;
                    result.ExceptionType = WfExceptionType.Sendback_NotTaskNode;
                    result.Message       = "当前节点不是任务类型的节点,无法退回上一步节点!";
                    return(rmins);
                }

                if (aim.IsMineTask(runningNode, runner.UserID) == false)
                {
                    result.Status        = WfExecutedStatus.Exception;
                    result.ExceptionType = WfExceptionType.Sendback_NotMineTask;
                    result.Message       = "不是登录用户的任务,无法退回!";
                    return(rmins);
                }

                //判断当前节点是否是多实例节点
                if (runningNode.MIHostActivityInstanceID != null)
                {
                    if (runningNode.CompleteOrder == 1)
                    {
                        //只有串行模式下有CompleteOrder的值为 1
                        //串行模式多实例的第一个执行节点,此时可退回到上一步
                        sendbackOperation = SendbackOperationTypeEnum.MISFirstOneIsRunning;
                    }
                    else if (runningNode.CompleteOrder > 1)
                    {
                        //已经是中间节点,只能退回到上一步多实例子节点
                        sendbackOperation = SendbackOperationTypeEnum.MISOneIsRunning;
                    }
                    else if (runningNode.CompleteOrder == -1)
                    {
                        sendbackOperation = SendbackOperationTypeEnum.MIPOneIsRunning;
                    }
                }
                else
                {
                    sendbackOperation = SendbackOperationTypeEnum.Normal;
                }
            }
            else if (runningActivityInstanceList.Count() > 1)
            {
                var firstActivityInstance = runningActivityInstanceList[0];
                if (firstActivityInstance.MIHostActivityInstanceID != null)
                {
                    //判断多实例主节点下的子节点是否都处于待办状态,如果是,则可以退回到上一步
                    bool isAllInReadyState = true;
                    var  allChildNodeList  = aim.GetActivityMultipleInstance(firstActivityInstance.MIHostActivityInstanceID.Value,
                                                                             firstActivityInstance.ProcessInstanceID);

                    int runningCount = 0;
                    foreach (var ai in allChildNodeList)
                    {
                        if (ai.ActivityState != (short)ActivityStateEnum.Ready &&
                            ai.ActivityState != (short)ActivityStateEnum.Suspended)
                        {
                            if (ai.ActivityState == (short)ActivityStateEnum.Running)
                            {
                                runningCount++;
                            }
                            else
                            {
                                isAllInReadyState = false;
                                break;
                            }
                        }
                    }
                    if (runningCount > 1)
                    {
                        isAllInReadyState = false;
                    }

                    if (isAllInReadyState == false)
                    {
                        //部分子节点有完成的
                        sendbackOperation = SendbackOperationTypeEnum.MIPSeveralIsRunning;
                    }
                    else if (runningCount == 1)
                    {
                        if (firstActivityInstance.CompleteOrder == -1)
                        {
                            sendbackOperation = SendbackOperationTypeEnum.MIPOneIsRunning;
                        }
                        else
                        {
                            //第一个子节点处于待办状态
                            sendbackOperation = SendbackOperationTypeEnum.MISFirstOneIsRunning;
                        }
                    }
                    else if (isAllInReadyState)
                    {
                        //子节点全部处于待办状态
                        sendbackOperation = SendbackOperationTypeEnum.MIPAllIsInReadyState;
                    }
                }
                else
                {
                    //有其它非多实例的并行节点,暂时不处理,后期实现该功能
                    result.Status        = WfExecutedStatus.Exception;
                    result.ExceptionType = WfExceptionType.Sendback_NullOrHasTooMany;
                    result.Message       = "有多个可以退回的节点,而且不是多实例节点,此功能暂时不支持!";

                    return(rmins);
                }
            }

            //根据不同分支场景,创建不同撤销运行时管理器
            return(CreateRuntimeInstanceSendbackByCase(runningActivityInstanceList, sendbackOperation, runner, ref result));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 撤销操作
        /// 包括:
        /// 1) 正常流转
        /// 2) 多实例节点流转
        /// </summary>
        /// <param name="runner">执行者</param>
        /// <param name="result">结果对象</param>
        /// <returns>运行时实例对象</returns>
        internal static WfRuntimeManager CreateRuntimeInstanceWithdraw(WfAppRunner runner,
                                                                       ref WfExecutedResult result)
        {
            WfRuntimeManager rmins = new WfRuntimeManagerWithdraw();

            rmins.WfExecutedResult = result = new WfExecutedResult();

            var aim = new ActivityInstanceManager();
            var runningActivityInstanceList = aim.GetRunningActivityInstanceList(runner.AppInstanceID, runner.ProcessGUID).ToList();

            WithdrawOperationTypeEnum withdrawOperation = WithdrawOperationTypeEnum.Default;

            //当前没有运行状态的节点存在,流程不存在,或者已经结束或取消
            if (runningActivityInstanceList == null || runningActivityInstanceList.Count() == 0)
            {
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Withdraw_NotInReady;
                result.Message       = "当前没有运行状态的节点存在,流程不存在,或者已经结束或取消";

                return(rmins);
            }

            if (runningActivityInstanceList.Count() == 1)      //如果只有1个运行节点
            {
                //先判断节点的状态是否是有效状态
                var runningNode = runningActivityInstanceList[0];
                if (runningNode.ActivityState != (short)ActivityStateEnum.Ready &&
                    runningNode.ActivityState != (short)ActivityStateEnum.Suspended)           //只有准备或挂起状态的节点可以撤销
                {
                    result.Status        = WfExecutedStatus.Exception;
                    result.ExceptionType = WfExceptionType.Withdraw_NotInReady;
                    result.Message       = string.Format("无法撤销到上一步,因为要撤销的节点为空,或不在【待办/挂起】状态,当前状态: {0}",
                                                         runningNode.ActivityState);//,节点状态:{0}    runningNode.ActivityState     为空报错20150514

                    return(rmins);
                }

                //判断是否是多实例节点的子节点
                if (runningNode.MIHostActivityInstanceID != null)
                {
                    if (runningNode.CompleteOrder == 1)
                    {
                        //只有串行模式下有CompleteOrder的值为 1
                        //串行模式多实例的第一个执行节点,此时上一步骤可以撤销
                        withdrawOperation = WithdrawOperationTypeEnum.MISFirstOneIsRunning;
                    }
                    else if (runningNode.CompleteOrder > 1)
                    {
                        //串行模式多实例内部撤销,其中只有1个节点处于运行状态
                        withdrawOperation = WithdrawOperationTypeEnum.MISOneIsRunning;
                    }
                    else if (runningNode.CompleteOrder == -1)
                    {
                        //并行模式下CompleteOrder的值为 -1,此时只剩余最后一个
                        //要撤销的话,是对并行会签节点的内部撤销,即认为是重新办理,找到当前运行人的节点,置状态为待办状态就可以
                        withdrawOperation = WithdrawOperationTypeEnum.MIPSeveralIsRunning;
                    }
                }
                else
                {
                    //当前运行节点是普通节点模式
                    withdrawOperation = WithdrawOperationTypeEnum.Normal;
                }
            }
            else if (runningActivityInstanceList.Count() > 1)       //有多个并行运行节点存在
            {
                //判断多实例主节点下的子节点是否都处于待办状态,如果是,则上一步可以撤销回去,否则不可以撤销
                var firstActivityInstance = runningActivityInstanceList[0];
                if (firstActivityInstance.MIHostActivityInstanceID != null)
                {
                    bool isAllInReadyState = true;
                    var  allChildNodeList  = aim.GetActivityMultipleInstance(firstActivityInstance.MIHostActivityInstanceID.Value,
                                                                             firstActivityInstance.ProcessInstanceID);

                    foreach (var ai in allChildNodeList)
                    {
                        if (ai.ActivityState != (short)ActivityStateEnum.Ready &&
                            ai.ActivityState != (short)ActivityStateEnum.Suspended)
                        {
                            isAllInReadyState = false;
                            break;
                        }
                    }

                    if (isAllInReadyState == true)
                    {
                        //子节点全部处于待办状态
                        withdrawOperation = WithdrawOperationTypeEnum.MIPAllIsInReadyState;
                    }
                    else
                    {
                        //部分子节点有完成的
                        withdrawOperation = WithdrawOperationTypeEnum.MIPSeveralIsRunning;
                    }
                }
                else
                {
                    //有其它非多实例的并行节点,暂时不处理,后期实现该功能
                    result.Status        = WfExecutedStatus.Exception;
                    result.ExceptionType = WfExceptionType.Withdraw_HasTooMany;
                    result.Message       = "有多个可以撤销回去的节点,而且不是多实例节点,此功能暂时不支持!";

                    return(rmins);
                }
            }

            //根据不同分支场景,创建不同撤销运行时管理器
            return(CreateRuntimeInstanceWithdrawByCase(runningActivityInstanceList, withdrawOperation, runner, ref result));
        }