Exemplo n.º 1
0
        /// <summary>
        /// 消息发布方法
        /// </summary>
        /// <param name="processInstance">流程实例</param>
        /// <param name="throwActivity">消息活动</param>
        /// <param name="throwActivityInstance">消息活动实例</param>
        public void PublishMessage(ProcessInstanceEntity processInstance,
                                   ActivityEntity throwActivity,
                                   ActivityInstanceEntity throwActivityInstance)
        {
            var           topic         = throwActivity.ActivityTypeDetail.Expression;
            ProcessEntity catchProcess  = null;
            var           catchActivity = XPDLHelper.GetMessageCatchActivity(processInstance, throwActivity, throwActivityInstance, out catchProcess);

            var appRunner = new WfAppRunner();

            appRunner.MessageTopic    = topic;
            appRunner.AppName         = throwActivityInstance.AppName;
            appRunner.AppInstanceID   = throwActivityInstance.AppInstanceID;
            appRunner.AppInstanceCode = throwActivityInstance.AppInstanceCode;
            appRunner.UserID          = throwActivityInstance.CreatedByUserID;
            appRunner.UserName        = throwActivityInstance.CreatedByUserName;

            var msgRunnerView = new MessageRunnerView();

            msgRunnerView.ProcessEntity  = catchProcess;
            msgRunnerView.ActivityEntity = catchActivity;
            msgRunnerView.WfAppRunner    = appRunner;

            var jsonRunner = JsonConvert.SerializeObject(msgRunnerView);

            var messageService = MessageQueueServiceFactory.Create();

            messageService.Publish(topic, jsonRunner);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 创建下一步活动的节点
        /// </summary>
        /// <param name="activity"></param>
        /// <returns></returns>
        internal static NextActivityComponent CreateNextActivityComponent(TransitionEntity transition,
                                                                          ActivityEntity activity)
        {
            NextActivityComponent component = null;

            if (XPDLHelper.IsSimpleComponentNode(activity.ActivityType) == true)           //可流转简单类型节点
            {
                string name = "单一节点";
                component = new NextActivityItem(name, transition, activity);
            }
            else if (activity.ActivityType == ActivityTypeEnum.SubProcessNode)
            {
                string name = "子流程节点";
                component = new NextActivityItem(name, transition, activity);
            }
            else
            {
                string name = string.Empty;
                if (activity.GatewayDirectionType == Slickflow.Engine.Common.GatewayDirectionEnum.AndSplit)
                {
                    name = "必全选节点";
                }
                else if (activity.GatewayDirectionType == GatewayDirectionEnum.AndSplitMI)
                {
                    name = "并行多实例节点";
                }
                else
                {
                    name = "或多选节点";
                }

                component = new NextActivityGateway(name, transition, activity);
            }
            return(component);
        }
        /// <summary>
        /// 根据Transition,获取下一步节点列表
        /// </summary>
        /// <param name="forwardTransition">转移实体</param>
        /// <param name="conditionKeyValuePair">条件kv对</param>
        /// <param name="resultType">结果类型</param>
        protected NextActivityComponent GetNextActivityListFromGatewayCore(TransitionEntity forwardTransition,
                                                                           IDictionary <string, string> conditionKeyValuePair,
                                                                           out NextActivityMatchedType resultType)
        {
            NextActivityComponent child = null;

            if (XPDLHelper.IsSimpleComponentNode(forwardTransition.ToActivity.ActivityType) == true)       //可流转简单类型节点
            {
                child      = NextActivityComponentFactory.CreateNextActivityComponent(forwardTransition, forwardTransition.ToActivity);
                resultType = NextActivityMatchedType.Successed;
            }
            else if (forwardTransition.ToActivity.ActivityType == ActivityTypeEnum.GatewayNode)
            {
                child = GetNextActivityListFromGateway(forwardTransition,
                                                       forwardTransition.ToActivity,
                                                       conditionKeyValuePair,
                                                       out resultType);
            }
            else
            {
                resultType = NextActivityMatchedType.Failed;

                throw new XmlDefinitionException(string.Format("未知的节点类型:{0}", forwardTransition.ToActivity.ActivityType.ToString()));
            }
            return(child);
        }
Exemplo n.º 4
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();

            SendbackOpertaionTypeEnum sendbackOperation = SendbackOpertaionTypeEnum.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);
                }

                sendbackOperation = SendbackOpertaionTypeEnum.Normal;
            }
            else if (runningActivityInstanceList.Count() > 1)
            {
                //有其它非多实例的并行节点,暂时不处理,后期实现该功能
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Sendback_NullOrHasTooMany;
                result.Message       = "有多个可以退回的节点,而且不是多实例节点,此功能暂时不支持!";

                return(rmins);
            }

            //根据不同分支场景,创建不同撤销运行时管理器
            return(CreateRuntimeInstanceSendbackByCase(runningActivityInstanceList, sendbackOperation, runner, ref result));
        }
        /// <summary>
        /// 创建下一步活动的节点
        /// </summary>
        /// <param name="transition">转移</param>
        /// <param name="activity">活动</param>
        /// <returns>下一步节点封装</returns>
        internal static NextActivityComponent CreateNextActivityComponent(TransitionEntity transition,
                                                                          ActivityEntity activity)
        {
            string name = string.Empty;
            NextActivityComponent component = null;

            if (XPDLHelper.IsSimpleComponentNode(activity.ActivityType) == true)           //可流转简单类型节点
            {
                name      = "单一节点";
                component = new NextActivityItem(name, transition, activity);
            }
            else if (XPDLHelper.IsIntermediateEventComponentNode(activity.ActivityType) == true)
            {
                name      = "跨事件节点";
                component = new NextActivityIntermediate(name, transition, activity);
            }
            else if (XPDLHelper.IsGatewayComponentNode(activity.ActivityType) == true)
            {
                if (activity.GatewayDirectionType == GatewayDirectionEnum.AndSplit)
                {
                    name      = "必全选节点";
                    component = new NextActivityGateway(name, transition, activity);
                }
                else if (activity.GatewayDirectionType == GatewayDirectionEnum.AndSplitMI)
                {
                    name      = "并行多实例节点";
                    component = new NextActivityGateway(name, transition, activity);
                }
                else if (activity.GatewayDirectionType == GatewayDirectionEnum.OrSplit ||
                         activity.GatewayDirectionType == GatewayDirectionEnum.OrSplitMI ||
                         activity.GatewayDirectionType == GatewayDirectionEnum.XOrSplit)
                {
                    name      = "或多选节点";
                    component = new NextActivityGateway(name, transition, activity);
                }
                else
                {
                    throw new WfXpdlException(string.Format("无法创建下一步节点列表,不明确的分支类型:{0}",
                                                            activity.GatewayDirectionType.ToString()));
                }
            }
            else if (activity.ActivityType == ActivityTypeEnum.SubProcessNode)
            {
                name      = "子流程节点";
                component = new NextActivityItem(name, transition, activity);
            }
            else
            {
                throw new WfXpdlException(string.Format("无法创建下一步节点列表,不明确的节点类型:{0}",
                                                        activity.ActivityType.ToString()));
            }

            return(component);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 根据Transition,获取下一步节点列表
        /// </summary>
        /// <param name="forwardTransition">转移实体</param>
        /// <param name="conditionKeyValuePair">条件kv对</param>
        /// <param name="session">会话</param>
        /// <param name="resultType">结果类型</param>
        protected NextActivityComponent GetNextActivityListFromGatewayCore(TransitionEntity forwardTransition,
                                                                           IDictionary <string, string> conditionKeyValuePair,
                                                                           IDbSession session,
                                                                           out NextActivityMatchedType resultType)
        {
            NextActivityComponent child = null;

            if (XPDLHelper.IsSimpleComponentNode(forwardTransition.ToActivity.ActivityType) == true)       //可流转简单类型节点
            {
                child      = NextActivityComponentFactory.CreateNextActivityComponent(forwardTransition, forwardTransition.ToActivity);
                resultType = NextActivityMatchedType.Successed;
            }
            else if (forwardTransition.ToActivity.ActivityType == ActivityTypeEnum.GatewayNode)
            {
                child = GetNextActivityListFromGateway(forwardTransition,
                                                       forwardTransition.ToActivity,
                                                       conditionKeyValuePair,
                                                       session,
                                                       out resultType);
            }
            else if (forwardTransition.ToActivity.ActivityType == ActivityTypeEnum.IntermediateNode)
            {
                if (forwardTransition.ToActivity.ActivityTypeDetail.TriggerType == TriggerTypeEnum.Timer)
                {
                    child      = NextActivityComponentFactory.CreateNextActivityComponent(forwardTransition, forwardTransition.ToActivity);
                    resultType = NextActivityMatchedType.Successed;
                }
                else
                {
                    NextActivityScheduleBase activitySchedule = NextActivityScheduleFactory.CreateActivityScheduleIntermediate(this.ProcessModel);
                    child = activitySchedule.GetNextActivityListFromGateway(forwardTransition,
                                                                            forwardTransition.ToActivity,
                                                                            conditionKeyValuePair,
                                                                            session,
                                                                            out resultType);
                }
            }
            else if (forwardTransition.ToActivity.ActivityType == ActivityTypeEnum.ServiceNode)
            {
                NextActivityScheduleBase activitySchedule = NextActivityScheduleFactory.CreateActivityScheduleIntermediate(this.ProcessModel);
                child = activitySchedule.GetNextActivityListFromGateway(forwardTransition,
                                                                        forwardTransition.ToActivity,
                                                                        conditionKeyValuePair,
                                                                        session,
                                                                        out resultType);
            }
            else
            {
                resultType = NextActivityMatchedType.Failed;

                throw new XmlDefinitionException(LocalizeHelper.GetEngineMessage("nextactivityschedulebase.unknownnodetype", forwardTransition.ToActivity.ActivityType.ToString()));
            }
            return(child);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 创建跳转节点(强制拉取跳转方式,后续节点状态可以强制拉取前置节点到当前节点[后续节点])
        /// </summary>
        /// <param name="fromActivity">要拉取的节点</param>
        /// <param name="toActivity">拉取到节点</param>
        /// <returns></returns>
        internal static NextActivityComponent CreateNextActivityComponent(ActivityEntity fromActivity,
                                                                          ActivityEntity toActivity)
        {
            NextActivityComponent component = null;

            if (XPDLHelper.IsSimpleComponentNode(fromActivity.ActivityType) == true)       //可流转简单类型节点
            {
                string name       = "单一节点";
                var    transition = TransitionBuilder.CreateJumpforwardEmptyTransition(fromActivity, toActivity);

                component = new NextActivityItem(name, transition, fromActivity);     //强制拉取跳转类型的transition 为空类型
            }
            else
            {
                throw new ApplicationException(string.Format("不能跳转到其它非任务类型的节点!当前节点:{0}",
                                                             fromActivity.ActivityType));
            }
            return(component);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 创建跳转节点(强制拉取跳转方式,后续节点状态可以强制拉取前置节点到当前节点[后续节点])
        /// </summary>
        /// <param name="fromActivity">要拉取的节点</param>
        /// <param name="toActivity">拉取到节点</param>
        /// <returns>下一步节点封装</returns>
        internal static NextActivityComponent CreateNextActivityComponent(ActivityEntity fromActivity,
                                                                          ActivityEntity toActivity)
        {
            NextActivityComponent component = null;

            if (XPDLHelper.IsSimpleComponentNode(fromActivity.ActivityType) == true)       //可流转简单类型节点
            {
                //单一节点
                string name       = LocalizeHelper.GetEngineMessage("nextactivitycomponentfactory.singlenode");;
                var    transition = CreateJumpforwardEmptyTransition(fromActivity, toActivity);

                component = new NextActivityItem(name, transition, toActivity);     //强制拉取跳转类型的transition 为空类型
            }
            else
            {
                throw new ApplicationException(LocalizeHelper.GetEngineMessage("nextactivitycomponentfactory.CreateNextActivityComponent.jump.error",
                                                                               fromActivity.ActivityType.ToString()));
            }
            return(component);
        }
        /// <summary>
        /// 获取网关节点前的节点
        /// </summary>
        /// <param name="transitionList">转移列表</param>
        /// <param name="toActivityInstanceID">流转到的活动实例ID</param>
        /// <param name="previousActivityInstanceList">前节点实例列表</param>
        private void GetPreviousOfGatewayActivityInstance(IList <TransitionInstanceEntity> transitionList,
                                                          int toActivityInstanceID,
                                                          IList <ActivityInstanceEntity> previousActivityInstanceList)
        {
            var previousTransitionList = transitionList
                                         .Where(o => o.ToActivityInstanceID == toActivityInstanceID)
                                         .ToList();

            var aim = new ActivityInstanceManager();

            foreach (var entity in previousTransitionList)
            {
                var activityType = EnumHelper.ParseEnum <ActivityTypeEnum>(entity.FromActivityType.ToString());
                if (XPDLHelper.IsSimpleComponentNode(activityType) == true)
                {
                    previousActivityInstanceList.Add(aim.GetById(entity.FromActivityInstanceID));
                }
                else if (entity.FromActivityType == (short)ActivityTypeEnum.GatewayNode)
                {
                    GetPreviousOfGatewayActivityInstance(transitionList, entity.FromActivityInstanceID, previousActivityInstanceList);
                }
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// 创建下一步活动的节点
        /// </summary>
        /// <param name="transition">转移</param>
        /// <param name="activity">活动</param>
        /// <returns>下一步节点封装</returns>
        internal static NextActivityComponent CreateNextActivityComponent(TransitionEntity transition,
                                                                          ActivityEntity activity)
        {
            string name = string.Empty;
            NextActivityComponent component = null;

            if (XPDLHelper.IsSimpleComponentNode(activity.ActivityType) == true)           //可流转简单类型节点
            {
                //单一节点
                name      = LocalizeHelper.GetEngineMessage("nextactivitycomponentfactory.singlenode");
                component = new NextActivityItem(name, transition, activity);
            }
            else if (XPDLHelper.IsIntermediateEventComponentNode(activity.ActivityType) == true)
            {
                //跨事件节点
                name      = LocalizeHelper.GetEngineMessage("nextactivitycomponentfactory.intermediatenode");
                component = new NextActivityIntermediate(name, transition, activity);
            }
            else if (XPDLHelper.IsGatewayComponentNode(activity.ActivityType) == true)
            {
                if (activity.GatewayDirectionType == GatewayDirectionEnum.AndSplit ||
                    activity.GatewayDirectionType == GatewayDirectionEnum.AndJoin)
                {
                    //必全选节点
                    name = LocalizeHelper.GetEngineMessage("nextactivitycomponentfactory.mandatorycheckall");
                }
                else if (activity.GatewayDirectionType == GatewayDirectionEnum.AndSplitMI ||
                         activity.GatewayDirectionType == GatewayDirectionEnum.AndJoinMI)
                {
                    //并行多实例节点
                    name = LocalizeHelper.GetEngineMessage("nextactivitycomponentfactory.parallelmultipleinstance");
                }
                else if (activity.GatewayDirectionType == GatewayDirectionEnum.OrSplit ||
                         activity.GatewayDirectionType == GatewayDirectionEnum.OrJoin)
                {
                    //或多选节点
                    name = LocalizeHelper.GetEngineMessage("nextactivitycomponentfactory.orsplitorjoin");
                }
                else if (activity.GatewayDirectionType == GatewayDirectionEnum.XOrSplit ||
                         activity.GatewayDirectionType == GatewayDirectionEnum.XOrJoin)
                {
                    //异或节点
                    name = LocalizeHelper.GetEngineMessage("nextactivitycomponentfactory.xor");
                }
                else if (activity.GatewayDirectionType == GatewayDirectionEnum.EOrJoin)
                {
                    //增强合并多选节点
                    name = LocalizeHelper.GetEngineMessage("nextactivitycomponentfactory.eorjoin");
                }
                else
                {
                    throw new WfXpdlException(LocalizeHelper.GetEngineMessage("nextactivitycomponentfactory.CreateNextActivityComponent.gateway.error",
                                                                              activity.GatewayDirectionType.ToString()));
                }
                component = new NextActivityGateway(name, transition, activity);
            }
            else if (activity.ActivityType == ActivityTypeEnum.SubProcessNode)
            {
                //子流程节点
                name      = LocalizeHelper.GetEngineMessage("nextactivitycomponentfactory.subprocess");
                component = new NextActivityItem(name, transition, activity);
            }
            else
            {
                throw new WfXpdlException(LocalizeHelper.GetEngineMessage("nextactivitycomponentfactory.CreateNextActivityComponent.error",
                                                                          activity.ActivityType.ToString()));
            }

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

            rmins.WfExecutedResult = result = new WfExecutedResult();

            //没有指定退回节点信息
            if (runner.NextPerformerType != NextPerformerIntTypeEnum.Traced &&
                (runner.NextActivityPerformers == null || runner.NextActivityPerformers.Count == 0))
            {
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Sendback_IsNull;
                result.Message       = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceSendBack.null.error");

                return(rmins);
            }

            //先查找当前用户正在办理的运行节点
            var            aim         = new ActivityInstanceManager();
            TaskViewEntity taskView    = null;
            var            runningNode = aim.GetRunningNode(runner, out taskView);

            if (runningNode == null)
            {
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Sendback_NotInRunning;
                result.Message       = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceSendBack.nonerun.error");

                return(rmins);
            }

            if (aim.IsMineTask(runningNode, runner.UserID) == false)
            {
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Sendback_NotMineTask;
                result.Message       = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceSendBack.nonetask.error");
                return(rmins);
            }

            var activityType = EnumHelper.ParseEnum <ActivityTypeEnum>(runningNode.ActivityType.ToString());

            if (XPDLHelper.IsSimpleComponentNode(activityType) == false)
            {
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Sendback_NotTaskNode;
                result.Message       = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceSendBack.nottask.error");
                return(rmins);
            }

            //获取上一步节点信息
            var hasGatewayPassed     = false;
            var processInstance      = (new ProcessInstanceManager()).GetById(runningNode.ProcessInstanceID);
            var processModel         = ProcessModelFactory.Create(processInstance.ProcessGUID, processInstance.Version);
            var previousStepChecker  = new PreviousStepChecker();
            var previousActivityList = previousStepChecker.GetPreviousActivityList(runningNode, processModel, out hasGatewayPassed);

            //判断退回是否有效
            if (previousActivityList == null || previousActivityList.Count == 0)
            {
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Sendback_IsNull;
                result.Message       = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceSendBack.empty.error");
                return(rmins);
            }

            //前端用户指定退回步骤的模式
            if (runner.NextPerformerType != NextPerformerIntTypeEnum.Traced)
            {
                if (runner.NextActivityPerformers == null || runner.NextActivityPerformers.Count == 0)
                {
                    result.Status        = WfExecutedStatus.Exception;
                    result.ExceptionType = WfExceptionType.Sendback_IsNull;
                    result.Message       = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceSendBack.noneperformer.error");

                    return(rmins);
                }

                //检查节点是否一致
                if (previousActivityList.Count == 1)
                {
                    var onlyActivityGUID = previousActivityList[0].ActivityGUID;
                    var isOnly           = true;
                    foreach (var step in runner.NextActivityPerformers)
                    {
                        if (step.Key != onlyActivityGUID)
                        {
                            isOnly = false;
                            break;
                        }
                    }

                    //存在不一致的退回节点
                    if (isOnly == false)
                    {
                        result.Status        = WfExecutedStatus.Exception;
                        result.ExceptionType = WfExceptionType.Sendback_IsTooManyPrevious;
                        result.Message       = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceSendBack.notunique.error");

                        return(rmins);
                    }
                }
            }
            else
            {
                //Traced 用于直接返回上一步使用,测试模式
                var prevActivity  = previousActivityList[0];
                var performerList = PerformerBuilder.CreatePerformerList(runningNode.CreatedByUserID, runningNode.CreatedByUserName);
                runner.NextActivityPerformers = ActivityResource.CreateNextActivityPerformers(prevActivity.ActivityGUID, performerList);
            }

            //创建运行时
            rmins.TaskView = taskView;
            rmins.RunningActivityInstance = runningNode;
            rmins.ProcessInstanceID       = runningNode.ProcessInstanceID;
            rmins.ProcessInstance         = processInstance;
            rmins.ProcessModel            = processModel;

            rmins.AppRunner.AppName                = runner.AppName;
            rmins.AppRunner.AppInstanceID          = runner.AppInstanceID;
            rmins.AppRunner.UserID                 = runner.UserID;
            rmins.AppRunner.UserName               = runner.UserName;
            rmins.AppRunner.NextActivityPerformers = runner.NextActivityPerformers;

            //设置退回选项类
            var sendbackOperation = new SendBackOperation();

            sendbackOperation.BackwardType    = BackwardTypeEnum.Sendback;
            sendbackOperation.ProcessInstance = processInstance;
            sendbackOperation.BackwardFromActivityInstance = runningNode;
            sendbackOperation.HasGatewayPassed             = hasGatewayPassed;
            sendbackOperation.ActivityResource             = new ActivityResource(runner, rmins.AppRunner.NextActivityPerformers);
            sendbackOperation.ProcessModel             = processModel;
            sendbackOperation.IsCancellingBrothersNode = (runner.ControlParameterSheet != null &&
                                                          runner.ControlParameterSheet.IsCancellingBrothersNode == 1) ? true : false;

            rmins.SendBackOperation = sendbackOperation;

            return(rmins);
        }
Exemplo n.º 13
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));
        }
Exemplo n.º 14
0
        /// <summary>
        /// 退回操作
        /// </summary>
        /// <param name="runner">执行者</param>
        /// <param name="result">结果对象</param>
        /// <returns>运行时实例对象</returns>
        internal static WfRuntimeManager CreateRuntimeInstanceSendBack(WfAppRunner runner,
                                                                       ref WfExecutedResult result)
        {
            var rmins = new WfRuntimeManagerSendBack();

            rmins.WfExecutedResult = result = new WfExecutedResult();

            var sendbackOperation = SendbackOperationTypeEnum.Default;

            //先查找当前用户正在办理的运行节点
            var aim         = new ActivityInstanceManager();
            var runningNode = runner.TaskID != null?aim.GetByTask(runner.TaskID.Value)
                                  : aim.GetRunningNode(runner);

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

                return(rmins);
            }

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

            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);
            }

            //获取当前运行主节点信息
            var currentNode = runningNode;

            if (runningNode.MIHostActivityInstanceID != null)
            {
                currentNode = aim.GetById(runningNode.MIHostActivityInstanceID.Value);
            }

            //获取上一步流转节点信息,可能经过And, Or等路由节点
            //判断前置步骤是否经过Gateway节点
            var hasGatewayPassed     = false;
            var processInstance      = (new ProcessInstanceManager()).GetById(runningNode.ProcessInstanceID);
            var processModel         = ProcessModelFactory.Create(processInstance.ProcessGUID, processInstance.Version);
            var previousActivityList = aim.GetPreviousActivityList(runningNode, processModel, out hasGatewayPassed);

            if (previousActivityList == null ||
                previousActivityList.Count == 0)
            {
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Sendback_IsNull;
                result.Message       = "当前没有可以退回的节点,请检查流程数据!";

                return(null);
            }

            //多个退回节点存在的有效退回判断
            IList <ActivityEntity> sendbackPreviousActivityList = new List <ActivityEntity>();

            if (previousActivityList.Count > 1)
            {
                if (runner.NextActivityPerformers == null ||
                    runner.NextActivityPerformers.Count == 0)
                {
                    result.Status        = WfExecutedStatus.Exception;
                    result.ExceptionType = WfExceptionType.Sendback_IsTooManyPrevious;
                    result.Message       = "当前有多个可以退回的节点,无法选择,请明确指定!";

                    return(rmins);
                }

                //明确指定的退回节点,需要判断处理
                var isInvalidSendBack = IsInvalidStepsInPrevousActivityList(previousActivityList,
                                                                            runner.NextActivityPerformers,
                                                                            sendbackPreviousActivityList);

                if (isInvalidSendBack == true)
                {
                    result.Status        = WfExecutedStatus.Exception;
                    result.ExceptionType = WfExceptionType.Sendback_NotContainedInPreviousOrStartNode;
                    result.Message       = "指定的退回节点不在上一步节点运行列表中,或者上一步是开始节点,无法退回!";

                    return(rmins);
                }
            }
            else
            {
                //只有一个要退回去的节点
                sendbackPreviousActivityList.Add(previousActivityList[0]);
            }

            //判断当前节点是否是多实例节点
            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;
                }
            }

            if (hasGatewayPassed == true)
            {
                sendbackOperation = SendbackOperationTypeEnum.GatewayFollowedByParalleledNodes;
            }
            else
            {
                sendbackOperation = SendbackOperationTypeEnum.Normal;
            }

            //根据不同分支场景,创建不同撤销运行时管理器
            return(CreateRuntimeInstanceSendbackByCase(runningNode, processModel, processInstance,
                                                       sendbackPreviousActivityList, hasGatewayPassed, sendbackOperation, runner, ref result));
        }
        /// <summary>
        /// 创建撤销处理运行时
        /// </summary>
        /// <param name="runner">撤销人</param>
        /// <param name="result">创建结果</param>
        /// <returns>运行时管理器</returns>
        internal static WfRuntimeManager CreateRuntimeInstanceWithdraw(WfAppRunner runner,
                                                                       ref WfExecutedResult result)
        {
            var rmins = new WfRuntimeManagerSendBack();

            rmins.WfExecutedResult = result = new WfExecutedResult();

            if (runner.TaskID == null)
            {
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Withdraw_ErrorArguments;
                result.Message       = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceWithdraw.missingtaskid.error");
                return(rmins);
            }
            //获取已经完成任务的信息
            var tm       = new TaskManager();
            var taskDone = tm.GetTaskView(runner.TaskID.Value);

            if (tm.IsMine(taskDone, runner.UserID) == false)
            {
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Sendback_NotMineTask;
                result.Message       = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceWithdraw.nonetask.error");
                return(rmins);
            }

            //赋值下一步办理列表
            runner.NextActivityPerformers = NextStepUtility.CreateNextStepPerformerList(taskDone.ActivityGUID,
                                                                                        taskDone.AssignedToUserID, taskDone.AssignedToUserName);

            //没有指定退回节点信息
            if (runner.NextActivityPerformers == null || runner.NextActivityPerformers.Count == 0)
            {
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Sendback_IsNull;
                result.Message       = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceWithdraw.noneperformer.error");

                return(rmins);
            }

            //获取待办任务
            var tim          = new TransitionInstanceManager();
            var nextStepList = tim.GetTargetActivityInstanceList(taskDone.ActivityInstanceID).ToList();

            ActivityInstanceEntity runningNode = nextStepList.Count > 0 ?  nextStepList[0] : null;

            if (runningNode == null)
            {
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Sendback_NotInRunning;
                result.Message       = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceWithdraw.nonerun.error");

                return(rmins);
            }

            var activityType = EnumHelper.ParseEnum <ActivityTypeEnum>(runningNode.ActivityType.ToString());

            if (XPDLHelper.IsSimpleComponentNode(activityType) == false)
            {
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Sendback_NotTaskNode;
                result.Message       = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceWithdraw.nottask.error");
                return(rmins);
            }

            //获取待办任务(模拟待办任务用户做退回处理)
            var taskToDo = tm.GetTaskViewByActivity(runningNode.ProcessInstanceID, runningNode.ID);

            runner.UserID   = taskToDo.AssignedToUserID;
            runner.UserName = taskToDo.AssignedToUserName;

            //获取上一步节点信息
            var hasGatewayPassed = false;
            var processInstance  = (new ProcessInstanceManager()).GetById(runningNode.ProcessInstanceID);

            var previousStepChecker  = new PreviousStepChecker();
            var processModel         = ProcessModelFactory.Create(taskToDo.ProcessGUID, taskToDo.Version);
            var previousActivityList = previousStepChecker.GetPreviousActivityList(runningNode, processModel, out hasGatewayPassed);

            //判断退回是否有效
            if (previousActivityList == null || previousActivityList.Count == 0)
            {
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Sendback_IsNull;
                result.Message       = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceWithdraw.empty.error");
                return(rmins);
            }

            //检查节点是否一致
            if (previousActivityList.Count == 1)
            {
                var onlyActivityGUID = previousActivityList[0].ActivityGUID;
                var isOnly           = true;
                foreach (var step in runner.NextActivityPerformers)
                {
                    if (step.Key != onlyActivityGUID)
                    {
                        isOnly = false;
                        break;
                    }
                }

                //存在不一致的退回节点
                if (isOnly == false)
                {
                    result.Status        = WfExecutedStatus.Exception;
                    result.ExceptionType = WfExceptionType.Sendback_IsTooManyPrevious;
                    result.Message       = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceWithdraw.notunique.error");

                    return(rmins);
                }
            }

            //创建运行时
            rmins.TaskView = taskToDo;
            rmins.RunningActivityInstance = runningNode;
            rmins.ProcessInstanceID       = runningNode.ProcessInstanceID;
            rmins.ProcessInstance         = processInstance;
            rmins.ProcessModel            = processModel;

            rmins.AppRunner.AppName                = runner.AppName;
            rmins.AppRunner.AppInstanceID          = runner.AppInstanceID;
            rmins.AppRunner.UserID                 = runner.UserID;
            rmins.AppRunner.UserName               = runner.UserName;
            rmins.AppRunner.NextActivityPerformers = runner.NextActivityPerformers;

            //设置退回选项类
            var sendbackOperation = new SendBackOperation();

            sendbackOperation.BackwardType    = BackwardTypeEnum.Withdrawed;
            sendbackOperation.ProcessInstance = processInstance;
            sendbackOperation.BackwardFromActivityInstance = runningNode;
            sendbackOperation.HasGatewayPassed             = hasGatewayPassed;
            sendbackOperation.ActivityResource             = new ActivityResource(runner, rmins.AppRunner.NextActivityPerformers);
            sendbackOperation.ProcessModel             = processModel;
            sendbackOperation.IsCancellingBrothersNode = true;          //撤销时默认撤销各个并行分支

            rmins.SendBackOperation = sendbackOperation;

            return(rmins);
        }
Exemplo n.º 16
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()))
                                         );
                }
            }
        }
Exemplo n.º 17
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);

                            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()))
                                         );
                }
            }
        }