/// <summary> /// 执行退回操作 /// </summary> internal override void Execute() { var runningNode = base.SendBackOperation.BackwardFromActivityInstance; //创建撤销到上一步的节点记录 var psc = new PreviousStepChecker(); var previousAdjacentBrotherNode = psc.GetPreviousOfMultipleInstanceNode( runningNode.MIHostActivityInstanceID.Value, runningNode.ID, runningNode.CompleteOrder.Value); CreateBackwardActivityTaskOfInnerMultipleInstance(this.SendBackOperation.ProcessInstance, previousAdjacentBrotherNode, base.SendBackOperation.BackwardType, base.SendBackOperation.BackwardFromActivityInstance.ID, base.SendBackOperation.ActivityResource, base.Session); //创建新的一条待办状态的记录,用于下次执行 var newSuspendNode = base.ActivityInstanceManager.CreateActivityInstanceObject(runningNode); newSuspendNode.ActivityState = (short)ActivityStateEnum.Suspended; newSuspendNode.MIHostActivityInstanceID = runningNode.MIHostActivityInstanceID; newSuspendNode.CompleteOrder = runningNode.CompleteOrder; newSuspendNode.ComplexType = runningNode.ComplexType; newSuspendNode.SignForwardType = runningNode.SignForwardType; newSuspendNode.AssignedToUserIDs = runningNode.AssignedToUserIDs; newSuspendNode.AssignedToUserNames = runningNode.AssignedToUserNames; base.ActivityInstanceManager.Insert(newSuspendNode, base.Session); //同时为此活动实例,创建新的任务 base.TaskManager.Renew(runningNode, newSuspendNode, base.SendBackOperation.ActivityResource.AppRunner, base.Session); }
/// <summary> /// 流程返签,先检查约束条件,然后调用wfruntimeinstance执行 /// </summary> /// <param name="runner">执行者</param> /// <param name="result">结果对象</param> /// <returns>运行时实例对象</returns> public static WfRuntimeManager CreateRuntimeInstanceReverse(WfAppRunner runner, ref WfExecutedResult result) { var rmins = new WfRuntimeManagerReverse(); rmins.WfExecutedResult = result = new WfExecutedResult(); var pim = new ProcessInstanceManager(); var processInstance = pim.GetProcessInstanceLatest(runner.AppInstanceID, runner.ProcessGUID); if (processInstance == null || processInstance.ProcessState != (short)ProcessStateEnum.Completed) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Reverse_NotInCompleted; result.Message = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceReverse.error"); return(rmins); } //用于注册事件时候的流程ID rmins.ProcessInstanceID = processInstance.ID; var tim = new TransitionInstanceManager(); var endTransitionInstance = tim.GetEndTransition(runner.AppName, runner.AppInstanceID, runner.ProcessGUID); var processModel = ProcessModelFactory.Create(processInstance.ProcessGUID, processInstance.Version); var endActivity = processModel.GetActivity(endTransitionInstance.ToActivityGUID); var aim = new ActivityInstanceManager(); var endActivityInstance = aim.GetById(endTransitionInstance.ToActivityInstanceID); bool hasGatewayNode = false; var npc = new PreviousStepChecker(); var lastTaskActivityInstance = npc.GetPreviousActivityInstanceList(endActivityInstance, false, out hasGatewayNode).ToList()[0]; var lastTaskActivity = processModel.GetActivity(lastTaskActivityInstance.ActivityGUID); //封装返签结束点之前办理节点的任务接收人 rmins.AppRunner.NextActivityPerformers = ActivityResource.CreateNextActivityPerformers(lastTaskActivityInstance.ActivityGUID, lastTaskActivityInstance.EndedByUserID, lastTaskActivityInstance.EndedByUserName); rmins.ActivityResource = new ActivityResource(runner, rmins.AppRunner.NextActivityPerformers); 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.BackwardContext.ProcessInstance = processInstance; rmins.BackwardContext.BackwardToTaskActivity = lastTaskActivity; rmins.BackwardContext.BackwardToTaskActivityInstance = lastTaskActivityInstance; rmins.BackwardContext.BackwardToTargetTransitionGUID = hasGatewayNode == false ? endTransitionInstance.TransitionGUID : String.Empty; rmins.BackwardContext.BackwardFromActivity = endActivity; rmins.BackwardContext.BackwardFromActivityInstance = endActivityInstance; rmins.BackwardContext.BackwardTaskReceiver = WfBackwardTaskReceiver.Instance(lastTaskActivityInstance.ActivityName, lastTaskActivityInstance.EndedByUserID, lastTaskActivityInstance.EndedByUserName); return(rmins); }
/// <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); }
/// <summary> /// 创建跳转实例信息 /// </summary> /// <param name="runner">执行者</param> /// <param name="result">结果对象</param> /// <returns>运行时实例对象</returns> public static WfRuntimeManager CreateRuntimeInstanceJump(WfAppRunner runner, ref WfExecutedResult result) { var rmins = new WfRuntimeManagerJump(); rmins.WfExecutedResult = result = new WfExecutedResult(); if (string.IsNullOrEmpty(runner.AppName) || String.IsNullOrEmpty(runner.AppInstanceID) || runner.ProcessGUID == null || runner.NextActivityPerformers == null) { //缺失方法参数 result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Jump_ErrorArguments; result.Message = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceJump.missing.error"); return(rmins); } //流程跳转时,只能跳转到一个节点 if (runner.NextActivityPerformers.Count() > 1) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Jump_OverOneStep; result.Message = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceJump.jump.error", runner.NextActivityPerformers.Count().ToString()); return(rmins); } //获取当前运行节点信息 var aim = new ActivityInstanceManager(); TaskViewEntity taskView = null; var runningNode = aim.GetRunningNode(runner, out taskView); //传递runner变量 rmins.TaskView = taskView; rmins.AppRunner = runner; 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; //用于流程注册时间调用时候的流程实例ID提供 rmins.ProcessInstanceID = runningNode.ProcessInstanceID; var processModel = ProcessModelFactory.Create(taskView.ProcessGUID, taskView.Version); rmins.ProcessModel = processModel; #region 考虑回跳方式 //获取跳转节点信息 var jumpBackActivityGUID = runner.NextActivityPerformers.First().Key; var jumpBackActivityInstance = aim.GetActivityInstanceLatest(runningNode.ProcessInstanceID, jumpBackActivityGUID); if (jumpBackActivityInstance != null) { //跳转到曾经执行过的节点上,可以作为跳回方式处理 rmins.IsBackward = true; rmins.BackwardContext.ProcessInstance = (new ProcessInstanceManager()).GetById(runningNode.ProcessInstanceID); rmins.BackwardContext.BackwardToTaskActivity = processModel.GetActivity(jumpBackActivityGUID); //获取当前运行节点的上一步节点 bool hasGatewayNode = false; var tim = new TransitionInstanceManager(); var lastTaskTransitionInstance = tim.GetLastTaskTransition(runner.AppName, runner.AppInstanceID, runner.ProcessGUID); var npc = new PreviousStepChecker(); var previousActivityInstance = npc.GetPreviousActivityInstanceList(runningNode, true, out hasGatewayNode).ToList()[0]; //仅仅是回跳到上一步节点,即按SendBack方式处理 if (previousActivityInstance.ActivityGUID == jumpBackActivityGUID) { rmins.BackwardContext.BackwardToTaskActivityInstance = previousActivityInstance; rmins.BackwardContext.BackwardToTargetTransitionGUID = hasGatewayNode == 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); rmins.AppRunner.NextActivityPerformers = ActivityResource.CreateNextActivityPerformers( previousActivityInstance.ActivityGUID, previousActivityInstance.EndedByUserID, previousActivityInstance.EndedByUserName); } else { //回跳到早前节点 if (jumpBackActivityInstance.ActivityState != (short)ActivityStateEnum.Completed) { //回跳节点不在完成状态 result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Jump_NotActivityBackCompleted; result.Message = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceJump.back.error"); return(rmins); } rmins.BackwardContext.BackwardToTaskActivityInstance = jumpBackActivityInstance; //判断两个节点是否有Transition的定义存在 var transition = processModel.GetForwardTransition(runningNode.ActivityGUID, jumpBackActivityGUID); rmins.BackwardContext.BackwardToTargetTransitionGUID = transition != null ? transition.TransitionGUID : WfDefine.WF_XPDL_GATEWAY_BYPASS_GUID; rmins.BackwardContext.BackwardFromActivity = processModel.GetActivity(runningNode.ActivityGUID); rmins.BackwardContext.BackwardFromActivityInstance = runningNode; rmins.BackwardContext.BackwardTaskReceiver = WfBackwardTaskReceiver.Instance( jumpBackActivityInstance.ActivityName, jumpBackActivityInstance.EndedByUserID, jumpBackActivityInstance.EndedByUserName); rmins.AppRunner.NextActivityPerformers = ActivityResource.CreateNextActivityPerformers( jumpBackActivityInstance.ActivityGUID, jumpBackActivityInstance.EndedByUserID, jumpBackActivityInstance.EndedByUserName); } //获取资源数据 var activityResourceBack = new ActivityResource(rmins.AppRunner, rmins.AppRunner.NextActivityPerformers, runner.Conditions); rmins.ActivityResource = activityResourceBack; } else { //跳转到从未执行过的节点上 var activityResource = new ActivityResource(runner, runner.NextActivityPerformers, runner.Conditions); rmins.ActivityResource = activityResource; rmins.RunningActivityInstance = runningNode; } #endregion return(rmins); }