Пример #1
0
        /// <summary>
        /// OrJoin合并时的节点完成方法
        /// 1. 如果有满足条件的OrJoin前驱转移,则会重新生成新的OrJoin节点实例
        /// </summary>
        /// <param name="processInstance"></param>
        /// <param name="fromTransition"></param>
        /// <param name="fromActivityInstance"></param>
        /// <param name="activityResource"></param>
        /// <param name="wfLinqDataContext"></param>
        public GatewayExecutedResult CompleteAutomaticlly(ProcessInstanceEntity processInstance,
                                                          TransitionEntity fromTransition,
                                                          ActivityInstanceEntity fromActivityInstance,
                                                          ActivityResource activityResource,
                                                          ISession session)
        {
            var toActivityInstance = base.CreateActivityInstanceObject(processInstance, activityResource.LogonUser);

            base.InsertActivityInstance(toActivityInstance,
                                        session);

            base.CompleteActivityInstance(toActivityInstance.ActivityInstanceGUID,
                                          activityResource,
                                          session);

            SyncActivityInstanceObjectState(NodeStateEnum.Completed);

            base.InsertTransitionInstance(processInstance,
                                          fromTransition,
                                          fromActivityInstance,
                                          toActivityInstance,
                                          TransitionTypeEnum.Forward,
                                          activityResource.LogonUser,
                                          session);

            GatewayExecutedResult result = GatewayExecutedResult.CreateGatewayExecutedResult(GatewayExecutedStatus.Successed);

            return(result);
        }
Пример #2
0
        /// <summary>
        /// 自动完成结束节点
        /// </summary>
        /// <param name="processInstance"></param>
        /// <param name="fromActivityInstance"></param>
        /// <param name="activityResource"></param>
        /// <param name="wfLinqDataContext"></param>
        public GatewayExecutedResult CompleteAutomaticlly(ProcessInstanceEntity processInstance,
                                                          TransitionEntity fromToTransition,
                                                          ActivityInstanceEntity fromActivityInstance,
                                                          ActivityResource activityResource,
                                                          ISession session)
        {
            GatewayExecutedResult result = null;
            var toActivityInstance       = base.CreateActivityInstanceObject(processInstance, activityResource.LogonUser);

            base.InsertActivityInstance(toActivityInstance,
                                        session);

            base.CompleteActivityInstance(toActivityInstance.ActivityInstanceGUID,
                                          activityResource,
                                          session);

            //写节点转移实例数据
            base.InsertTransitionInstance(processInstance,
                                          fromToTransition,
                                          fromActivityInstance,
                                          toActivityInstance,
                                          TransitionTypeEnum.Forward,
                                          activityResource.LogonUser,
                                          session);

            //设置流程完成
            ProcessInstanceManager pim = new ProcessInstanceManager();

            pim.Complete(processInstance.ProcessInstanceGUID, activityResource.LogonUser, session);

            return(result);
        }
Пример #3
0
        public GatewayExecutedResult CompleteAutomaticlly(ProcessInstanceEntity processInstance,
                                                          TransitionEntity fromTransition,
                                                          ActivityInstanceEntity fromActivityInstance,
                                                          ActivityResource activityResource,
                                                          ISession session)
        {
            GatewayExecutedResult result = GatewayExecutedResult.CreateGatewayExecutedResult(GatewayExecutedStatus.Unknown);

            bool canRenewInstance = false;

            //检查是否有运行中的合并节点实例
            ActivityInstanceEntity joinNode = base.ActivityInstanceManager.GetActivityWithRunningState(
                processInstance.ProcessInstanceGUID,
                base.Activity.ActivityGUID,
                session);

            if (joinNode == null)
            {
                canRenewInstance = true;
            }
            else
            {
                //判断是否可以激活下一步节点
                canRenewInstance = (joinNode.CanRenewInstance == 1);
                if (!canRenewInstance)
                {
                    result = GatewayExecutedResult.CreateGatewayExecutedResult(GatewayExecutedStatus.FallBehindOfXOrJoin);
                    return(result);
                }
            }

            if (canRenewInstance)
            {
                var toActivityInstance = base.CreateActivityInstanceObject(processInstance, activityResource.LogonUser);
                base.InsertActivityInstance(toActivityInstance,
                                            session);

                base.CompleteActivityInstance(toActivityInstance.ActivityInstanceGUID,
                                              activityResource,
                                              session);

                base.SyncActivityInstanceObjectState(NodeStateEnum.Completed);

                //写节点转移实例数据
                base.InsertTransitionInstance(processInstance,
                                              fromTransition,
                                              fromActivityInstance,
                                              toActivityInstance,
                                              TransitionTypeEnum.Forward,
                                              activityResource.LogonUser,
                                              session);

                result = GatewayExecutedResult.CreateGatewayExecutedResult(GatewayExecutedStatus.Successed);
            }
            return(result);
        }
Пример #4
0
        public GatewayExecutedResult CompleteAutomaticlly(ProcessInstanceEntity processInstance,
                                                          TransitionEntity fromTransition,
                                                          ActivityInstanceEntity fromActivityInstance,
                                                          ActivityResource activityResource,
                                                          ISession session)
        {
            //检查是否有运行中的合并节点实例
            ActivityInstanceEntity joinNode = base.ActivityInstanceManager.GetActivityWithRunningState(processInstance.ProcessInstanceGUID,
                                                                                                       base.Activity.ActivityGUID,
                                                                                                       session);

            if (joinNode == null)
            {
                var aiEntity = base.CreateActivityInstanceObject(processInstance, activityResource.LogonUser);
                base.InsertActivityInstance(aiEntity,
                                            session);
            }
            else
            {
                //更新节点的活动实例属性
                base.ActivityInstance = joinNode;
                int tokensRequired = base.ActivityInstance.TokensRequired;
                int tokensHad      = base.ActivityInstance.TokensHad;

                //更新Token数目
                base.ActivityInstanceManager.IncreaseTokensHad(base.ActivityInstance.ActivityInstanceGUID,
                                                               activityResource.LogonUser,
                                                               session);

                if ((tokensHad + 1) == tokensRequired)
                {
                    //如果达到完成节点的Token数,则设置该节点状态为完成
                    base.CompleteActivityInstance(base.ActivityInstance.ActivityInstanceGUID,
                                                  activityResource,
                                                  session);

                    SyncActivityInstanceObjectState(NodeStateEnum.Completed);
                }
            }

            GatewayExecutedResult result = GatewayExecutedResult.CreateGatewayExecutedResult(GatewayExecutedStatus.Successed);

            return(result);
        }
Пример #5
0
        internal static GatewayExecutedResult CreateGatewayExecutedResult(GatewayExecutedStatus status)
        {
            GatewayExecutedResult result = new GatewayExecutedResult(GatewayExecutedStatus.Unknown, "Gateway节点的执行状态未知!");

            switch (status)
            {
            case GatewayExecutedStatus.Successed:
                result = new GatewayExecutedResult(GatewayExecutedStatus.Successed, "Gateway节点成功执行!");
                break;

            case GatewayExecutedStatus.FallBehindOfXOrJoin:
                result = new GatewayExecutedResult(GatewayExecutedStatus.FallBehindOfXOrJoin, "第一个满足条件的节点已经执行,互斥合并节点不能再次被实例化!");
                break;

            default:
                break;
            }
            return(result);
        }
Пример #6
0
        /// <summary>
        /// 递归执行节点
        /// </summary>
        /// <param name="root"></param>
        /// <param name="fromNode"></param>
        /// <param name="conditionKeyValuePair"></param>
        protected void ContinueForwardCurrentNodeRecurisivly(NextActivityComponent root,
                                                             NodeBase fromNode,
                                                             IDictionary <string, string> conditionKeyValuePair)
        {
            foreach (NextActivityComponent c in root)
            {
                if (c.HasChildren)
                {
                    //此节点类型为分支或合并节点类型:首先需要实例化当前节点(自动完成)
                    NodeBase gatewayNode = GatewayNodeFactory.CreateNewNode(c.Activity);
                    ICompleteAutomaticlly autoGatewayNode = (ICompleteAutomaticlly)gatewayNode;
                    GatewayExecutedResult gatewayResult   = autoGatewayNode.CompleteAutomaticlly(WfExecutionContext.ProcessInstance,
                                                                                                 c.Transition,
                                                                                                 fromNode.ActivityInstance,
                                                                                                 WfExecutionContext.ActivityResource,
                                                                                                 Session);

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

                        //新任务加入队列
                        if (workItem.IsAutomanticWorkItem)
                        {
                            ToDoAutoWorkItemQueue.Enqueue(workItem);
                        }
                    }
                    else
                    {
                        //下一步的任务节点没有创建,需给出提示信息
                        if ((fromNode.Activity.GatewayDirectionType | GatewayDirectionEnum.AllJoinType)
                            == GatewayDirectionEnum.AllJoinType)
                        {
                            WfExecutedResult workItemExecutedResult = WfExecutedResult.Exception(
                                WfExecutedStatus.WaitingForOthersJoin,
                                "等待其它需要合并的分支!");
                        }
                    }
                }
                else if (c.Activity.NodeType == NodeTypeEnum.EndNode)
                {
                    //此节点为完成结束节点,结束流程
                    NodeBase endNode = new EndNode(c.Activity);
                    ICompleteAutomaticlly autoEndNode = (ICompleteAutomaticlly)endNode;
                    autoEndNode.CompleteAutomaticlly(WfExecutionContext.ProcessInstance,
                                                     c.Transition,
                                                     fromNode.ActivityInstance,
                                                     WfExecutionContext.ActivityResource,
                                                     Session);
                }
                else
                {
                    WfExecutedResult workItemExecutedResult = WfExecutedResult.XmlError(
                        string.Format("XML文件定义了未知的节点类型,执行失败,节点类型信息:{0}",
                                      c.Activity.NodeType.ToString()));
                }
            }
        }