/// <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); } }
protected internal virtual void WriteTree(StringBuilder writer, string prefix, bool isTail) { writer.Append(prefix); if (isTail) { writer.Append("������ "); } else { writer.Append("������ "); } writer.Append(ActivityId + "=>" + Id + "\n"); for (int i = 0; i < childTransitionInstances.Length; i++) { ITransitionInstance transitionInstance = childTransitionInstances[i]; bool transitionIsTail = (i == (childTransitionInstances.Length - 1)) && (childActivityInstances.Length == 0); WriteTransition(transitionInstance, writer, prefix + (isTail ? " " : "�? "), transitionIsTail); } for (int i = 0; i < childActivityInstances.Length; i++) { ActivityInstanceImpl child = (ActivityInstanceImpl)childActivityInstances[i]; child.WriteTree(writer, prefix + (isTail ? " " : "�? "), (i == (childActivityInstances.Length - 1))); } }
public virtual MigratingTransitionInstance AddTransitionInstance(IMigrationInstruction migrationInstruction, ITransitionInstance transitionInstance, ScopeImpl sourceScope, ScopeImpl targetScope, ExecutionEntity asyncExecution) { var migratingTransitionInstance = new MigratingTransitionInstance(transitionInstance, migrationInstruction, sourceScope, targetScope, asyncExecution); migratingTransitionInstances.Add(migratingTransitionInstance); return(migratingTransitionInstance); }
public MigratingTransitionInstance(ITransitionInstance transitionInstance, IMigrationInstruction migrationInstruction, ScopeImpl sourceScope, ScopeImpl targetScope, ExecutionEntity asyncExecution) { this.transitionInstance = transitionInstance; this.migrationInstruction = migrationInstruction; this.sourceScope = sourceScope; this.targetScope = targetScope; currentScope = sourceScope; RepresentativeExecution = asyncExecution; ActiveState = RepresentativeExecution.IsActive; }
protected internal virtual void WriteTransition(ITransitionInstance transition, StringBuilder writer, string prefix, bool isTail) { writer.Append(prefix); if (isTail) { writer.Append("������ "); } else { writer.Append("������ "); } writer.Append("transition to/from " + transition.ActivityId + ":" + transition.Id + "\n"); }
protected internal virtual bool MatchesRequestedTransitionInstance(ITransitionInstance instance, string queryInstanceId) { var match = instance.Id.Equals(queryInstanceId); // check if the execution queried for has been replaced by the given instance // => if yes, given instance is matched // this is a fix for CAM-4090 to tolerate inconsistent transition instance ids as described in CAM-4143 if (!match) { // note: execution id = transition instance id //ExecutionEntity cachedExecution = Context.CommandContext.DbEntityManager.getCachedEntity<ExecutionEntity>(typeof(ExecutionEntity), queryInstanceId); // follow the links of execution replacement; // note: this can be at most two hops: // case 1: // the query execution is the scope execution // => tree may have expanded meanwhile // => scope execution references replacing execution directly (one hop) // // case 2: // the query execution is a concurrent execution // => tree may have compacted meanwhile // => concurrent execution references scope execution directly (one hop) // // case 3: // the query execution is a concurrent execution // => tree may have compacted/expanded/compacted/../expanded any number of times // => the concurrent execution has been removed and therefore references the scope execution (first hop) // => the scope execution may have been replaced itself again with another concurrent execution (second hop) // note that the scope execution may have a long "history" of replacements, but only the last replacement is relevant here // if (cachedExecution != null) // { //ExecutionEntity replacingExecution = cachedExecution.resolveReplacedBy(); //if (replacingExecution != null) //{ // match = replacingExecution.Id.Equals(instance.Id); //} // } } return(match); }
/// <summary>节点实例监听器</summary> public void onEdgeInstanceEventFired(EdgeInstanceEvent e) { if (e.EventType == EdgeInstanceEventEnum.ON_TAKING_THE_TOKEN) { IToken token = e.Token; ITransitionInstance transInst = (ITransitionInstance)e.getSource(); String condition = transInst.Transition.Condition; calculateTheAliveValue(token, condition); if (this.RuntimeContext.IsEnableTrace && token.IsAlive) { Transition transition = transInst.Transition; IWFElement fromNode = transition.FromNode; int minorNumber = 1; if (fromNode is Activity) { minorNumber = 2; } else { minorNumber = 1; } ProcessInstanceTrace trace = new ProcessInstanceTrace(); trace.ProcessInstanceId = e.Token.ProcessInstanceId; trace.StepNumber = e.Token.StepNumber; trace.Type = ProcessInstanceTraceEnum.TRANSITION_TYPE; trace.FromNodeId = transInst.Transition.FromNode.Id; trace.ToNodeId = transInst.Transition.ToNode.Id; trace.EdgeId = transInst.Transition.Id; trace.MinorNumber = minorNumber; //TODO wmj2003 这里应该是insert。一旦token从当前边上经过,那么就保存流程运行轨迹. RuntimeContext.PersistenceService.SaveOrUpdateProcessInstanceTrace(trace); } } }
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); }
public virtual void AddEnteringTransitionInstance(ITransitionInstance transitionInstance) { this.EnteringTransitionInstances.Add(transitionInstance); }
public virtual void AddLeavingTransitionInstance(ITransitionInstance transitionInstance) { LeavingTransitionInstances.Add(transitionInstance); }
/// <summary> /// if anyone wants to improve this algorithm, feel welcome! </summary> protected internal virtual bool IsTreeMatched(IActivityInstance expectedInstance, IActivityInstance actualInstance) { if (expectedInstance.ActivityId != actualInstance.ActivityId || (expectedInstance.Id != null && expectedInstance.Id != actualInstance.Id)) { return(false); } else { if (expectedInstance.ChildActivityInstances.Length != actualInstance.ChildActivityInstances.Length) { return(false); } else { IList <IActivityInstance> unmatchedInstances = new List <IActivityInstance>((expectedInstance.ChildActivityInstances)); foreach (IActivityInstance actualChild in actualInstance.ChildActivityInstances) { bool matchFound = false; foreach (IActivityInstance expectedChild in unmatchedInstances) { if (IsTreeMatched(expectedChild, actualChild)) { unmatchedInstances.Remove(actualChild); matchFound = true; break; } } if (!matchFound) { return(false); } } if (expectedInstance.ChildTransitionInstances.Length != actualInstance.ChildTransitionInstances.Length) { return(false); } IList <ITransitionInstance> unmatchedTransitionInstances = new List <ITransitionInstance>((expectedInstance.ChildTransitionInstances)); foreach (ITransitionInstance child in actualInstance.ChildTransitionInstances) { IEnumerator <ITransitionInstance> expectedTransitionInstanceIt = unmatchedTransitionInstances.GetEnumerator(); bool matchFound = false; while (expectedTransitionInstanceIt.MoveNext() && !matchFound) { ITransitionInstance expectedChild = expectedTransitionInstanceIt.Current; if (expectedChild.ActivityId.Equals(child.ActivityId)) { matchFound = true; //JAVA TO C# CONVERTER TODO Resources.Task: .NET enumerators are read-only: //expectedTransitionInstanceIt.Remove(); } } if (!matchFound) { return(false); } } } return(true); } }
/// <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); }
public virtual void HandleTransitionInstance(ITransitionInstance transitionInstance) { Parser.TransitionInstanceHandler.Handle(this, transitionInstance); }