コード例 #1
0
        /// <summary>
        /// 获取预选步骤人员列表
        /// </summary>
        /// <param name="runner">当前运行用户</param>
        /// <returns>步骤预选人员列表</returns>
        private IDictionary <string, PerformerList> GetNextActivityPerformersPriliminary(WfAppRunner runner)
        {
            IDictionary <string, PerformerList> nextSteps = null;

            var            tm       = new TaskManager();
            TaskViewEntity taskView = tm.GetTaskOfMine(runner);

            //读取活动实例中记录的步骤预选数据
            var aim = new ActivityInstanceManager();

            if (taskView.MIHostActivityInstanceID != null)
            {
                var mainActivityInstanceID = taskView.MIHostActivityInstanceID.Value;
                var mainActivityInstance   = aim.GetById(mainActivityInstanceID);
                if (mainActivityInstance != null)
                {
                    nextSteps = NextStepUtility.DeserializeNextStepPerformers(mainActivityInstance.NextStepPerformers);
                }
            }

            IProcessModel processModel = ProcessModelFactory.Create(runner.ProcessGUID, runner.Version);
            var           nextActivity = processModel.GetNextActivity(taskView.ActivityGUID);

            if (nextActivity != null)
            {
                if (nextActivity.ActivityType == ActivityTypeEnum.GatewayNode)
                {
                    //获取网关节点信息
                    var gatewayActivityInstance = aim.GetActivityInstanceLatest(taskView.ProcessInstanceID, nextActivity.ActivityGUID);
                    if (gatewayActivityInstance != null &&
                        !string.IsNullOrEmpty(gatewayActivityInstance.NextStepPerformers))
                    {
                        nextSteps = NextStepUtility.DeserializeNextStepPerformers(gatewayActivityInstance.NextStepPerformers);
                    }
                }
                else if (XPDLHelper.IsInterTimerEventComponentNode(nextActivity) == true)
                {
                    //中间Timer事件节点
                    var timerActivityInstance = aim.GetActivityInstanceLatest(taskView.ProcessInstanceID, nextActivity.ActivityGUID);
                    if (timerActivityInstance != null &&
                        !string.IsNullOrEmpty(timerActivityInstance.NextStepPerformers))
                    {
                        nextSteps = NextStepUtility.DeserializeNextStepPerformers(timerActivityInstance.NextStepPerformers);
                    }
                }
            }
            return(nextSteps);
        }
コード例 #2
0
        /// <summary>
        /// 获取预选步骤人员列表
        /// </summary>
        /// <param name="nextActivityTree">下一步活动节点树</param>
        /// <param name="runner">当前运行用户</param>
        /// <returns>步骤预选人员列表</returns>
        private IDictionary <string, PerformerList> GetNextActivityPerformers(IList <NodeView> nextActivityTree,
                                                                              WfAppRunner runner)
        {
            IDictionary <string, PerformerList> nextSteps = null;

            var            tm       = new TaskManager();
            TaskViewEntity taskView = tm.GetTaskOfMine(runner);

            //读取活动实例中记录的步骤预选数据
            var aim = new ActivityInstanceManager();

            if (taskView.MIHostActivityInstanceID != null)
            {
                var mainActivityInstanceID = taskView.MIHostActivityInstanceID.Value;
                var mainActivityInstance   = aim.GetById(mainActivityInstanceID);
                if (mainActivityInstance != null)
                {
                    nextSteps = NextStepUtility.DeserializeNextStepPerformers(mainActivityInstance.NextStepPerformers);
                }
            }

            //获取网关节点信息
            IProcessModel processModel = ProcessModelFactory.Create(runner.ProcessGUID, runner.Version);
            var           nextActivity = processModel.GetNextActivity(taskView.ActivityGUID);

            if (nextActivity.ActivityType == ActivityTypeEnum.GatewayNode)
            {
                var gatewayActivityInstance = aim.GetActivityInstanceLatest(taskView.ProcessInstanceID, nextActivity.ActivityGUID);
                if (gatewayActivityInstance != null &&
                    !string.IsNullOrEmpty(gatewayActivityInstance.NextStepPerformers))
                {
                    nextSteps = NextStepUtility.DeserializeNextStepPerformers(gatewayActivityInstance.NextStepPerformers);
                }
            }
            return(nextSteps);
        }
コード例 #3
0
        private static WfRuntimeManager CreateRuntimeInstanceSendbackByCase(ActivityInstanceEntity runningNode,
                                                                            IProcessModel processModel,
                                                                            ProcessInstanceEntity processInstance,
                                                                            IList <ActivityEntity> sendbackPreviousActivityList,
                                                                            Boolean hasGatewayPassed,
                                                                            SendbackOperationTypeEnum sendbackOperation,
                                                                            WfAppRunner runner,
                                                                            ref WfExecutedResult result)
        {
            WfRuntimeManager rmins = new WfRuntimeManagerSendBack();

            rmins.WfExecutedResult = result = new WfExecutedResult();

            var aim = new ActivityInstanceManager();


            //以下处理,需要知道上一步是独立节点的信息
            var tim = new TransitionInstanceManager();
            TransitionInstanceEntity lastTaskTransitionInstance = tim.GetLastTaskTransition(runner.AppName,
                                                                                            runner.AppInstanceID, runner.ProcessGUID);

            if (lastTaskTransitionInstance.TransitionType == (short)TransitionTypeEnum.Loop)
            {
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Sendback_IsLoopNode;
                result.Message       = "当前流转是自循环,无需退回!";

                return(rmins);
            }

            //设置退回节点的相关信息
            var previousActivityGUID     = sendbackPreviousActivityList[0].ActivityGUID;
            var previousActivityInstance = aim.GetActivityInstanceLatest(runner.AppInstanceID, runner.ProcessGUID, previousActivityGUID);

            //普通模式的退回
            if (sendbackOperation == SendbackOperationTypeEnum.Normal)
            {
                //简单串行模式下的退回
                rmins = new WfRuntimeManagerSendBack();
                rmins.WfExecutedResult = result = new WfExecutedResult();

                rmins.ProcessModel = processModel;
                rmins.BackwardContext.ProcessInstance                = processInstance;
                rmins.BackwardContext.BackwardToTaskActivity         = processModel.GetActivity(previousActivityInstance.ActivityGUID);
                rmins.BackwardContext.BackwardToTaskActivityInstance = previousActivityInstance;
                rmins.BackwardContext.BackwardToTargetTransitionGUID =
                    hasGatewayPassed == false ? lastTaskTransitionInstance.TransitionGUID : WfDefine.WF_XPDL_GATEWAY_BYPASS_GUID;            //如果中间有Gateway节点,则没有直接相连的TransitonGUID

                rmins.BackwardContext.BackwardFromActivity         = processModel.GetActivity(runningNode.ActivityGUID);
                rmins.BackwardContext.BackwardFromActivityInstance = runningNode;
                rmins.BackwardContext.BackwardTaskReceiver         = WfBackwardTaskReceiver.Instance(previousActivityInstance.ActivityName,
                                                                                                     previousActivityInstance.EndedByUserID, previousActivityInstance.EndedByUserName);

                //封装AppUser对象
                rmins.AppRunner.AppName                = runner.AppName;
                rmins.AppRunner.AppInstanceID          = runner.AppInstanceID;
                rmins.AppRunner.ProcessGUID            = runner.ProcessGUID;
                rmins.AppRunner.UserID                 = runner.UserID;
                rmins.AppRunner.UserName               = runner.UserName;
                rmins.AppRunner.NextActivityPerformers = ActivityResource.CreateNextActivityPerformers(previousActivityInstance.ActivityGUID,
                                                                                                       previousActivityInstance.EndedByUserID,
                                                                                                       previousActivityInstance.EndedByUserName);
                rmins.ActivityResource = new ActivityResource(runner, rmins.AppRunner.NextActivityPerformers);

                return(rmins);
            }

            //如果有其它模式,没有处理到,则直接抛出异常
            throw new WorkflowException("未知的退回场景,请报告给技术支持人员!");
        }
コード例 #4
0
        /// <summary>
        /// 创建跳转实例信息
        /// </summary>
        /// <param name="runner">执行者</param>
        /// <param name="result">结果对象</param>
        /// <returns>运行时实例对象</returns>
        public static WfRuntimeManager CreateRuntimeInstanceJump(WfAppRunner runner,
                                                                 ref WfExecutedResult result)
        {
            var rmins = new WfRuntimeManagerJump();

            rmins.WfExecutedResult = result = new WfExecutedResult();

            if (string.IsNullOrEmpty(runner.AppName) ||
                String.IsNullOrEmpty(runner.AppInstanceID) ||
                runner.ProcessGUID == null ||
                runner.NextActivityPerformers == null)
            {
                //缺失方法参数
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Jump_ErrorArguments;
                result.Message       = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceJump.missing.error");
                return(rmins);
            }

            //流程跳转时,只能跳转到一个节点
            if (runner.NextActivityPerformers.Count() > 1)
            {
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Jump_OverOneStep;
                result.Message       = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceJump.jump.error",
                                                                       runner.NextActivityPerformers.Count().ToString());
                return(rmins);
            }

            //获取当前运行节点信息
            var            aim         = new ActivityInstanceManager();
            TaskViewEntity taskView    = null;
            var            runningNode = aim.GetRunningNode(runner, out taskView);

            //传递runner变量
            rmins.TaskView                = taskView;
            rmins.AppRunner               = runner;
            rmins.AppRunner.AppName       = runner.AppName;
            rmins.AppRunner.AppInstanceID = runner.AppInstanceID;
            rmins.AppRunner.ProcessGUID   = runner.ProcessGUID;
            rmins.AppRunner.UserID        = runner.UserID;
            rmins.AppRunner.UserName      = runner.UserName;

            //用于流程注册时间调用时候的流程实例ID提供
            rmins.ProcessInstanceID = runningNode.ProcessInstanceID;

            var processModel = ProcessModelFactory.Create(taskView.ProcessGUID, taskView.Version);

            rmins.ProcessModel = processModel;

            #region 考虑回跳方式
            //获取跳转节点信息
            var jumpBackActivityGUID     = runner.NextActivityPerformers.First().Key;
            var jumpBackActivityInstance = aim.GetActivityInstanceLatest(runningNode.ProcessInstanceID, jumpBackActivityGUID);

            if (jumpBackActivityInstance != null)
            {
                //跳转到曾经执行过的节点上,可以作为跳回方式处理
                rmins.IsBackward = true;
                rmins.BackwardContext.ProcessInstance        = (new ProcessInstanceManager()).GetById(runningNode.ProcessInstanceID);
                rmins.BackwardContext.BackwardToTaskActivity = processModel.GetActivity(jumpBackActivityGUID);

                //获取当前运行节点的上一步节点
                bool hasGatewayNode             = false;
                var  tim                        = new TransitionInstanceManager();
                var  lastTaskTransitionInstance = tim.GetLastTaskTransition(runner.AppName,
                                                                            runner.AppInstanceID, runner.ProcessGUID);

                var npc = new PreviousStepChecker();
                var previousActivityInstance = npc.GetPreviousActivityInstanceList(runningNode, true,
                                                                                   out hasGatewayNode).ToList()[0];

                //仅仅是回跳到上一步节点,即按SendBack方式处理
                if (previousActivityInstance.ActivityGUID == jumpBackActivityGUID)
                {
                    rmins.BackwardContext.BackwardToTaskActivityInstance = previousActivityInstance;
                    rmins.BackwardContext.BackwardToTargetTransitionGUID =
                        hasGatewayNode == false ? lastTaskTransitionInstance.TransitionGUID : WfDefine.WF_XPDL_GATEWAY_BYPASS_GUID;        //如果中间有Gateway节点,则没有直接相连的TransitonGUID

                    rmins.BackwardContext.BackwardFromActivity         = processModel.GetActivity(runningNode.ActivityGUID);
                    rmins.BackwardContext.BackwardFromActivityInstance = runningNode;
                    rmins.BackwardContext.BackwardTaskReceiver         = WfBackwardTaskReceiver.Instance(
                        previousActivityInstance.ActivityName,
                        previousActivityInstance.EndedByUserID,
                        previousActivityInstance.EndedByUserName);

                    rmins.AppRunner.NextActivityPerformers = ActivityResource.CreateNextActivityPerformers(
                        previousActivityInstance.ActivityGUID,
                        previousActivityInstance.EndedByUserID,
                        previousActivityInstance.EndedByUserName);
                }
                else
                {
                    //回跳到早前节点
                    if (jumpBackActivityInstance.ActivityState != (short)ActivityStateEnum.Completed)
                    {
                        //回跳节点不在完成状态
                        result.Status        = WfExecutedStatus.Exception;
                        result.ExceptionType = WfExceptionType.Jump_NotActivityBackCompleted;
                        result.Message       = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceJump.back.error");

                        return(rmins);
                    }

                    rmins.BackwardContext.BackwardToTaskActivityInstance = jumpBackActivityInstance;

                    //判断两个节点是否有Transition的定义存在
                    var transition = processModel.GetForwardTransition(runningNode.ActivityGUID, jumpBackActivityGUID);
                    rmins.BackwardContext.BackwardToTargetTransitionGUID = transition != null ? transition.TransitionGUID : WfDefine.WF_XPDL_GATEWAY_BYPASS_GUID;

                    rmins.BackwardContext.BackwardFromActivity         = processModel.GetActivity(runningNode.ActivityGUID);
                    rmins.BackwardContext.BackwardFromActivityInstance = runningNode;
                    rmins.BackwardContext.BackwardTaskReceiver         = WfBackwardTaskReceiver.Instance(
                        jumpBackActivityInstance.ActivityName,
                        jumpBackActivityInstance.EndedByUserID,
                        jumpBackActivityInstance.EndedByUserName);

                    rmins.AppRunner.NextActivityPerformers = ActivityResource.CreateNextActivityPerformers(
                        jumpBackActivityInstance.ActivityGUID,
                        jumpBackActivityInstance.EndedByUserID,
                        jumpBackActivityInstance.EndedByUserName);
                }
                //获取资源数据
                var activityResourceBack = new ActivityResource(rmins.AppRunner,
                                                                rmins.AppRunner.NextActivityPerformers,
                                                                runner.Conditions);
                rmins.ActivityResource = activityResourceBack;
            }
            else
            {
                //跳转到从未执行过的节点上
                var activityResource = new ActivityResource(runner, runner.NextActivityPerformers, runner.Conditions);
                rmins.ActivityResource        = activityResource;
                rmins.RunningActivityInstance = runningNode;
            }
            #endregion

            return(rmins);
        }