Exemple #1
0
        public IJoinPoint synchronized(IToken tk)
        {
            IJoinPoint joinPoint = null;

            tk.NodeId = this.Synchronizer.Id;
            //log.debug("The weight of the Entering TransitionInstance is " + tk.getValue());
            // 触发TokenEntered事件
            NodeInstanceEvent event1 = new NodeInstanceEvent(this);

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

            //汇聚检查
            joinPoint = ((ProcessInstance)tk.ProcessInstance).createJoinPoint(this, tk);// JoinPoint由谁生成比较好?
            int value = (int)joinPoint.Value;

            if (value > this.Volume)//如果value大于同步器容量,那说明出错了
            {
                KernelException exception = new KernelException(tk.ProcessInstance,
                                                                this.Synchronizer,
                                                                "Error:The token count of the synchronizer-instance can NOT be  greater than  it's volumn  ");
                throw exception;
            }
            if (value < this.Volume)
            {// 如果Value小于容量则继续等待其他弧的汇聚。 (哪些状态为dead的token到此结束,不再向下传递)
                return(null);
            }
            return(joinPoint);
        }
Exemple #2
0
        public bool CanApply(IJoinPoint joinPoint, Type aspectType)
        {
            if (aspectType.BaseType.IsGenericType)
            {
                var attibuteTypes = aspectType.BaseType.GetGenericArguments();
                if (attibuteTypes.Length > 0)
                {
                    var attibuteType = attibuteTypes.FirstOrDefault(x => typeof(AbstractAspectAttribute).IsAssignableFrom(x));
                    if (attibuteType != null)
                    {
                        var attributes = joinPoint.MethodInfo.GetCustomAttributes(attibuteType, true);
                        return attributes.Length > 0;
                    }
                    return false;
                }
                else
                {
                    return false;
                }

            }
            else
            {
                return true;
            }
        }
Exemple #3
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);
        }
Exemple #4
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 #5
0
        /// <summary>生成joinPoint</summary>
        /// <param name="synchInst"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public IJoinPoint createJoinPoint(ISynchronizerInstance synchInst, IToken token)// throws EngineException
        {
            int enterTransInstanceCount = synchInst.EnteringTransitionInstances.Count;

            if (enterTransInstanceCount == 0)//检查流程定义是否合法,同步器节点必须有输入边
            {
                throw new EngineException(this.Id, this.WorkflowProcess,
                                          synchInst.Synchronizer.Id, "The process definition [" + this.Name + "] is invalid,the synchronizer[" + synchInst.Synchronizer + "] has no entering transition");
            }
            IPersistenceService persistenceService = this.RuntimeContext.PersistenceService;

            //保存到数据库
            persistenceService.SaveOrUpdateToken(token);

            IJoinPoint resultJoinPoint = null;

            resultJoinPoint = new JoinPoint();
            resultJoinPoint.ProcessInstance = this;
            resultJoinPoint.SynchronizerId  = synchInst.Synchronizer.Id;
            if (enterTransInstanceCount == 1)
            {
                // 生成一个不存储到数据库中的JoinPoint
                resultJoinPoint.addValue(token.Value);

                if (token.IsAlive)
                {
                    resultJoinPoint.Alive          = true;
                    resultJoinPoint.FromActivityId = token.FromActivityId;
                }
                resultJoinPoint.StepNumber = token.StepNumber + 1;

                return(resultJoinPoint);
            }
            else
            {
                int stepNumber = 0;

                List <IToken> tokensList_0            = persistenceService.FindTokensForProcessInstance(this.Id, synchInst.Synchronizer.Id);
                Dictionary <String, IToken> tokensMap = new Dictionary <String, IToken>();
                for (int i = 0; i < tokensList_0.Count; i++)
                {
                    IToken tmpToken          = (IToken)tokensList_0[i];
                    String tmpFromActivityId = tmpToken.FromActivityId;
                    if (!tokensMap.ContainsKey(tmpFromActivityId))
                    {
                        tokensMap.Add(tmpFromActivityId, tmpToken);
                    }
                    else
                    {
                        //TODO  ====下面的代码有意义吗?===start===wmj2003
                        IToken tmpToken2 = (IToken)tokensMap[tmpFromActivityId];
                        if (tmpToken2.StepNumber > tmpToken.StepNumber)
                        {
                            tokensMap[tmpFromActivityId] = tmpToken2;
                        }
                        //TODO  ====下面的代码有意义吗?===end===wmj2003
                    }
                }

                List <IToken> tokensList = new List <IToken>(tokensMap.Values);

                for (int i = 0; i < tokensList.Count; i++)
                {
                    IToken _token = (IToken)tokensList[i];
                    resultJoinPoint.addValue(_token.Value);
                    if (_token.IsAlive)//如果token的状态是alive
                    {
                        resultJoinPoint.Alive = true;
                        String oldFromActivityId = resultJoinPoint.FromActivityId;
                        if (String.IsNullOrEmpty(oldFromActivityId))
                        {
                            resultJoinPoint.FromActivityId = _token.FromActivityId;
                        }
                        else
                        {
                            resultJoinPoint.FromActivityId = oldFromActivityId + TokenFrom.FROM_ACTIVITY_ID_SEPARATOR + _token.FromActivityId;
                        }
                    }
                    if (token.StepNumber > stepNumber)
                    {
                        stepNumber = token.StepNumber;
                    }
                }

                resultJoinPoint.StepNumber = stepNumber + 1;

                return(resultJoinPoint);
            }
        }