protected void Invoke(WorkflowContext context, string selectTransition, ExecutingContext executeContext) { Node current = context.Instance.Current; bool validation = true; AbstractWorkflowCooperation abstractWorkflowCooperation = workflowService.WorkflowCooperationService; if (abstractWorkflowCooperation != null && current.Cooperation > 0) { IList <WorkflowProcess> records = workflowService.ProcessService.Query(new { current.InstanceID, Command = current.Cooperation }) .Where(c => c.RelationshipID == current.NID) .ToList(); validation = abstractWorkflowCooperation.Check(current, records); selectTransition = abstractWorkflowCooperation.SelectStrategy().Decide(records); if (validation) { abstractWorkflowCooperation.Detached(records, selectTransition, (r) => workflowService.ProcessService.Detached(r), u => workflowService.ProcessService.Update(u)); } } executeContext.IsValid = validation; if (executeContext.IsValid) { workflowService.InstanceService.Jump(selectTransition, context.Instance.InstanceID); } workflowService.Actions.ForEach(pluin => pluin.ActionExecute(executeContext)); }
/// <summary> /// 进行流程跳转 /// </summary> /// <param name="context"></param> public void Jump(WorkflowContext context) { WorkflowInstance instance = context.Instance; if (instance.State == WorkflowInstanceState.Running) { if (context.TransitionID == Utils.CONST_REJECT_TRANSITION_ID) { Reject(instance, context); return; } Node current = instance.Current; Transition currentTransition = current.Transitions .FirstOrDefault(e => e.NID == context.TransitionID); Node to = workflowService.NodeService.Query(current.InstanceID) .Where(e => e.ID == currentTransition.Destination).FirstOrDefault(); var executeContext = new ExecutingContext() { From = current, To = to, Instance = context.Instance, Data = context.Data, Result = false }; if (current.Cooperation == 1) { this.Discuss(context, current, executeContext); } else { this.Invoke(context.Instance.InstanceID, currentTransition, executeContext); } if (to.NodeType == WorkflowNodeCategory.End) { workflowService.InstanceService.Transfer(WorkflowInstanceState.End, instance.InstanceID); } else if (to.NodeType == WorkflowNodeCategory.Decision) { Transition transition = (currentTransition.Direction == WorkflowOpertaion.Back) ? workflowService.NodeService.GetBackTransition(WorkflowInstance.GetInstance(instance.InstanceID).Current) : workflowService.NodeService.GetTransition(to); if (transition == null) { return; } Jump(new WorkflowContext() { Instance = WorkflowInstance.GetInstance(instance.InstanceID), TransitionID = transition.NID, Data = context.Data }); } } }
/// <summary> /// 触发流程跳转事件 /// </summary> /// <param name="executeContext">执行上下文</param> protected void OnExecuteProcess(ExecutingContext executeContext) { Processing(executeContext); OnProcess(executeContext); if (OnCompleted != null && executeContext.To.NodeType == WorkflowNodeCategory.End) { OnCompleted(executeContext); } }
public void ActionExecute(ExecutingContext executingContext) { IList <IWorkflowAction> actions = GetWorkflowActions(executingContext.To); foreach (IWorkflowAction action in actions) { action.ActionExecute(executingContext); } }
/// <summary> /// 跳转过程处理入库 /// </summary> /// <param name="executeContext">执行上下文</param> protected void Processing(ExecutingContext executeContext) { workflowService.Processing(new WorkflowProcess() { RelationshipID = executeContext.To.NID, Origin = executeContext.From.ID, Destination = executeContext.To.ID, TransitionID = executeContext.TransitionID, InstanceID = executeContext.Instance.InstanceID, NodeType = executeContext.From.NodeType }); }
/// <summary> /// 跳转过程处理入库 /// </summary> /// <param name="executeContext">执行上下文</param> protected void Processing(ExecutingContext executeContext, string transitionID, WorkflowOpertaion command) { workflowService.ProcessService.Persistent(new WorkflowProcess() { RelationshipID = executeContext.From.NID, Origin = executeContext.From.ID, Destination = executeContext.To.ID, TransitionID = transitionID, InstanceID = executeContext.Instance.InstanceID, NodeType = executeContext.From.NodeType, Command = command }); }
/// <summary> /// 跳转过程处理入库 /// </summary> /// <param name="executeContext">执行上下文</param> protected void Processing(ExecutingContext executeContext) { workflowService.Processing(new WorkflowProcess() { RNID = executeContext.To.NID, ORIGIN = executeContext.From.IDENTIFICATION, DESTINATION = executeContext.To.IDENTIFICATION, TRANSITIONID = executeContext.TransitionID, INSTANCEID = executeContext.Instance.InstanceID, NODETYPE = executeContext.From.NodeType, OPERATION = executeContext.Operation }); }
/// <summary> /// 跳转过程处理入库 /// </summary> /// <param name="executeContext">执行上下文</param> protected void Processing(ExecutingContext executeContext) { ProcessService.Persistent(new WorkflowProcess() { RelationshipID = executeContext.From.NID, Origin = executeContext.From.ID, Destination = executeContext.To.ID, TransitionID = executeContext.TransitionID, InstanceID = executeContext.Instance.InstanceID, NodeType = executeContext.From.NodeType, Increment = executeContext.From.Increment }); this.Actions.ForEach(pluin => pluin.ActionExecute(executeContext)); }
protected void Invoke(string instanceID, Transition selectTransition, ExecutingContext executeContext) { workflowService.InstanceService.Jump(selectTransition.Destination, instanceID, new WorkflowProcess() { RelationshipID = executeContext.From.NID, Origin = executeContext.From.ID, Destination = executeContext.To.ID, TransitionID = selectTransition.NID, InstanceID = executeContext.Instance.InstanceID, NodeType = executeContext.From.NodeType, Direction = selectTransition.Direction }, workflowService.ProcessService); workflowService.Actions.ForEach(pluin => pluin.ActionExecute(executeContext)); }
/// <summary> /// 进行流程跳转 /// </summary> /// <param name="context"></param> public void Jump(WorkflowContext context) { WorkflowInstance instance = context.Instance; if (instance.State == WorkflowInstanceState.Running) { Node current = instance.Current; string transitionTo = current.Transitions .FirstOrDefault(e => e.NID == context.TransitionID).Destination; Node to = workflowService.NodeService.Query(new { current.InstanceID }) .Where(e => e.ID == transitionTo) .FirstOrDefault(); var executeContext = new ExecutingContext() { From = current, To = to, Instance = context.Instance, Data = context.Data }; Processing(executeContext, context.TransitionID, (WorkflowOpertaion)executeContext.From.Cooperation); this.Invoke(context, transitionTo, executeContext); if (to.NodeType == WorkflowNodeCategory.End) { workflowService.InstanceService.Transfer(WorkflowInstanceState.End, instance.InstanceID); } else if (to.NodeType == WorkflowNodeCategory.Decision) { Transition transition = workflowService.NodeService.GetTransition(to); if (transition == null) { return; } Jump(new WorkflowContext() { Instance = WorkflowInstance.GetInstance(instance.InstanceID), TransitionID = transition.NID, Data = context.Data }); } } }
/// <summary> /// 跳转过程处理入库 /// </summary> /// <param name="executeContext">执行上下文</param> protected void Processing(ExecutingContext executeContext) { workflowService.Processing(new WorkflowProcess() { RelationshipID = executeContext.To.NID, Origin = executeContext.From.ID, Destination = executeContext.To.ID, TransitionID = executeContext.TransitionID, InstanceID = executeContext.Instance.InstanceID, NodeType = executeContext.From.NodeType }); System.Threading.Tasks.Task.Factory.StartNew(() => { }); }
protected void Discuss(WorkflowContext context, Node current, ExecutingContext executeContext, string actorID) { string instanceID = context.Instance.InstanceID; IWorkflowCooperationService workflowCooperationService = workflowService.NodeService.WorkflowCooperationService; IStrategyService strategyService = workflowService.StrategyService; workflowService.NodeService.WorkflowCooperationService.Persistent(new WorkflowCooperation { NID = Guid.NewGuid().ToString(), NodeID = current.NID, InstanceID = context.Instance.InstanceID, TransitionID = context.TransitionID, CreateDateTime = DateTime.Now }); IList <WorkflowCooperation> records = workflowCooperationService.Query(instanceID) .Where(e => e.NodeID == current.NID) .ToList(); executeContext.Result = strategyService.Check(records); if (executeContext.Result) { string to = strategyService.Use().Execute(records); Transition transition = current.Transitions.FirstOrDefault(e => e.NID == to); Node node = workflowService.NodeService.Query(current.InstanceID) .Where(e => e.ID == transition.Destination).FirstOrDefault(); this.Invoke(node, instanceID, transition, new ExecutingContext() { From = current, To = node, Instance = context.Instance, Data = context.Data, Result = executeContext.Result, Direction = executeContext.Direction }, actorID, context); } else { workflowService.Actions.ForEach(pluin => pluin.ActionExecute(executeContext)); } }
/// <summary> /// 进行流程跳转 /// </summary> /// <param name="context"></param> public void Jump(WorkflowContext context) { WorkflowInstance instance = context.Instance; if (instance.State == WorkflowInstanceState.Running) { string instanceID = instance.InstanceID; Node current = instance.Current; if (context.TransitionID == Utils.CONST_REJECT_TRANSITION_ID) { Reject(instance, context); return; } Transition currentTransition = current.Transitions .FirstOrDefault(e => e.NID == context.TransitionID); Node to = workflowService.NodeService.Query(instanceID) .Where(e => e.ID == currentTransition.Destination).FirstOrDefault(); var executeContext = new ExecutingContext() { From = current, To = to, Direction = currentTransition.Direction, Instance = context.Instance, Data = context.Data, Result = false }; if (current.Cooperation == 1) { this.Discuss(context, current, executeContext, context.ActorID); } else { this.Invoke(to, instanceID, currentTransition, executeContext, context.ActorID, context); } } }
/// <summary> /// 原路退回,回退到上一节点 /// </summary> /// <param name="context">工作流上下文</param> public void Back(WorkflowContext context) { WorkflowInstance instance = context.Instance; if (instance.State == WorkflowInstanceState.Running) { Node current = instance.Current; Node previous = current.Previous; if (previous != null) { string transitionTo = previous.ID; Node to = workflowService.NodeService.Query(new { current.InstanceID }) .Where(e => e.ID == transitionTo) .FirstOrDefault(); var executeContext = new ExecutingContext() { From = current, To = to, Instance = instance, Data = context.Data, IsValid = true }; Processing(executeContext, String.Empty, WorkflowOpertaion.Back); workflowService.InstanceService.Jump(transitionTo, instance.InstanceID); if (previous.NodeType == WorkflowNodeCategory.Start) { workflowService.ProcessService.DetachedAll(context.Instance.InstanceID); } workflowService.Actions.ForEach(pluin => pluin.ActionExecute(executeContext)); } } }
protected void Invoke(Node to, string instanceID, Transition selectTransition, ExecutingContext executeContext, String actorID, WorkflowContext context) { workflowService.InstanceService.Jump(selectTransition.Destination, instanceID, new WorkflowProcess() { RelationshipID = executeContext.From.NID, ActorID = actorID, Origin = executeContext.From.ID, Destination = executeContext.To.ID, TransitionID = selectTransition.NID, InstanceID = executeContext.Instance.InstanceID, NodeType = executeContext.From.NodeType, Direction = selectTransition.Direction }, workflowService.ProcessService); workflowService.Actions.ForEach(pluin => pluin.ActionExecute(executeContext)); if (to.NodeType == WorkflowNodeCategory.End) { workflowService.InstanceService.Transfer(WorkflowInstanceState.End, instanceID); } else if (to.NodeType == WorkflowNodeCategory.Decision) { Transition transition = (selectTransition.Direction == WorkflowOpertaion.Back) ? workflowService.NodeService.GetBackTransition(WorkflowInstance.GetInstance(instanceID).Current) : workflowService.NodeService.GetTransition(to); if (transition == null) { return; } Jump(new WorkflowContext() { Instance = WorkflowInstance.GetInstance(instanceID), TransitionID = transition.NID, Data = context.Data, ActorID = context.ActorID }); } }
/// <summary> /// 触发流程跳转事件 /// </summary> /// <param name="executeContext">执行上下文</param> protected void OnExecuteProcess(ExecutingContext executeContext) { Processing(executeContext); OnProcess(executeContext); }