Exemplo n.º 1
0
        /// <summary>
        /// EOrJoin合并时的节点完成方法
        /// 根据前置转移上定义的是否强制分支来判断完成合并节点
        /// </summary>
        /// <param name="processInstance">流程实例</param>
        /// <param name="transitionGUID">转移GUID</param>
        /// <param name="fromActivity">起始活动</param>
        /// <param name="fromActivityInstance">起始活动实例</param>
        /// <param name="runner">运行者</param>
        /// <param name="session">会话</param>
        private NodeAutoExecutedResult CompleteAutomaticallyByForcedBranchesCount(ProcessInstanceEntity processInstance,
                                                                                  string transitionGUID,
                                                                                  ActivityEntity fromActivity,
                                                                                  ActivityInstanceEntity fromActivityInstance,
                                                                                  WfAppRunner runner,
                                                                                  IDbSession session)
        {
            NodeAutoExecutedResult result = NodeAutoExecutedResult.CreateGatewayExecutedResult(NodeAutoExecutedStatus.Unknown);

            IList <TransitionEntity> forcedTransitionList = null;
            var tokensCountRequired = base.ProcessModel.GetForcedBranchesCountBeforeEOrJoin(GatewayActivity, out forcedTransitionList);

            if (tokensCountRequired == 0)
            {
                result = NodeAutoExecutedResult.CreateGatewayExecutedResult(NodeAutoExecutedStatus.Failed);
                throw new WfXpdlException(LocalizeHelper.GetEngineMessage("nodemediatoreorjoin.CompleteAutomaticallyByForcedBranchesCount.error"));
            }

            //根据强制分支的数目和具体分支来完成增强合并节点
            var forcedCount = forcedTransitionList.Where(t => t.TransitionGUID == transitionGUID).Count();

            if (forcedCount == 0)
            {
                //当前执行的分支不是强制分支,直接返回就可以
                result = NodeAutoExecutedResult.CreateGatewayExecutedResult(NodeAutoExecutedStatus.NotForcedBrancheWhenEOrJoin);
            }
            else if (forcedCount == 1)
            {
                result = CompleteAutomaticallyInternal(processInstance, transitionGUID, fromActivity, fromActivityInstance, tokensCountRequired, runner, session);
            }
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 自动完成
        /// </summary>
        /// <param name="processInstance">流程实例</param>
        /// <param name="transitionGUID">转移GUID</param>
        /// <param name="fromActivity">起始活动</param>
        /// <param name="fromActivityInstance">起始活动实例</param>
        /// <param name="toActivity">目标活动</param>
        /// <param name="runner">运行者</param>
        /// <param name="session">会话</param>
        /// <returns>网关执行结果</returns>
        public NodeAutoExecutedResult CompleteAutomaticlly(ProcessInstanceEntity processInstance,
                                                           string transitionGUID,
                                                           ActivityEntity fromActivity,
                                                           ActivityInstanceEntity fromActivityInstance,
                                                           ActivityEntity toActivity,
                                                           WfAppRunner runner,
                                                           IDbSession session)
        {
            var gatewayActivityInstance = base.CreateActivityInstanceObject(toActivity, processInstance, runner);

            base.InsertActivityInstance(gatewayActivityInstance,
                                        session);

            base.CompleteActivityInstance(gatewayActivityInstance.ID,
                                          runner,
                                          session);

            gatewayActivityInstance.ActivityState = (short)ActivityStateEnum.Completed;
            base.Linker.ToActivityInstance        = gatewayActivityInstance;

            //写节点转移实例数据
            base.InsertTransitionInstance(processInstance,
                                          transitionGUID,
                                          fromActivityInstance,
                                          gatewayActivityInstance,
                                          TransitionTypeEnum.Forward,
                                          TransitionFlyingTypeEnum.NotFlying,
                                          runner,
                                          session);

            NodeAutoExecutedResult result = NodeAutoExecutedResult.CreateGatewayExecutedResult(NodeAutoExecutedStatus.Successed);

            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// EOrJoin合并时的节点完成方法
        /// 前端动态传递要合并的Tokens的数目
        /// </summary>
        /// <param name="processInstance">流程实例</param>
        /// <param name="transitionGUID">转移GUID</param>
        /// <param name="fromActivity">起始活动</param>
        /// <param name="fromActivityInstance">起始活动实例</param>
        /// <param name="runner">运行者</param>
        /// <param name="session">会话</param>
        private NodeAutoExecutedResult CompleteAutomaticallyByTokensCount(ProcessInstanceEntity processInstance,
                                                                          string transitionGUID,
                                                                          ActivityEntity fromActivity,
                                                                          ActivityInstanceEntity fromActivityInstance,
                                                                          WfAppRunner runner,
                                                                          IDbSession session)
        {
            NodeAutoExecutedResult result = NodeAutoExecutedResult.CreateGatewayExecutedResult(NodeAutoExecutedStatus.Unknown);

            if (runner.ControlParameterSheet == null || runner.ControlParameterSheet.EOrJoinTokenPassCount <= 0)
            {
                result = NodeAutoExecutedResult.CreateGatewayExecutedResult(NodeAutoExecutedStatus.Failed);
                throw new WfXpdlException(LocalizeHelper.GetEngineMessage("nodemediatoreorjoin.CompleteAutomaticallyByTokensCount.error"));
            }
            var tokensCountRequired = runner.ControlParameterSheet.EOrJoinTokenPassCount;

            result = CompleteAutomaticallyInternal(processInstance, transitionGUID, fromActivity, fromActivityInstance, tokensCountRequired, runner, session);
            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// EOrJoin合并时的节点完成方法
        /// </summary>
        /// <param name="processInstance">流程实例</param>
        /// <param name="transitionGUID">转移GUID</param>
        /// <param name="fromActivity">起始活动</param>
        /// <param name="fromActivityInstance">起始活动实例</param>
        /// <param name="runner">运行者</param>
        /// <param name="session">会话</param>
        public NodeAutoExecutedResult CompleteAutomaticlly(ProcessInstanceEntity processInstance,
                                                           string transitionGUID,
                                                           ActivityEntity fromActivity,
                                                           ActivityInstanceEntity fromActivityInstance,
                                                           WfAppRunner runner,
                                                           IDbSession session)
        {
            NodeAutoExecutedResult result = NodeAutoExecutedResult.CreateGatewayExecutedResult(NodeAutoExecutedStatus.Unknown);

            //根据强制或合并类型来处理
            if (GatewayActivity.GatewayJoinPassType == GatewayJoinPassEnum.TokenCountPass)
            {
                result = CompleteAutomaticallyByTokensCount(processInstance, transitionGUID, fromActivity, fromActivityInstance, runner, session);
            }
            else if (GatewayActivity.GatewayJoinPassType == GatewayJoinPassEnum.ForcedBranchPass)
            {
                result = CompleteAutomaticallyByForcedBranchesCount(processInstance, transitionGUID, fromActivity, fromActivityInstance, runner, session);
            }
            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 置开始节点为结束状态
        /// </summary>
        /// <param name="processInstance"></param>
        /// <param name="activityResource"></param>
        /// <param name="session"></param>
        /// <returns></returns>
        private NodeAutoExecutedResult CompleteAutomaticlly(ProcessInstanceEntity processInstance,
                                                            ActivityResource activityResource,
                                                            IDbSession session)
        {
            //开始节点没前驱信息
            var fromActivityInstance = base.CreateActivityInstanceObject(base.Linker.FromActivity, processInstance, activityResource.AppRunner);

            base.ActivityInstanceManager.Insert(fromActivityInstance, session);

            base.ActivityInstanceManager.Complete(fromActivityInstance.ID,
                                                  activityResource.AppRunner,
                                                  session);

            fromActivityInstance.ActivityState = (short)ActivityStateEnum.Completed;
            base.Linker.FromActivityInstance   = fromActivityInstance;

            NodeAutoExecutedResult result = NodeAutoExecutedResult.CreateGatewayExecutedResult(NodeAutoExecutedStatus.Successed);

            return(result);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 自动完成
        /// </summary>
        /// <param name="processInstance">流程实例</param>
        /// <param name="transitionGUID">转移GUID</param>
        /// <param name="fromActivity">起始活动</param>
        /// <param name="fromActivityInstance">起始活动实例</param>
        /// <param name="runner">运行者</param>
        /// <param name="session">会话</param>
        /// <returns>网关执行结果</returns>
        public NodeAutoExecutedResult CompleteAutomaticlly(ProcessInstanceEntity processInstance,
                                                           string transitionGUID,
                                                           ActivityEntity fromActivity,
                                                           ActivityInstanceEntity fromActivityInstance,
                                                           WfAppRunner runner,
                                                           IDbSession session)
        {
            NodeAutoExecutedResult result = NodeAutoExecutedResult.CreateGatewayExecutedResult(NodeAutoExecutedStatus.Unknown);

            //XOrJoin合并,直接置为完成状态,因为始终只有一个分支可以得到执行,其它分支被排斥
            var gatewayActivityInstance = base.CreateActivityInstanceObject(base.GatewayActivity,
                                                                            processInstance, runner);

            gatewayActivityInstance.GatewayDirectionTypeID = (short)GatewayDirectionEnum.XOrJoin;

            base.InsertActivityInstance(gatewayActivityInstance,
                                        session);

            base.CompleteActivityInstance(gatewayActivityInstance.ID,
                                          runner,
                                          session);

            gatewayActivityInstance.ActivityState = (short)ActivityStateEnum.Completed;
            base.GatewayActivityInstance          = gatewayActivityInstance;

            //写节点转移实例数据
            base.InsertTransitionInstance(processInstance,
                                          transitionGUID,
                                          fromActivityInstance,
                                          gatewayActivityInstance,
                                          TransitionTypeEnum.Forward,
                                          TransitionFlyingTypeEnum.NotFlying,
                                          runner,
                                          session);

            result = NodeAutoExecutedResult.CreateGatewayExecutedResult(NodeAutoExecutedStatus.Successed);

            return(result);
        }
Exemplo n.º 7
0
        /// <summary>
        /// EOrJoin合并时的节点完成方法
        /// 内部执行逻辑
        /// </summary>
        /// <param name="processInstance">流程实例</param>
        /// <param name="transitionGUID">转移GUID</param>
        /// <param name="fromActivity">起始活动</param>
        /// <param name="fromActivityInstance">起始活动实例</param>
        /// <param name="tokensCountRequired">合并要求的Token数目</param>
        /// <param name="runner">运行者</param>
        /// <param name="session">会话</param>
        private NodeAutoExecutedResult CompleteAutomaticallyInternal(ProcessInstanceEntity processInstance,
                                                                     string transitionGUID,
                                                                     ActivityEntity fromActivity,
                                                                     ActivityInstanceEntity fromActivityInstance,
                                                                     int tokensCountRequired,
                                                                     WfAppRunner runner,
                                                                     IDbSession session)
        {
            NodeAutoExecutedResult result = NodeAutoExecutedResult.CreateGatewayExecutedResult(NodeAutoExecutedStatus.Unknown);
            //当前执行的分支就是强制分支
            //检查是否有运行中的合并节点实例
            ActivityInstanceEntity joinNode = base.ActivityInstanceManager.GetActivityRunning(
                processInstance.ID,
                base.GatewayActivity.ActivityGUID,
                session);;

            if (joinNode == null)
            {
                //第一个分支首次运行
                joinNode = base.CreateActivityInstanceObject(base.GatewayActivity,
                                                             processInstance, runner);

                //计算总需要的Token数目
                joinNode.TokensRequired = tokensCountRequired;
                joinNode.TokensHad      = 1;

                //进入运行状态
                joinNode.ActivityState          = (short)ActivityStateEnum.Running;
                joinNode.GatewayDirectionTypeID = (short)GatewayDirectionEnum.OrJoin;

                //写入默认第一次的预选步骤用户列表
                joinNode.NextStepPerformers = NextStepUtility.SerializeNextStepPerformers(runner.NextActivityPerformers);

                base.InsertActivityInstance(joinNode,
                                            session);
                base.InsertTransitionInstance(processInstance,
                                              transitionGUID,
                                              fromActivityInstance,
                                              joinNode,
                                              TransitionTypeEnum.Forward,
                                              TransitionFlyingTypeEnum.NotFlying,
                                              runner,
                                              session);
            }
            else
            {
                //更新节点的活动实例属性
                joinNode.TokensHad          += 1;
                base.GatewayActivityInstance = joinNode;

                //更新Token数目
                base.ActivityInstanceManager.IncreaseTokensHad(base.GatewayActivityInstance.ID,
                                                               runner,
                                                               session);
                base.InsertTransitionInstance(processInstance,
                                              transitionGUID,
                                              fromActivityInstance,
                                              joinNode,
                                              TransitionTypeEnum.Forward,
                                              TransitionFlyingTypeEnum.NotFlying,
                                              runner,
                                              session);
            }

            //判断是否到达合并节点的通过Token数目要求
            if (joinNode.TokensHad == joinNode.TokensRequired)
            {
                //如果达到完成节点的Token数,则设置该节点状态为完成
                base.CompleteActivityInstance(base.GatewayActivityInstance.ID,
                                              runner,
                                              session);
                base.GatewayActivityInstance.ActivityState = (short)ActivityStateEnum.Completed;

                //更新其它分支上的待办节点为阻止状态(CanRenewInstance = 0)
                base.ActivityInstanceManager.UpdateActivityInstanceBlockedBetweenSplitJoin(base.GatewayActivity, base.GatewayActivityInstance,
                                                                                           base.ProcessModel, session);

                result = NodeAutoExecutedResult.CreateGatewayExecutedResult(NodeAutoExecutedStatus.Successed);
            }
            else if (joinNode.TokensHad < joinNode.TokensRequired)
            {
                result = NodeAutoExecutedResult.CreateGatewayExecutedResult(NodeAutoExecutedStatus.WaitingForOthersJoin);
            }
            return(result);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 自动完成
        /// </summary>
        /// <param name="processInstance">流程实例</param>
        /// <param name="transitionGUID">转移GUID</param>
        /// <param name="fromActivity">起始活动</param>
        /// <param name="fromActivityInstance">起始活动实例</param>
        /// <param name="runner">运行者</param>
        /// <param name="session">会话</param>
        /// <returns>网关执行结果</returns>
        public NodeAutoExecutedResult CompleteAutomaticlly(ProcessInstanceEntity processInstance,
                                                           string transitionGUID,
                                                           ActivityEntity fromActivity,
                                                           ActivityInstanceEntity fromActivityInstance,
                                                           WfAppRunner runner,
                                                           IDbSession session)
        {
            //检查是否有运行中的合并节点实例
            ActivityInstanceEntity joinNode = base.ActivityInstanceManager.GetActivityRunning(processInstance.ID,
                                                                                              base.GatewayActivity.ActivityGUID,
                                                                                              session);

            int tokensRequired = 0;
            int tokensHad      = 0;

            if (joinNode == null)
            {
                var joinActivityInstance = base.CreateActivityInstanceObject(base.GatewayActivity,
                                                                             processInstance, runner);

                //计算总需要的Token数目
                joinActivityInstance.TokensRequired = GetTokensRequired();
                joinActivityInstance.TokensHad      = 1;
                tokensRequired = joinActivityInstance.TokensRequired;

                //进入运行状态
                joinActivityInstance.ActivityState          = (short)ActivityStateEnum.Running;
                joinActivityInstance.GatewayDirectionTypeID = (short)GatewayDirectionEnum.AndJoin;

                //写入默认第一次的预选步骤用户列表
                joinActivityInstance.NextStepPerformers = NextStepUtility.SerializeNextStepPerformers(runner.NextActivityPerformers);

                base.InsertActivityInstance(joinActivityInstance,
                                            session);
                base.InsertTransitionInstance(processInstance,
                                              transitionGUID,
                                              fromActivityInstance,
                                              joinActivityInstance,
                                              TransitionTypeEnum.Forward,
                                              TransitionFlyingTypeEnum.NotFlying,
                                              runner,
                                              session);
            }
            else
            {
                //更新节点的活动实例属性
                base.GatewayActivityInstance = joinNode;
                tokensRequired = base.GatewayActivityInstance.TokensRequired;
                tokensHad      = base.GatewayActivityInstance.TokensHad;
                //更新Token数目
                base.ActivityInstanceManager.IncreaseTokensHad(base.GatewayActivityInstance.ID,
                                                               runner,
                                                               session);
                base.InsertTransitionInstance(processInstance,
                                              transitionGUID,
                                              fromActivityInstance,
                                              joinNode,
                                              TransitionTypeEnum.Forward,
                                              TransitionFlyingTypeEnum.NotFlying,
                                              runner,
                                              session);
            }
            if ((tokensHad + 1) == tokensRequired)
            {
                //如果达到完成节点的Token数,则设置该节点状态为完成
                base.CompleteActivityInstance(base.GatewayActivityInstance.ID,
                                              runner,
                                              session);
                base.GatewayActivityInstance.ActivityState = (short)ActivityStateEnum.Completed;
            }

            NodeAutoExecutedResult result = NodeAutoExecutedResult.CreateGatewayExecutedResult(
                NodeAutoExecutedStatus.Successed);

            return(result);
        }