/// <summary> /// 创建下一步活动的节点 /// </summary> /// <param name="activity"></param> /// <returns></returns> internal static NextActivityComponent CreateNextActivityComponent(TransitionEntity transition, ActivityEntity activity) { NextActivityComponent component = null; if (activity.NodeType == NodeTypeEnum.TaskNode || activity.NodeType == NodeTypeEnum.EndNode) { string name = "单一节点"; component = new NextActivityItem(name, transition, activity); } else { string name = string.Empty; if (activity.GatewayDirectionType == Sys.Workflow.Common.GatewayDirectionEnum.AndSplit) { name = "必全选节点"; } else { name = "或多选节点"; } component = new NextActivityGateway(name, transition, activity); } return(component); }
/// <summary> /// 根据Transition,获取下一步节点列表 /// </summary> /// <param name="nextActivityList"></param> /// <param name="processInstanceGUID"></param> /// <param name="currentGatewayActivity"></param> /// <param name="forwardTransition"></param> /// <param name="conditionKeyValuePair"></param> protected NextActivityComponent GetNextActivityListFromGatewayCore(TransitionEntity forwardTransition, IDictionary <string, string> conditionKeyValuePair, out NextActivityMatchedType resultType) { NextActivityComponent child = null; if (forwardTransition.ToActivity.NodeType == NodeTypeEnum.TaskNode || forwardTransition.ToActivity.NodeType == NodeTypeEnum.EndNode) { child = NextActivityComponentFactory.CreateNextActivityComponent(forwardTransition, forwardTransition.ToActivity); resultType = NextActivityMatchedType.Successed; } else if (forwardTransition.ToActivity.NodeType == NodeTypeEnum.GatewayNode) { child = GetNextActivityListFromGateway(forwardTransition, forwardTransition.ToActivity, conditionKeyValuePair, out resultType); } else { resultType = NextActivityMatchedType.Failed; throw new XmlDefinitionException(string.Format("未知的节点类型:{0}", forwardTransition.ToActivity.NodeType.ToString())); } return(child); }
public override void Add(NextActivityComponent nextActivity) { nextActivityList.Add(nextActivity); if (hasChildren == false) { hasChildren = true; } }
/// <summary> /// 获取下一步节点列表,伴随运行时条件信息 /// </summary> /// <param name="currentActivity"></param> /// <param name="conditionKeyValuePair"></param> /// <returns></returns> internal NextActivityMatchedResult GetNextActivityList(ActivityEntity currentActivity, IDictionary <string, string> conditionKeyValuePair = null) { try { NextActivityMatchedResult result = null; NextActivityMatchedType resultType = NextActivityMatchedType.Unknown; //创建“下一步节点”的根节点 NextActivityComponent root = NextActivityComponentFactory.CreateNextActivityComponent(); NextActivityComponent child = null; List <TransitionEntity> transitionList = GetForwardTransitionList(currentActivity.ActivityGUID, conditionKeyValuePair).ToList(); if (transitionList.Count > 0) { //遍历连线,获取下一步节点的列表 foreach (TransitionEntity transition in transitionList) { if (transition.ToActivity.NodeType == NodeTypeEnum.EndNode || transition.ToActivity.NodeType == NodeTypeEnum.TaskNode) { child = NextActivityComponentFactory.CreateNextActivityComponent(transition, transition.ToActivity); } else if (transition.ToActivity.NodeType == NodeTypeEnum.GatewayNode) { NextActivityScheduleBase activitySchedule = NextActivityScheduleFactory.CreateActivitySchedule(this, transition.ToActivity.GatewaySplitJoinType); child = activitySchedule.GetNextActivityListFromGateway(transition, transition.ToActivity, conditionKeyValuePair, out resultType); } else { throw new XmlDefinitionException(string.Format("未知的节点类型:{0}", transition.ToActivity.NodeType.ToString())); } if (child != null) { root.Add(child); resultType = NextActivityMatchedType.Successed; } } } else { resultType = NextActivityMatchedType.NoneTransitionFilteredByCondition; } result = NextActivityMatchedResult.CreateNextActivityMatchedResultObject(resultType, root); return(result); } catch (System.Exception e) { throw new WfXpdlException(string.Format("解析流程定义文件发生异常,异常描述:{0}", e.Message), e); } }
public override bool Remove(NextActivityComponent nextActivity) { bool isRemoved = nextActivityList.Remove(nextActivity); if (nextActivityList.Count == 0) { hasChildren = false; } return(isRemoved); }
/// <summary> /// 获取下一步节点列表,伴随条件信息 /// </summary> /// <param name="currentActivity"></param> /// <param name="conditionKeyValuePair"></param> /// <returns></returns> internal NextActivityMatchedResult GetNextActivityList(Guid ProcessInstanceGUID, ActivityEntity currentActivity, ConditionKeyValuePair conditionKeyValuePair) { NextActivityMatchedResult result = null; NextActivityMatchedType resultType = NextActivityMatchedType.Unknown; //创建“下一步节点”的根节点 NextActivityComponent root = NextActivityComponentFactory.CreateNextActivityComponent(); NextActivityComponent child = null; TransitionManager tm = new TransitionManager(this.ProcessEntity); List <TransitionEntity> transitionList = tm.GetForwardTransitionList(currentActivity.ActivityGUID, conditionKeyValuePair).ToList(); if (transitionList.Count > 0) { //遍历连线,获取下一步节点的列表 foreach (TransitionEntity transition in transitionList) { if (transition.ToActivity.NodeType == NodeTypeEnum.EndNode || transition.ToActivity.NodeType == NodeTypeEnum.TaskNode) { child = NextActivityComponentFactory.CreateNextActivityComponent(transition, transition.ToActivity); } else if (transition.ToActivity.NodeType == NodeTypeEnum.GatewayNode) { NextActivityScheduleBase activitySchedule = NextActivityScheduleFactory.CreateActivitySchedule(this.ProcessEntity, transition.ToActivity.GatewaySplitJoinType); child = activitySchedule.GetNextActivityListFromGateway(ProcessInstanceGUID, transition, transition.ToActivity, conditionKeyValuePair, out resultType); } else { throw new XmlDefinitionException(string.Format("未知的节点类型:{0}", transition.ToActivity.NodeType.ToString())); } if (child != null) { root.Add(child); resultType = NextActivityMatchedType.Successed; } } } else { resultType = NextActivityMatchedType.NoneTransitionFilteredByCondition; } result = NextActivityMatchedResult.CreateNextActivityMatchedResultObject(resultType, root); return(result); }
/// <summary> /// 添加子节点到网关节点 /// </summary> /// <param name="newRoot"></param> /// <param name="root"></param> /// <param name="child"></param> /// <returns></returns> private NextActivityComponent AddChildToNewGatewayComponent(NextActivityComponent newRoot, NextActivityComponent root, NextActivityComponent child) { if ((newRoot == null) && (child != null)) { newRoot = NextActivityComponentFactory.CreateNextActivityComponent(root); } if ((newRoot != null) && (child != null)) { newRoot.Add(child); } return(newRoot); }
/// <summary> /// 把子节点添加到网关路由节点,根据网关节点和子节点是否为空处理 /// </summary> /// <param name="gatewayComponent"></param> /// <param name="child"></param> /// <param name="currentGatewayActivity"></param> /// <returns></returns> protected NextActivityComponent AddChildToGatewayComponent(TransitionEntity fromTransition, ActivityEntity currentGatewayActivity, NextActivityComponent gatewayComponent, NextActivityComponent child) { if ((gatewayComponent == null) && (child != null)) { gatewayComponent = NextActivityComponentFactory.CreateNextActivityComponent(fromTransition, currentGatewayActivity); } if ((gatewayComponent != null) && (child != null)) { gatewayComponent.Add(child); } return(gatewayComponent); }
/// <summary> /// 获取下一步节点列表(伴随条件和资源) /// </summary> /// <param name="currentActivity"></param> /// <param name="conditionKeyValuePair"></param> /// <returns></returns> internal NextActivityMatchedResult GetNextActivityList(ActivityEntity currentActivity, IDictionary <string, string> conditionKeyValuePair, ActivityResource activityResource, Expression <Func <ActivityResource, ActivityEntity, bool> > expression) { NextActivityComponent newRoot = NextActivityComponentFactory.CreateNextActivityComponent(); //先获取未加运行时表达式过滤的下一步节点列表 NextActivityMatchedResult result = GetNextActivityList(currentActivity, conditionKeyValuePair); foreach (NextActivityComponent c in result.Root) { if (c.HasChildren) { NextActivityComponent child = GetNextActivityListByExpressionRecurisivly(c, activityResource, expression); if (child != null) { newRoot.Add(child); } } else { if (expression.Compile().Invoke(activityResource, c.Activity)) { newRoot.Add(c); } } } NextActivityMatchedResult newResult = null; if (newRoot.HasChildren) { newResult = NextActivityMatchedResult.CreateNextActivityMatchedResultObject(result.MatchedType, newRoot); } else { newResult = NextActivityMatchedResult.CreateNextActivityMatchedResultObject(NextActivityMatchedType.NoneTransitionFilteredByCondition, newRoot); } return(newResult); }
/// <summary> /// 迭代遍历 /// </summary> /// <param name="root"></param> /// <param name="treeNodeList"></param> private void Tranverse(NextActivityComponent root, IList <NodeView> treeNodeList) { foreach (var child in root) { if (child.HasChildren) { Tranverse(child, treeNodeList); } else { treeNodeList.Add(new NodeView { ID = child.Activity.ActivityGUID, Text = child.Activity.ActivityName, Roles = child.Activity.Roles }); } } }
/// <summary> /// 递归获取满足条件的下一步节点列表 /// </summary> /// <param name="root"></param> /// <param name="activityResource"></param> /// <param name="expression"></param> /// <returns></returns> private NextActivityComponent GetNextActivityListByExpressionRecurisivly(NextActivityComponent root, ActivityResource activityResource, Expression <Func <ActivityResource, ActivityEntity, bool> > expression) { NextActivityComponent r1 = null; foreach (NextActivityComponent c in root) { if (c.HasChildren) { NextActivityComponent child = GetNextActivityListByExpressionRecurisivly(c, activityResource, expression); r1 = AddChildToNewGatewayComponent(r1, c, child); } else { if (expression.Compile().Invoke(activityResource, c.Activity)) { r1 = AddChildToNewGatewayComponent(r1, root, c); } } } return(r1); }
/// <summary> /// 获取下一步节点列表 /// </summary> /// <param name="processInstanceGUID"></param> /// <param name="fromTransition"></param> /// <param name="currentGatewayActivity"></param> /// <param name="conditionKeyValuePair"></param> /// <returns></returns> internal override NextActivityComponent GetNextActivityListFromGateway(TransitionEntity fromTransition, ActivityEntity currentGatewayActivity, IDictionary <string, string> conditionKeyValuePair, out NextActivityMatchedType resultType) { NextActivityComponent child = null; NextActivityComponent gatewayComponent = null; resultType = NextActivityMatchedType.Unknown; //直接取出下步列表,运行时再根据条件执行 List <TransitionEntity> transitionList = base.ProcessModel.GetForwardTransitionList(currentGatewayActivity.ActivityGUID).ToList(); foreach (TransitionEntity transition in transitionList) { child = GetNextActivityListFromGatewayCore(transition, conditionKeyValuePair, out resultType); gatewayComponent = AddChildToGatewayComponent(fromTransition, currentGatewayActivity, gatewayComponent, child); } return(gatewayComponent); }
public virtual bool Remove(NextActivityComponent nextActivity) { throw new InvalidOperationException("非组合节点,无子项可以删除!"); }
public virtual void Add(NextActivityComponent nextActivity) { throw new InvalidOperationException("非组合节点,不能添加子项!"); }
private NextActivityMatchedResult(NextActivityMatchedType matchedType, NextActivityComponent root) { MatchedType = matchedType; Root = root; }
/// <summary> /// 创建方法 /// </summary> /// <param name="scheduleStatus"></param> /// <param name="root"></param> /// <returns></returns> internal static NextActivityMatchedResult CreateNextActivityMatchedResultObject(NextActivityMatchedType matchedType, NextActivityComponent root) { NextActivityMatchedResult result = new NextActivityMatchedResult(matchedType, root); switch (matchedType) { case NextActivityMatchedType.Unknown: result.Message = NextActivityMatchedResult.Unkonwn; break; case NextActivityMatchedType.Failed: result.Message = NextActivityMatchedResult.Exceptional; break; case NextActivityMatchedType.Successed: result.Message = NextActivityMatchedResult.Successed; break; case NextActivityMatchedType.NoneTransitionFilteredByCondition: result.Message = NextActivityMatchedResult.NoneTransitionFilteredByCondition; break; case NextActivityMatchedType.WaitingForSplitting: result.Message = NextActivityMatchedResult.NoneTransitionAsBeingFiltered; break; case NextActivityMatchedType.NoneTransitionMatchedToSplit: result.Message = NextActivityMatchedResult.NoneWayMatchedToSplit; break; case NextActivityMatchedType.WaitingForOthersJoin: result.Message = NextActivityMatchedResult.WaitingForOthersJoin; break; case NextActivityMatchedType.NotMadeItselfToJoin: result.Message = NextActivityMatchedResult.NotMadeItselfToJoin; break; } return(result); }
/// <summary> /// 根据现有下一步节点列表,创建新的下一步节点列表对象 /// </summary> /// <param name="c"></param> /// <returns></returns> internal static NextActivityComponent CreateNextActivityComponent(NextActivityComponent c) { NextActivityComponent newComp = CreateNextActivityComponent(c.Transition, c.Activity); return(newComp); }
/// <summary> /// 获取下一步节点列表 /// </summary> /// <param name="processInstanceGUID"></param> /// <param name="fromTransition"></param> /// <param name="currentGatewayActivity"></param> /// <param name="conditionKeyValuePair"></param> /// <returns></returns> internal override NextActivityComponent GetNextActivityListFromGateway(TransitionEntity fromTransition, ActivityEntity currentGatewayActivity, IDictionary <string, string> conditionKeyValuePair, out NextActivityMatchedType resultType) { NextActivityComponent child = null; NextActivityComponent gatewayComponent = null; resultType = NextActivityMatchedType.Unknown; var transitionList = this.ProcessModel.GetForwardTransitionList(currentGatewayActivity.ActivityGUID).ToList(); if (currentGatewayActivity.GatewayDirectionType == GatewayDirectionEnum.AndSplit) { //判读连线上的条件是否都满足,如果都满足才可以取出后续节点列表 bool isCheckedOk = base.ProcessModel.CheckAndSplitOccurrenceCondition(transitionList, conditionKeyValuePair); if (isCheckedOk) { //获取AndSplit的每一条后续连线上的To节点 foreach (TransitionEntity transition in transitionList) { child = GetNextActivityListFromGatewayCore(transition, conditionKeyValuePair, out resultType); gatewayComponent = AddChildToGatewayComponent(fromTransition, currentGatewayActivity, gatewayComponent, child); } } if (gatewayComponent == null) { resultType = NextActivityMatchedType.WaitingForSplitting; } } else if (currentGatewayActivity.GatewayDirectionType == GatewayDirectionEnum.OrSplit) { //获取OrSplit的,满足条件的后续连线上的To节点 foreach (TransitionEntity transition in transitionList) { bool isValidTransition = base.ProcessModel.IsValidTransition(transition, conditionKeyValuePair); if (isValidTransition) { child = GetNextActivityListFromGatewayCore(transition, conditionKeyValuePair, out resultType); gatewayComponent = AddChildToGatewayComponent(fromTransition, currentGatewayActivity, gatewayComponent, child); } if (gatewayComponent == null) { resultType = NextActivityMatchedType.NoneTransitionMatchedToSplit; } } } else if (currentGatewayActivity.GatewayDirectionType == GatewayDirectionEnum.XOrSplit) { //按连线定义的优先级排序 transitionList.Sort(new TransitionPriorityCompare()); //获取XOrSplit的,第一条满足条件的后续连线上的To节点 foreach (TransitionEntity transition in transitionList) { bool isValidTransitionXOr = base.ProcessModel.IsValidTransition(transition, conditionKeyValuePair); if (isValidTransitionXOr) { child = GetNextActivityListFromGatewayCore(transition, conditionKeyValuePair, out resultType); gatewayComponent = AddChildToGatewayComponent(fromTransition, currentGatewayActivity, gatewayComponent, child); //退出循环 break; } } if (gatewayComponent == null) { resultType = NextActivityMatchedType.NoneTransitionMatchedToSplit; } } else if (currentGatewayActivity.GatewayDirectionType == GatewayDirectionEnum.ComplexSplit) { resultType = NextActivityMatchedType.Failed; throw new Exception("ComplexSplit 没有具体实现!"); } else { resultType = NextActivityMatchedType.Failed; throw new Exception("Split 分支节点的类型不明确!"); } return(gatewayComponent); }