Ejemplo n.º 1
0
        public override void fire(IToken tk)
        {
            IJoinPoint joinPoint = synchronized(tk);

            if (joinPoint == null)
            {
                return;
            }
            IProcessInstance  processInstance = tk.ProcessInstance;
            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);

            //首先必须检查是否有满足条件的循环
            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)
            {
                NodeInstanceEvent event3 = new NodeInstanceEvent(this);
                event3.Token     = tk;
                event3.EventType = NodeInstanceEventEnum.NODEINSTANCE_COMPLETED;
                this.fireNodeEvent(event3);
            }

            //        NodeInstanceEvent event4 = new NodeInstanceEvent(this);
            //        event4.setToken(tk);
            //        event4.setEventType(NodeInstanceEvent.NODEINSTANCE_LEAVING);
            //        this.fireNodeEvent(event4);
        }
Ejemplo n.º 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);
        }