Exemple #1
0
        /// <summary>结束活动</summary>
        /// <param name="token"></param>
        /// <param name="targetActivityInstance"></param>
        public void complete(IToken token, IActivityInstance targetActivityInstance)
        {
            NodeInstanceEvent event2 = new NodeInstanceEvent(this);

            event2.Token     = token;
            event2.EventType = NodeInstanceEventEnum.NODEINSTANCE_LEAVING;//token leaving
            this.fireNodeEvent(event2);


            token.FromActivityId = this.Activity.Id;

            if (targetActivityInstance != null)
            {
                token.StepNumber = token.StepNumber + 1;
                targetActivityInstance.fire(token);
            }
            else
            {
                //按照定义,activity有且只有一个输出弧,所以此处只进行一次循环。
                for (int i = 0; LeavingTransitionInstances != null && i < LeavingTransitionInstances.Count; i++)
                {
                    ITransitionInstance transInst = LeavingTransitionInstances[i];
                    transInst.take(token);
                }
            }

            if (token.IsAlive)
            {
                NodeInstanceEvent neevent = new NodeInstanceEvent(this);
                neevent.Token     = token;
                neevent.EventType = NodeInstanceEventEnum.NODEINSTANCE_COMPLETED;//token completed
                this.fireNodeEvent(neevent);
            }
        }
Exemple #2
0
        public override void fire(IToken tk)
        {
            //TODO 此处性能需要改善一下,20090312
            IJoinPoint joinPoint = synchronized(tk);

            if (joinPoint == null)
            {
                return;
            }

            //如果汇聚点的容量和同步器节点的容量相同
            IProcessInstance processInstance = tk.ProcessInstance;
            // Synchronize的fire条件应该只与joinPoint的value有关(value==volume),与alive无关
            NodeInstanceEvent event2 = new NodeInstanceEvent(this);

            event2.Token     = tk;
            event2.EventType = NodeInstanceEventEnum.NODEINSTANCE_FIRED;
            this.fireNodeEvent(event2);

            //在此事件监听器中,删除原有的token
            NodeInstanceEvent event4 = new NodeInstanceEvent(this);

            event4.Token     = tk;
            event4.EventType = NodeInstanceEventEnum.NODEINSTANCE_LEAVING;

            this.fireNodeEvent(event4);

            //首先必须检查是否有满足条件的循环,loop比transition有更高的优先级,
            //(只能够有一个loop的条件为true,流程定义的时候需要注意)
            Boolean doLoop = false;//表示是否有满足条件的循环,false表示没有,true表示有。

            if (joinPoint.Alive)
            {
                IToken tokenForLoop = null;

                tokenForLoop                 = new Token(); // 产生新的token
                tokenForLoop.IsAlive         = joinPoint.Alive;
                tokenForLoop.ProcessInstance = processInstance;
                tokenForLoop.StepNumber      = joinPoint.StepNumber - 1;
                tokenForLoop.FromActivityId  = joinPoint.FromActivityId;

                for (int i = 0; i < this.LeavingLoopInstances.Count; i++)
                {
                    ILoopInstance loopInstance = this.LeavingLoopInstances[i];
                    doLoop = loopInstance.take(tokenForLoop);
                    if (doLoop)
                    {
                        break;
                    }
                }
            }
            if (!doLoop)
            {//如果没有循环,则执行transitionInstance
                //非顺序流转的需要生成新的token,
                Boolean             activiateDefaultCondition = true;
                ITransitionInstance defaultTransInst          = null;
                for (int i = 0; LeavingTransitionInstances != null && i < LeavingTransitionInstances.Count; i++)
                {
                    ITransitionInstance transInst = LeavingTransitionInstances[i];
                    String condition = transInst.Transition.Condition;
                    if (condition != null && condition.Equals(ConditionConstant.DEFAULT))
                    {
                        defaultTransInst = transInst;
                        continue;
                    }

                    Token token = new Token(); // 产生新的token
                    token.IsAlive         = joinPoint.Alive;
                    token.ProcessInstance = processInstance;
                    token.StepNumber      = joinPoint.StepNumber;
                    token.FromActivityId  = joinPoint.FromActivityId;
                    Boolean alive = transInst.take(token);
                    if (alive)
                    {
                        activiateDefaultCondition = false;
                    }
                }
                if (defaultTransInst != null)
                {
                    Token token = new Token();
                    token.IsAlive         = activiateDefaultCondition && joinPoint.Alive;
                    token.ProcessInstance = processInstance;
                    token.StepNumber      = joinPoint.StepNumber;
                    token.FromActivityId  = joinPoint.FromActivityId;
                    defaultTransInst.take(token);
                }
            }

            NodeInstanceEvent event3 = new NodeInstanceEvent(this);

            event3.Token     = tk;
            event3.EventType = NodeInstanceEventEnum.NODEINSTANCE_COMPLETED;
            this.fireNodeEvent(event3);
        }
Exemple #3
0
        /// <summary>
        /// 开始节点触发
        /// </summary>
        /// <param name="tk"></param>
        public override void fire(IToken tk)
        {
            if (!tk.IsAlive) //如果token是false,那么直接返回
            {
                return;      //
            }
            if (tk.Value != this.Volume)
            {
                KernelException exception = new KernelException(tk.ProcessInstance,
                                                                this.startNode,
                                                                "Error:Illegal StartNodeInstance,the tokenValue MUST be equal to the volume ");
                throw exception;
            }

            tk.NodeId = this.Synchronizer.Id;                      //到开始节点(同步器)

            IProcessInstance processInstance = tk.ProcessInstance; //从token中获得流程实例对象

            //触发token_entered事件
            NodeInstanceEvent event1 = new NodeInstanceEvent(this);

            event1.Token     = tk;
            event1.EventType = NodeInstanceEventEnum.NODEINSTANCE_TOKEN_ENTERED;//token进入
            this.fireNodeEvent(event1);

            //触发fired事件
            NodeInstanceEvent event2 = new NodeInstanceEvent(this);

            event2.Token     = tk;
            event2.EventType = NodeInstanceEventEnum.NODEINSTANCE_FIRED;//token 触发
            this.fireNodeEvent(event2);

            //触发leaving事件
            NodeInstanceEvent event4 = new NodeInstanceEvent(this);

            event4.Token     = tk;
            event4.EventType = NodeInstanceEventEnum.NODEINSTANCE_LEAVING;//token 离开
            this.fireNodeEvent(event4);


            Boolean             activiateDefaultCondition = true;//激活默认弧线的标志
            ITransitionInstance defaultTransInst          = null;

            //找到所有开始节点的输出弧
            for (int i = 0; LeavingTransitionInstances != null && i < LeavingTransitionInstances.Count; i++)
            {
                ITransitionInstance transInst = LeavingTransitionInstances[i];//开始节点的边的类型只能是transition
                String condition = transInst.Transition.Condition;
                //如果弧线的条件!=null 并且 =“default” ,那么弧线实例就是default的弧线了。
                if (condition != null && condition.Equals(ConditionConstant.DEFAULT))
                {
                    defaultTransInst = transInst;//记录default转移线,其他条件都未false,才执行它
                    continue;
                }

                Token token = new Token(); // 产生新的token
                token.IsAlive         = true;
                token.ProcessInstance = processInstance;
                token.FromActivityId  = tk.FromActivityId;
                token.StepNumber      = tk.StepNumber + 1; //步骤号+1

                Boolean alive = transInst.take(token);     //触发弧线的token
                if (alive)
                {
                    activiateDefaultCondition = false;
                }
            }
            if (defaultTransInst != null)//如果defaultTransInst!=null ,走的是default值的弧线
            {
                Token token = new Token();
                token.IsAlive         = activiateDefaultCondition;//设置token为dead
                token.ProcessInstance = processInstance;
                token.FromActivityId  = token.FromActivityId;
                token.StepNumber      = tk.StepNumber + 1;
                defaultTransInst.take(token);
            }


            //触发completed事件
            NodeInstanceEvent event3 = new NodeInstanceEvent(this);

            event3.Token     = tk;
            event3.EventType = NodeInstanceEventEnum.NODEINSTANCE_COMPLETED;
            this.fireNodeEvent(event3);
        }