/// <summary> /// 根据不同撤销场景创建运行时管理器 /// </summary> /// <param name="runningActivityInstanceList">运行节点列表</param> /// <param name="withdrawOperation">撤销类型</param> /// <param name="runner">执行者</param> /// <param name="result">结果对象</param> /// <returns>运行时管理器</returns> private static WfRuntimeManager CreateRuntimeInstanceWithdrawByCase( List <ActivityInstanceEntity> runningActivityInstanceList, WithdrawOpertaionTypeEnum withdrawOperation, WfAppRunner runner, ref WfExecutedResult result) { WfRuntimeManager rmins = new WfRuntimeManagerWithdraw(); rmins.WfExecutedResult = result = new WfExecutedResult(); //根据当前运行节点获取 ActivityInstanceEntity runningNode = runningActivityInstanceList[0]; ProcessInstanceEntity processInstance = (new ProcessInstanceManager()).GetById(runningNode.ProcessInstanceID); IProcessModel processModel = ProcessModelFactory.Create(processInstance.ProcessGUID, processInstance.Version); //以下处理,需要知道上一步是独立节点的信息 //获取上一步流转节点信息,可能经过And, Or等路由节点 var tim = new TransitionInstanceManager(); bool hasGatewayNode = false; var currentNode = runningNode; var lastActivityInstanceList = tim.GetPreviousActivityInstance(currentNode, false, out hasGatewayNode).ToList(); if (lastActivityInstanceList == null || lastActivityInstanceList.Count > 1) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Withdraw_HasTooMany; result.Message = "当前没有可以撤销回去的节点,或者有多个可以撤销回去的节点,无法选择!"; return(rmins); } TransitionInstanceEntity lastTaskTransitionInstance = null; if (hasGatewayNode == false) { lastTaskTransitionInstance = tim.GetLastTaskTransition(runner.AppName, runner.AppInstanceID, runner.ProcessGUID); if (lastTaskTransitionInstance.TransitionType == (short)TransitionTypeEnum.Loop) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Withdraw_IsLoopNode; result.Message = "当前流转是自循环,无需撤销!"; return(rmins); } } var previousActivityInstance = lastActivityInstanceList[0]; if (previousActivityInstance.EndedByUserID != runner.UserID) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Withdraw_NotCreatedByMine; result.Message = string.Format("上一步节点的任务办理人跟当前登录用户不一致,无法撤销回上一步!节点办理人:{0}", previousActivityInstance.EndedByUserName); return(rmins); } if (previousActivityInstance.ActivityType == (short)ActivityTypeEnum.EndNode) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Withdraw_PreviousIsEndNode; result.Message = "上一步是结束节点,无法撤销!"; return(rmins); } //当前运行节点是普通节点 if (withdrawOperation == WithdrawOpertaionTypeEnum.Normal) { //简单串行模式下的退回 rmins = new WfRuntimeManagerWithdraw(); rmins.WfExecutedResult = result = new WfExecutedResult(); rmins.ProcessModel = processModel; rmins.AppRunner.ProcessGUID = runner.ProcessGUID; rmins.BackwardContext.ProcessInstance = processInstance; rmins.BackwardContext.BackwardToTargetTransitionGUID = hasGatewayNode == false ? lastTaskTransitionInstance.TransitionGUID : String.Empty; rmins.BackwardContext.BackwardToTaskActivity = processModel.GetActivity(previousActivityInstance.ActivityGUID); rmins.BackwardContext.BackwardToTaskActivityInstance = previousActivityInstance; rmins.BackwardContext.BackwardFromActivity = processModel.GetActivity(runningNode.ActivityGUID); rmins.BackwardContext.BackwardFromActivityInstance = runningNode; //准备状态的接收节点 rmins.BackwardContext.BackwardTaskReciever = WfBackwardTaskReciever.Instance( previousActivityInstance.ActivityName, previousActivityInstance.EndedByUserID, previousActivityInstance.EndedByUserName); //封装AppUser对象 rmins.AppRunner.AppName = runner.AppName; rmins.AppRunner.AppInstanceID = runner.AppInstanceID; rmins.AppRunner.UserID = runner.UserID; rmins.AppRunner.UserName = runner.UserName; rmins.AppRunner.NextActivityPerformers = ActivityResource.CreateNextActivityPerformers( previousActivityInstance.ActivityGUID, runner.UserID, runner.UserName); rmins.ActivityResource = new ActivityResource(runner, rmins.AppRunner.NextActivityPerformers); return(rmins); } //如果有其它模式,没有处理到,则直接抛出异常 throw new WorkflowException("未知的撤销场景,请报告给技术支持人员!"); }
/// <summary> /// 根据不同退回场景创建运行时管理器 /// </summary> /// <param name="runningActivityInstanceList">运行节点列表</param> /// <param name="sendbackOperation">退回类型</param> /// <param name="runner">执行者</param> /// <param name="result">结果对象</param> /// <returns>运行时管理器</returns> private static WfRuntimeManager CreateRuntimeInstanceSendbackByCase( List <ActivityInstanceEntity> runningActivityInstanceList, SendbackOpertaionTypeEnum sendbackOperation, WfAppRunner runner, ref WfExecutedResult result) { WfRuntimeManager rmins = new WfRuntimeManagerSendBack(); rmins.WfExecutedResult = result = new WfExecutedResult(); ActivityInstanceEntity runningNode = runningActivityInstanceList.Where(x => x.ActivityState == (int)ActivityStateEnum.Running).OrderBy(x => x.ID).FirstOrDefault(); if (runningNode == null) { runningNode = runningActivityInstanceList[0]; } ProcessInstanceEntity processInstance = (new ProcessInstanceManager()).GetById(runningNode.ProcessInstanceID); IProcessModel processModel = ProcessModelFactory.Create(processInstance.ProcessGUID, processInstance.Version); var aim = new ActivityInstanceManager(); //以下处理,需要知道上一步是独立节点的信息 //获取上一步流转节点信息,可能经过And, Or等路由节点 var tim = new TransitionInstanceManager(); bool hasGatewayNode = false; var currentNode = runningNode; var lastActivityInstanceList = tim.GetPreviousActivityInstance(currentNode, true, out hasGatewayNode).ToList(); if (lastActivityInstanceList == null || lastActivityInstanceList.Count == 0 || lastActivityInstanceList.Count > 1) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NullOrHasTooMany; result.Message = "当前没有可以退回的节点,或者有多个可以退回的节点,无法选择!"; return(rmins); } TransitionInstanceEntity lastTaskTransitionInstance = null; lastTaskTransitionInstance = tim.GetLastTaskTransition(runner.AppName, runner.AppInstanceID, runner.ProcessGUID); if (lastTaskTransitionInstance.TransitionType == (short)TransitionTypeEnum.Loop) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_IsLoopNode; result.Message = "当前流转是自循环,无需退回!"; return(rmins); } //设置退回节点的相关信息 var previousActivityInstance = lastActivityInstanceList[0]; if (previousActivityInstance.ActivityType == (short)ActivityTypeEnum.StartNode) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_PreviousIsStartNode; result.Message = "上一步是开始节点,无需退回!"; return(rmins); } if (sendbackOperation == SendbackOpertaionTypeEnum.Normal) { //简单串行模式下的退回 rmins = new WfRuntimeManagerSendBack(); rmins.WfExecutedResult = result = new WfExecutedResult(); rmins.ProcessModel = processModel; rmins.BackwardContext.ProcessInstance = processInstance; rmins.BackwardContext.BackwardToTaskActivity = processModel.GetActivity(previousActivityInstance.ActivityGUID); rmins.BackwardContext.BackwardToTaskActivityInstance = previousActivityInstance; rmins.BackwardContext.BackwardToTargetTransitionGUID = hasGatewayNode == false ? lastTaskTransitionInstance.TransitionGUID : String.Empty; //如果中间有Gateway节点,则没有直接相连的TransitonGUID rmins.BackwardContext.BackwardFromActivity = processModel.GetActivity(runningNode.ActivityGUID); rmins.BackwardContext.BackwardFromActivityInstance = runningNode; rmins.BackwardContext.BackwardTaskReciever = WfBackwardTaskReciever.Instance(previousActivityInstance.ActivityName, previousActivityInstance.EndedByUserID, previousActivityInstance.EndedByUserName); //封装AppUser对象 rmins.AppRunner.AppName = runner.AppName; rmins.AppRunner.AppInstanceID = runner.AppInstanceID; rmins.AppRunner.ProcessGUID = runner.ProcessGUID; rmins.AppRunner.UserID = runner.UserID; rmins.AppRunner.UserName = runner.UserName; rmins.AppRunner.NextActivityPerformers = ActivityResource.CreateNextActivityPerformers(previousActivityInstance.ActivityGUID, previousActivityInstance.EndedByUserID, previousActivityInstance.EndedByUserName); rmins.ActivityResource = new ActivityResource(runner, rmins.AppRunner.NextActivityPerformers); return(rmins); } //如果有其它模式,没有处理到,则直接抛出异常 throw new WorkflowException("未知的退回场景,请报告给技术支持人员!"); }
private static WfRuntimeManager CreateRuntimeInstanceSendbackByCase(ActivityInstanceEntity runningNode, IProcessModel processModel, ProcessInstanceEntity processInstance, IList <ActivityEntity> sendbackPreviousActivityList, Boolean hasGatewayPassed, SendbackOperationTypeEnum sendbackOperation, WfAppRunner runner, ref WfExecutedResult result) { WfRuntimeManager rmins = new WfRuntimeManagerSendBack(); rmins.WfExecutedResult = result = new WfExecutedResult(); var aim = new ActivityInstanceManager(); //以下处理,需要知道上一步是独立节点的信息 var tim = new TransitionInstanceManager(); TransitionInstanceEntity lastTaskTransitionInstance = tim.GetLastTaskTransition(runner.AppName, runner.AppInstanceID, runner.ProcessGUID); if (lastTaskTransitionInstance.TransitionType == (short)TransitionTypeEnum.Loop) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_IsLoopNode; result.Message = "当前流转是自循环,无需退回!"; return(rmins); } //设置退回节点的相关信息 var previousActivityGUID = sendbackPreviousActivityList[0].ActivityGUID; var previousActivityInstance = aim.GetActivityInstanceLatest(runner.AppInstanceID, runner.ProcessGUID, previousActivityGUID); //普通模式的退回 if (sendbackOperation == SendbackOperationTypeEnum.Normal) { //简单串行模式下的退回 rmins = new WfRuntimeManagerSendBack(); rmins.WfExecutedResult = result = new WfExecutedResult(); rmins.ProcessModel = processModel; rmins.BackwardContext.ProcessInstance = processInstance; rmins.BackwardContext.BackwardToTaskActivity = processModel.GetActivity(previousActivityInstance.ActivityGUID); rmins.BackwardContext.BackwardToTaskActivityInstance = previousActivityInstance; rmins.BackwardContext.BackwardToTargetTransitionGUID = hasGatewayPassed == false ? lastTaskTransitionInstance.TransitionGUID : WfDefine.WF_XPDL_GATEWAY_BYPASS_GUID; //如果中间有Gateway节点,则没有直接相连的TransitonGUID rmins.BackwardContext.BackwardFromActivity = processModel.GetActivity(runningNode.ActivityGUID); rmins.BackwardContext.BackwardFromActivityInstance = runningNode; rmins.BackwardContext.BackwardTaskReceiver = WfBackwardTaskReceiver.Instance(previousActivityInstance.ActivityName, previousActivityInstance.EndedByUserID, previousActivityInstance.EndedByUserName); //封装AppUser对象 rmins.AppRunner.AppName = runner.AppName; rmins.AppRunner.AppInstanceID = runner.AppInstanceID; rmins.AppRunner.ProcessGUID = runner.ProcessGUID; rmins.AppRunner.UserID = runner.UserID; rmins.AppRunner.UserName = runner.UserName; rmins.AppRunner.NextActivityPerformers = ActivityResource.CreateNextActivityPerformers(previousActivityInstance.ActivityGUID, previousActivityInstance.EndedByUserID, previousActivityInstance.EndedByUserName); rmins.ActivityResource = new ActivityResource(runner, rmins.AppRunner.NextActivityPerformers); return(rmins); } //如果有其它模式,没有处理到,则直接抛出异常 throw new WorkflowException("未知的退回场景,请报告给技术支持人员!"); }