/// <summary> /// 创建下一步活动的节点 /// </summary> /// <param name="activity"></param> /// <returns></returns> internal static NextActivityComponent CreateNextActivityComponent(TransitionEntity transition, ActivityEntity activity) { NextActivityComponent component = null; if (XPDLHelper.IsSimpleComponentNode(activity.ActivityType) == true) //可流转简单类型节点 { string name = "单一节点"; component = new NextActivityItem(name, transition, activity); } else if (activity.ActivityType == ActivityTypeEnum.SubProcessNode) { string name = "子流程节点"; component = new NextActivityItem(name, transition, activity); } else { string name = string.Empty; if (activity.GatewayDirectionType == Slickflow.Engine.Common.GatewayDirectionEnum.AndSplit) { name = "必全选节点"; } else if (activity.GatewayDirectionType == GatewayDirectionEnum.AndSplitMI) { name = "并行多实例节点"; } else { name = "或多选节点"; } component = new NextActivityGateway(name, transition, activity); } return(component); }
/// <summary> /// 根据Transition,获取下一步节点列表 /// </summary> /// <param name="forwardTransition">转移实体</param> /// <param name="conditionKeyValuePair">条件kv对</param> /// <param name="resultType">结果类型</param> protected NextActivityComponent GetNextActivityListFromGatewayCore(TransitionEntity forwardTransition, IDictionary <string, string> conditionKeyValuePair, out NextActivityMatchedType resultType) { NextActivityComponent child = null; if (XPDLHelper.IsSimpleComponentNode(forwardTransition.ToActivity.ActivityType) == true) //可流转简单类型节点 { child = NextActivityComponentFactory.CreateNextActivityComponent(forwardTransition, forwardTransition.ToActivity); resultType = NextActivityMatchedType.Successed; } else if (forwardTransition.ToActivity.ActivityType == ActivityTypeEnum.GatewayNode) { child = GetNextActivityListFromGateway(forwardTransition, forwardTransition.ToActivity, conditionKeyValuePair, out resultType); } else { resultType = NextActivityMatchedType.Failed; throw new XmlDefinitionException(string.Format("未知的节点类型:{0}", forwardTransition.ToActivity.ActivityType.ToString())); } return(child); }
/// <summary> /// 退回操作 /// </summary> /// <param name="runner">执行者</param> /// <param name="result">结果对象</param> /// <returns>运行时实例对象</returns> internal static WfRuntimeManager CreateRuntimeInstanceSendBack(WfAppRunner runner, ref WfExecutedResult result) { WfRuntimeManager rmins = new WfRuntimeManagerSendBack(); rmins.WfExecutedResult = result = new WfExecutedResult(); var aim = new ActivityInstanceManager(); var runningActivityInstanceList = aim.GetRunningActivityInstanceList(runner.AppInstanceID, runner.ProcessGUID).ToList(); SendbackOpertaionTypeEnum sendbackOperation = SendbackOpertaionTypeEnum.Default; //当前没有运行状态的节点存在,流程不存在,或者已经结束或取消 if (runningActivityInstanceList == null || runningActivityInstanceList.Count() == 0) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotInRunning; result.Message = "当前没有运行状态的节点存在,流程不存在,或者已经结束或取消"; return(rmins); } if (runningActivityInstanceList.Count() == 1) //如果只有1个运行节点 { var runningNode = runningActivityInstanceList[0]; var activityType = EnumHelper.ParseEnum <ActivityTypeEnum>(runningNode.ActivityType.ToString()); if (XPDLHelper.IsSimpleComponentNode(activityType) == false) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotTaskNode; result.Message = "当前节点不是任务类型的节点,无法退回上一步节点!"; return(rmins); } if (aim.IsMineTask(runningNode, runner.UserID) == false) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotMineTask; result.Message = "不是登录用户的任务,无法退回!"; return(rmins); } sendbackOperation = SendbackOpertaionTypeEnum.Normal; } else if (runningActivityInstanceList.Count() > 1) { //有其它非多实例的并行节点,暂时不处理,后期实现该功能 result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NullOrHasTooMany; result.Message = "有多个可以退回的节点,而且不是多实例节点,此功能暂时不支持!"; return(rmins); } //根据不同分支场景,创建不同撤销运行时管理器 return(CreateRuntimeInstanceSendbackByCase(runningActivityInstanceList, sendbackOperation, runner, ref result)); }
/// <summary> /// 创建下一步活动的节点 /// </summary> /// <param name="transition">转移</param> /// <param name="activity">活动</param> /// <returns>下一步节点封装</returns> internal static NextActivityComponent CreateNextActivityComponent(TransitionEntity transition, ActivityEntity activity) { string name = string.Empty; NextActivityComponent component = null; if (XPDLHelper.IsSimpleComponentNode(activity.ActivityType) == true) //可流转简单类型节点 { name = "单一节点"; component = new NextActivityItem(name, transition, activity); } else if (XPDLHelper.IsIntermediateEventComponentNode(activity.ActivityType) == true) { name = "跨事件节点"; component = new NextActivityIntermediate(name, transition, activity); } else if (XPDLHelper.IsGatewayComponentNode(activity.ActivityType) == true) { if (activity.GatewayDirectionType == GatewayDirectionEnum.AndSplit) { name = "必全选节点"; component = new NextActivityGateway(name, transition, activity); } else if (activity.GatewayDirectionType == GatewayDirectionEnum.AndSplitMI) { name = "并行多实例节点"; component = new NextActivityGateway(name, transition, activity); } else if (activity.GatewayDirectionType == GatewayDirectionEnum.OrSplit || activity.GatewayDirectionType == GatewayDirectionEnum.OrSplitMI || activity.GatewayDirectionType == GatewayDirectionEnum.XOrSplit) { name = "或多选节点"; component = new NextActivityGateway(name, transition, activity); } else { throw new WfXpdlException(string.Format("无法创建下一步节点列表,不明确的分支类型:{0}", activity.GatewayDirectionType.ToString())); } } else if (activity.ActivityType == ActivityTypeEnum.SubProcessNode) { name = "子流程节点"; component = new NextActivityItem(name, transition, activity); } else { throw new WfXpdlException(string.Format("无法创建下一步节点列表,不明确的节点类型:{0}", activity.ActivityType.ToString())); } return(component); }
/// <summary> /// 根据Transition,获取下一步节点列表 /// </summary> /// <param name="forwardTransition">转移实体</param> /// <param name="conditionKeyValuePair">条件kv对</param> /// <param name="session">会话</param> /// <param name="resultType">结果类型</param> protected NextActivityComponent GetNextActivityListFromGatewayCore(TransitionEntity forwardTransition, IDictionary <string, string> conditionKeyValuePair, IDbSession session, out NextActivityMatchedType resultType) { NextActivityComponent child = null; if (XPDLHelper.IsSimpleComponentNode(forwardTransition.ToActivity.ActivityType) == true) //可流转简单类型节点 { child = NextActivityComponentFactory.CreateNextActivityComponent(forwardTransition, forwardTransition.ToActivity); resultType = NextActivityMatchedType.Successed; } else if (forwardTransition.ToActivity.ActivityType == ActivityTypeEnum.GatewayNode) { child = GetNextActivityListFromGateway(forwardTransition, forwardTransition.ToActivity, conditionKeyValuePair, session, out resultType); } else if (forwardTransition.ToActivity.ActivityType == ActivityTypeEnum.IntermediateNode) { if (forwardTransition.ToActivity.ActivityTypeDetail.TriggerType == TriggerTypeEnum.Timer) { child = NextActivityComponentFactory.CreateNextActivityComponent(forwardTransition, forwardTransition.ToActivity); resultType = NextActivityMatchedType.Successed; } else { NextActivityScheduleBase activitySchedule = NextActivityScheduleFactory.CreateActivityScheduleIntermediate(this.ProcessModel); child = activitySchedule.GetNextActivityListFromGateway(forwardTransition, forwardTransition.ToActivity, conditionKeyValuePair, session, out resultType); } } else if (forwardTransition.ToActivity.ActivityType == ActivityTypeEnum.ServiceNode) { NextActivityScheduleBase activitySchedule = NextActivityScheduleFactory.CreateActivityScheduleIntermediate(this.ProcessModel); child = activitySchedule.GetNextActivityListFromGateway(forwardTransition, forwardTransition.ToActivity, conditionKeyValuePair, session, out resultType); } else { resultType = NextActivityMatchedType.Failed; throw new XmlDefinitionException(LocalizeHelper.GetEngineMessage("nextactivityschedulebase.unknownnodetype", forwardTransition.ToActivity.ActivityType.ToString())); } return(child); }
/// <summary> /// 创建跳转节点(强制拉取跳转方式,后续节点状态可以强制拉取前置节点到当前节点[后续节点]) /// </summary> /// <param name="fromActivity">要拉取的节点</param> /// <param name="toActivity">拉取到节点</param> /// <returns></returns> internal static NextActivityComponent CreateNextActivityComponent(ActivityEntity fromActivity, ActivityEntity toActivity) { NextActivityComponent component = null; if (XPDLHelper.IsSimpleComponentNode(fromActivity.ActivityType) == true) //可流转简单类型节点 { string name = "单一节点"; var transition = TransitionBuilder.CreateJumpforwardEmptyTransition(fromActivity, toActivity); component = new NextActivityItem(name, transition, fromActivity); //强制拉取跳转类型的transition 为空类型 } else { throw new ApplicationException(string.Format("不能跳转到其它非任务类型的节点!当前节点:{0}", fromActivity.ActivityType)); } return(component); }
/// <summary> /// 创建跳转节点(强制拉取跳转方式,后续节点状态可以强制拉取前置节点到当前节点[后续节点]) /// </summary> /// <param name="fromActivity">要拉取的节点</param> /// <param name="toActivity">拉取到节点</param> /// <returns>下一步节点封装</returns> internal static NextActivityComponent CreateNextActivityComponent(ActivityEntity fromActivity, ActivityEntity toActivity) { NextActivityComponent component = null; if (XPDLHelper.IsSimpleComponentNode(fromActivity.ActivityType) == true) //可流转简单类型节点 { //单一节点 string name = LocalizeHelper.GetEngineMessage("nextactivitycomponentfactory.singlenode");; var transition = CreateJumpforwardEmptyTransition(fromActivity, toActivity); component = new NextActivityItem(name, transition, toActivity); //强制拉取跳转类型的transition 为空类型 } else { throw new ApplicationException(LocalizeHelper.GetEngineMessage("nextactivitycomponentfactory.CreateNextActivityComponent.jump.error", fromActivity.ActivityType.ToString())); } return(component); }
/// <summary> /// 获取网关节点前的节点 /// </summary> /// <param name="transitionList">转移列表</param> /// <param name="toActivityInstanceID">流转到的活动实例ID</param> /// <param name="previousActivityInstanceList">前节点实例列表</param> private void GetPreviousOfGatewayActivityInstance(IList <TransitionInstanceEntity> transitionList, int toActivityInstanceID, IList <ActivityInstanceEntity> previousActivityInstanceList) { var previousTransitionList = transitionList .Where(o => o.ToActivityInstanceID == toActivityInstanceID) .ToList(); var aim = new ActivityInstanceManager(); foreach (var entity in previousTransitionList) { var activityType = EnumHelper.ParseEnum <ActivityTypeEnum>(entity.FromActivityType.ToString()); if (XPDLHelper.IsSimpleComponentNode(activityType) == true) { previousActivityInstanceList.Add(aim.GetById(entity.FromActivityInstanceID)); } else if (entity.FromActivityType == (short)ActivityTypeEnum.GatewayNode) { GetPreviousOfGatewayActivityInstance(transitionList, entity.FromActivityInstanceID, previousActivityInstanceList); } } }
/// <summary> /// 创建下一步活动的节点 /// </summary> /// <param name="transition">转移</param> /// <param name="activity">活动</param> /// <returns>下一步节点封装</returns> internal static NextActivityComponent CreateNextActivityComponent(TransitionEntity transition, ActivityEntity activity) { string name = string.Empty; NextActivityComponent component = null; if (XPDLHelper.IsSimpleComponentNode(activity.ActivityType) == true) //可流转简单类型节点 { //单一节点 name = LocalizeHelper.GetEngineMessage("nextactivitycomponentfactory.singlenode"); component = new NextActivityItem(name, transition, activity); } else if (XPDLHelper.IsIntermediateEventComponentNode(activity.ActivityType) == true) { //跨事件节点 name = LocalizeHelper.GetEngineMessage("nextactivitycomponentfactory.intermediatenode"); component = new NextActivityIntermediate(name, transition, activity); } else if (XPDLHelper.IsGatewayComponentNode(activity.ActivityType) == true) { if (activity.GatewayDirectionType == GatewayDirectionEnum.AndSplit || activity.GatewayDirectionType == GatewayDirectionEnum.AndJoin) { //必全选节点 name = LocalizeHelper.GetEngineMessage("nextactivitycomponentfactory.mandatorycheckall"); } else if (activity.GatewayDirectionType == GatewayDirectionEnum.AndSplitMI || activity.GatewayDirectionType == GatewayDirectionEnum.AndJoinMI) { //并行多实例节点 name = LocalizeHelper.GetEngineMessage("nextactivitycomponentfactory.parallelmultipleinstance"); } else if (activity.GatewayDirectionType == GatewayDirectionEnum.OrSplit || activity.GatewayDirectionType == GatewayDirectionEnum.OrJoin) { //或多选节点 name = LocalizeHelper.GetEngineMessage("nextactivitycomponentfactory.orsplitorjoin"); } else if (activity.GatewayDirectionType == GatewayDirectionEnum.XOrSplit || activity.GatewayDirectionType == GatewayDirectionEnum.XOrJoin) { //异或节点 name = LocalizeHelper.GetEngineMessage("nextactivitycomponentfactory.xor"); } else if (activity.GatewayDirectionType == GatewayDirectionEnum.EOrJoin) { //增强合并多选节点 name = LocalizeHelper.GetEngineMessage("nextactivitycomponentfactory.eorjoin"); } else { throw new WfXpdlException(LocalizeHelper.GetEngineMessage("nextactivitycomponentfactory.CreateNextActivityComponent.gateway.error", activity.GatewayDirectionType.ToString())); } component = new NextActivityGateway(name, transition, activity); } else if (activity.ActivityType == ActivityTypeEnum.SubProcessNode) { //子流程节点 name = LocalizeHelper.GetEngineMessage("nextactivitycomponentfactory.subprocess"); component = new NextActivityItem(name, transition, activity); } else { throw new WfXpdlException(LocalizeHelper.GetEngineMessage("nextactivitycomponentfactory.CreateNextActivityComponent.error", activity.ActivityType.ToString())); } return(component); }
/// <summary> /// 退回操作 /// </summary> /// <param name="runner">执行者</param> /// <param name="result">结果对象</param> /// <returns>运行时实例对象</returns> internal static WfRuntimeManager CreateRuntimeInstanceSendBack(WfAppRunner runner, ref WfExecutedResult result) { WfRuntimeManager rmins = new WfRuntimeManagerSendBack(); rmins.WfExecutedResult = result = new WfExecutedResult(); var aim = new ActivityInstanceManager(); var runningActivityInstanceList = aim.GetRunningActivityInstanceList(runner.AppInstanceID, runner.ProcessGUID).ToList(); SendbackOperationTypeEnum sendbackOperation = SendbackOperationTypeEnum.Default; //当前没有运行状态的节点存在,流程不存在,或者已经结束或取消 if (runningActivityInstanceList == null || runningActivityInstanceList.Count() == 0) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotInRunning; result.Message = "当前没有运行状态的节点存在,流程不存在,或者已经结束或取消"; return(rmins); } if (runningActivityInstanceList.Count() == 1) //如果只有1个运行节点 { var runningNode = runningActivityInstanceList[0]; var activityType = EnumHelper.ParseEnum <ActivityTypeEnum>(runningNode.ActivityType.ToString()); if (XPDLHelper.IsSimpleComponentNode(activityType) == false) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotTaskNode; result.Message = "当前节点不是任务类型的节点,无法退回上一步节点!"; return(rmins); } if (aim.IsMineTask(runningNode, runner.UserID) == false) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotMineTask; result.Message = "不是登录用户的任务,无法退回!"; return(rmins); } //判断当前节点是否是多实例节点 if (runningNode.MIHostActivityInstanceID != null) { if (runningNode.CompleteOrder == 1) { //只有串行模式下有CompleteOrder的值为 1 //串行模式多实例的第一个执行节点,此时可退回到上一步 sendbackOperation = SendbackOperationTypeEnum.MISFirstOneIsRunning; } else if (runningNode.CompleteOrder > 1) { //已经是中间节点,只能退回到上一步多实例子节点 sendbackOperation = SendbackOperationTypeEnum.MISOneIsRunning; } else if (runningNode.CompleteOrder == -1) { sendbackOperation = SendbackOperationTypeEnum.MIPOneIsRunning; } } else { sendbackOperation = SendbackOperationTypeEnum.Normal; } } else if (runningActivityInstanceList.Count() > 1) { var firstActivityInstance = runningActivityInstanceList[0]; if (firstActivityInstance.MIHostActivityInstanceID != null) { //判断多实例主节点下的子节点是否都处于待办状态,如果是,则可以退回到上一步 bool isAllInReadyState = true; var allChildNodeList = aim.GetActivityMultipleInstance(firstActivityInstance.MIHostActivityInstanceID.Value, firstActivityInstance.ProcessInstanceID); int runningCount = 0; foreach (var ai in allChildNodeList) { if (ai.ActivityState != (short)ActivityStateEnum.Ready && ai.ActivityState != (short)ActivityStateEnum.Suspended) { if (ai.ActivityState == (short)ActivityStateEnum.Running) { runningCount++; } else { isAllInReadyState = false; break; } } } if (runningCount > 1) { isAllInReadyState = false; } if (isAllInReadyState == false) { //部分子节点有完成的 sendbackOperation = SendbackOperationTypeEnum.MIPSeveralIsRunning; } else if (runningCount == 1) { if (firstActivityInstance.CompleteOrder == -1) { sendbackOperation = SendbackOperationTypeEnum.MIPOneIsRunning; } else { //第一个子节点处于待办状态 sendbackOperation = SendbackOperationTypeEnum.MISFirstOneIsRunning; } } else if (isAllInReadyState) { //子节点全部处于待办状态 sendbackOperation = SendbackOperationTypeEnum.MIPAllIsInReadyState; } } else { //有其它非多实例的并行节点,暂时不处理,后期实现该功能 result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NullOrHasTooMany; result.Message = "有多个可以退回的节点,而且不是多实例节点,此功能暂时不支持!"; return(rmins); } } //根据不同分支场景,创建不同撤销运行时管理器 return(CreateRuntimeInstanceSendbackByCase(runningActivityInstanceList, sendbackOperation, runner, ref result)); }
/// <summary> /// 退回操作 /// </summary> /// <param name="runner">执行者</param> /// <param name="result">结果对象</param> /// <returns>运行时实例对象</returns> internal static WfRuntimeManager CreateRuntimeInstanceSendBack(WfAppRunner runner, ref WfExecutedResult result) { var rmins = new WfRuntimeManagerSendBack(); rmins.WfExecutedResult = result = new WfExecutedResult(); var sendbackOperation = SendbackOperationTypeEnum.Default; //先查找当前用户正在办理的运行节点 var aim = new ActivityInstanceManager(); var runningNode = runner.TaskID != null?aim.GetByTask(runner.TaskID.Value) : aim.GetRunningNode(runner); if (runningNode == null) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotInRunning; result.Message = "当前没有运行状态的节点存在,流程不存在,或者已经结束或取消"; return(rmins); } if (aim.IsMineTask(runningNode, runner.UserID) == false) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotMineTask; result.Message = "不是当前登录用户的任务,无法退回!"; return(rmins); } var activityType = EnumHelper.ParseEnum <ActivityTypeEnum>(runningNode.ActivityType.ToString()); if (XPDLHelper.IsSimpleComponentNode(activityType) == false) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotTaskNode; result.Message = "当前节点不是任务类型的节点,无法退回上一步节点!"; return(rmins); } //获取当前运行主节点信息 var currentNode = runningNode; if (runningNode.MIHostActivityInstanceID != null) { currentNode = aim.GetById(runningNode.MIHostActivityInstanceID.Value); } //获取上一步流转节点信息,可能经过And, Or等路由节点 //判断前置步骤是否经过Gateway节点 var hasGatewayPassed = false; var processInstance = (new ProcessInstanceManager()).GetById(runningNode.ProcessInstanceID); var processModel = ProcessModelFactory.Create(processInstance.ProcessGUID, processInstance.Version); var previousActivityList = aim.GetPreviousActivityList(runningNode, processModel, out hasGatewayPassed); if (previousActivityList == null || previousActivityList.Count == 0) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_IsNull; result.Message = "当前没有可以退回的节点,请检查流程数据!"; return(null); } //多个退回节点存在的有效退回判断 IList <ActivityEntity> sendbackPreviousActivityList = new List <ActivityEntity>(); if (previousActivityList.Count > 1) { if (runner.NextActivityPerformers == null || runner.NextActivityPerformers.Count == 0) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_IsTooManyPrevious; result.Message = "当前有多个可以退回的节点,无法选择,请明确指定!"; return(rmins); } //明确指定的退回节点,需要判断处理 var isInvalidSendBack = IsInvalidStepsInPrevousActivityList(previousActivityList, runner.NextActivityPerformers, sendbackPreviousActivityList); if (isInvalidSendBack == true) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotContainedInPreviousOrStartNode; result.Message = "指定的退回节点不在上一步节点运行列表中,或者上一步是开始节点,无法退回!"; return(rmins); } } else { //只有一个要退回去的节点 sendbackPreviousActivityList.Add(previousActivityList[0]); } //判断当前节点是否是多实例节点 if (runningNode.MIHostActivityInstanceID != null) { if (runningNode.CompleteOrder == 1) { //只有串行模式下有CompleteOrder的值为 1 //串行模式多实例的第一个执行节点,此时可退回到上一步 sendbackOperation = SendbackOperationTypeEnum.MISFirstOneIsRunning; } else if (runningNode.CompleteOrder > 1) { //已经是中间节点,只能退回到上一步多实例子节点 sendbackOperation = SendbackOperationTypeEnum.MISOneIsRunning; } else if (runningNode.CompleteOrder == -1) { sendbackOperation = SendbackOperationTypeEnum.MIPOneIsRunning; } } if (hasGatewayPassed == true) { sendbackOperation = SendbackOperationTypeEnum.GatewayFollowedByParalleledNodes; } else { sendbackOperation = SendbackOperationTypeEnum.Normal; } //根据不同分支场景,创建不同撤销运行时管理器 return(CreateRuntimeInstanceSendbackByCase(runningNode, processModel, processInstance, sendbackPreviousActivityList, hasGatewayPassed, sendbackOperation, runner, ref result)); }
/// <summary> /// 创建撤销处理运行时 /// </summary> /// <param name="runner">撤销人</param> /// <param name="result">创建结果</param> /// <returns>运行时管理器</returns> internal static WfRuntimeManager CreateRuntimeInstanceWithdraw(WfAppRunner runner, ref WfExecutedResult result) { var rmins = new WfRuntimeManagerSendBack(); rmins.WfExecutedResult = result = new WfExecutedResult(); if (runner.TaskID == null) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Withdraw_ErrorArguments; result.Message = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceWithdraw.missingtaskid.error"); return(rmins); } //获取已经完成任务的信息 var tm = new TaskManager(); var taskDone = tm.GetTaskView(runner.TaskID.Value); if (tm.IsMine(taskDone, runner.UserID) == false) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotMineTask; result.Message = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceWithdraw.nonetask.error"); return(rmins); } //赋值下一步办理列表 runner.NextActivityPerformers = NextStepUtility.CreateNextStepPerformerList(taskDone.ActivityGUID, taskDone.AssignedToUserID, taskDone.AssignedToUserName); //没有指定退回节点信息 if (runner.NextActivityPerformers == null || runner.NextActivityPerformers.Count == 0) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_IsNull; result.Message = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceWithdraw.noneperformer.error"); return(rmins); } //获取待办任务 var tim = new TransitionInstanceManager(); var nextStepList = tim.GetTargetActivityInstanceList(taskDone.ActivityInstanceID).ToList(); ActivityInstanceEntity runningNode = nextStepList.Count > 0 ? nextStepList[0] : null; if (runningNode == null) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotInRunning; result.Message = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceWithdraw.nonerun.error"); return(rmins); } var activityType = EnumHelper.ParseEnum <ActivityTypeEnum>(runningNode.ActivityType.ToString()); if (XPDLHelper.IsSimpleComponentNode(activityType) == false) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotTaskNode; result.Message = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceWithdraw.nottask.error"); return(rmins); } //获取待办任务(模拟待办任务用户做退回处理) var taskToDo = tm.GetTaskViewByActivity(runningNode.ProcessInstanceID, runningNode.ID); runner.UserID = taskToDo.AssignedToUserID; runner.UserName = taskToDo.AssignedToUserName; //获取上一步节点信息 var hasGatewayPassed = false; var processInstance = (new ProcessInstanceManager()).GetById(runningNode.ProcessInstanceID); var previousStepChecker = new PreviousStepChecker(); var processModel = ProcessModelFactory.Create(taskToDo.ProcessGUID, taskToDo.Version); var previousActivityList = previousStepChecker.GetPreviousActivityList(runningNode, processModel, out hasGatewayPassed); //判断退回是否有效 if (previousActivityList == null || previousActivityList.Count == 0) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_IsNull; result.Message = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceWithdraw.empty.error"); return(rmins); } //检查节点是否一致 if (previousActivityList.Count == 1) { var onlyActivityGUID = previousActivityList[0].ActivityGUID; var isOnly = true; foreach (var step in runner.NextActivityPerformers) { if (step.Key != onlyActivityGUID) { isOnly = false; break; } } //存在不一致的退回节点 if (isOnly == false) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_IsTooManyPrevious; result.Message = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceWithdraw.notunique.error"); return(rmins); } } //创建运行时 rmins.TaskView = taskToDo; rmins.RunningActivityInstance = runningNode; rmins.ProcessInstanceID = runningNode.ProcessInstanceID; rmins.ProcessInstance = processInstance; rmins.ProcessModel = processModel; rmins.AppRunner.AppName = runner.AppName; rmins.AppRunner.AppInstanceID = runner.AppInstanceID; rmins.AppRunner.UserID = runner.UserID; rmins.AppRunner.UserName = runner.UserName; rmins.AppRunner.NextActivityPerformers = runner.NextActivityPerformers; //设置退回选项类 var sendbackOperation = new SendBackOperation(); sendbackOperation.BackwardType = BackwardTypeEnum.Withdrawed; sendbackOperation.ProcessInstance = processInstance; sendbackOperation.BackwardFromActivityInstance = runningNode; sendbackOperation.HasGatewayPassed = hasGatewayPassed; sendbackOperation.ActivityResource = new ActivityResource(runner, rmins.AppRunner.NextActivityPerformers); sendbackOperation.ProcessModel = processModel; sendbackOperation.IsCancellingBrothersNode = true; //撤销时默认撤销各个并行分支 rmins.SendBackOperation = sendbackOperation; return(rmins); }
/// <summary> /// 退回操作 /// </summary> /// <param name="runner">执行者</param> /// <param name="result">结果对象</param> /// <returns>运行时实例对象</returns> internal static WfRuntimeManager CreateRuntimeInstanceSendBack(WfAppRunner runner, ref WfExecutedResult result) { var rmins = new WfRuntimeManagerSendBack(); rmins.WfExecutedResult = result = new WfExecutedResult(); //没有指定退回节点信息 if (runner.NextPerformerType != NextPerformerIntTypeEnum.Traced && (runner.NextActivityPerformers == null || runner.NextActivityPerformers.Count == 0)) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_IsNull; result.Message = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceSendBack.null.error"); return(rmins); } //先查找当前用户正在办理的运行节点 var aim = new ActivityInstanceManager(); TaskViewEntity taskView = null; var runningNode = aim.GetRunningNode(runner, out taskView); if (runningNode == null) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotInRunning; result.Message = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceSendBack.nonerun.error"); return(rmins); } if (aim.IsMineTask(runningNode, runner.UserID) == false) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotMineTask; result.Message = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceSendBack.nonetask.error"); return(rmins); } var activityType = EnumHelper.ParseEnum <ActivityTypeEnum>(runningNode.ActivityType.ToString()); if (XPDLHelper.IsSimpleComponentNode(activityType) == false) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotTaskNode; result.Message = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceSendBack.nottask.error"); return(rmins); } //获取上一步节点信息 var hasGatewayPassed = false; var processInstance = (new ProcessInstanceManager()).GetById(runningNode.ProcessInstanceID); var processModel = ProcessModelFactory.Create(processInstance.ProcessGUID, processInstance.Version); var previousStepChecker = new PreviousStepChecker(); var previousActivityList = previousStepChecker.GetPreviousActivityList(runningNode, processModel, out hasGatewayPassed); //判断退回是否有效 if (previousActivityList == null || previousActivityList.Count == 0) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_IsNull; result.Message = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceSendBack.empty.error"); return(rmins); } //前端用户指定退回步骤的模式 if (runner.NextPerformerType != NextPerformerIntTypeEnum.Traced) { if (runner.NextActivityPerformers == null || runner.NextActivityPerformers.Count == 0) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_IsNull; result.Message = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceSendBack.noneperformer.error"); return(rmins); } //检查节点是否一致 if (previousActivityList.Count == 1) { var onlyActivityGUID = previousActivityList[0].ActivityGUID; var isOnly = true; foreach (var step in runner.NextActivityPerformers) { if (step.Key != onlyActivityGUID) { isOnly = false; break; } } //存在不一致的退回节点 if (isOnly == false) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_IsTooManyPrevious; result.Message = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceSendBack.notunique.error"); return(rmins); } } } else { //Traced 用于直接返回上一步使用,测试模式 var prevActivity = previousActivityList[0]; var performerList = PerformerBuilder.CreatePerformerList(runningNode.CreatedByUserID, runningNode.CreatedByUserName); runner.NextActivityPerformers = ActivityResource.CreateNextActivityPerformers(prevActivity.ActivityGUID, performerList); } //创建运行时 rmins.TaskView = taskView; rmins.RunningActivityInstance = runningNode; rmins.ProcessInstanceID = runningNode.ProcessInstanceID; rmins.ProcessInstance = processInstance; rmins.ProcessModel = processModel; rmins.AppRunner.AppName = runner.AppName; rmins.AppRunner.AppInstanceID = runner.AppInstanceID; rmins.AppRunner.UserID = runner.UserID; rmins.AppRunner.UserName = runner.UserName; rmins.AppRunner.NextActivityPerformers = runner.NextActivityPerformers; //设置退回选项类 var sendbackOperation = new SendBackOperation(); sendbackOperation.BackwardType = BackwardTypeEnum.Sendback; sendbackOperation.ProcessInstance = processInstance; sendbackOperation.BackwardFromActivityInstance = runningNode; sendbackOperation.HasGatewayPassed = hasGatewayPassed; sendbackOperation.ActivityResource = new ActivityResource(runner, rmins.AppRunner.NextActivityPerformers); sendbackOperation.ProcessModel = processModel; sendbackOperation.IsCancellingBrothersNode = (runner.ControlParameterSheet != null && runner.ControlParameterSheet.IsCancellingBrothersNode == 1) ? true : false; rmins.SendBackOperation = sendbackOperation; return(rmins); }