/// <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="context"></param>
        public void Jump(WorkflowContext context)
        {
            WorkflowInstance instance = context.Instance;

            if (instance.State == WorkflowInstanceState.Running)
            {
                WorkflowNode current = instance.Current;

                context.SetOperation(WorkflowAction.Jump);

                if (CheckAuthorization(context) == false)
                {
                    return;
                }

                long transitionTo = current.Transitions
                                    .FirstOrDefault(e => e.NID == context.TransitionID).DESTINATION;

                current.SetActor(context.ActorID, context.ActorName, WorkflowAction.Jump);
                instance.Jump(transitionTo);

                ASTNode to = current.GetNode(transitionTo);
                OnExecuteProcess(new ExecutingContext()
                {
                    From         = current,
                    To           = to,
                    TransitionID = context.TransitionID,
                    Instance     = instance,
                    Data         = context.Data,
                    Operation    = context.Operation,
                    ActorID      = context.ActorID,
                    ActorName    = context.ActorName
                });

                if (to.NodeType == WorkflowNodeCategeory.End)
                {
                    instance.State = WorkflowInstanceState.End;
                    instance.Transfer();
                }
                else if (to.NodeType == WorkflowNodeCategeory.Decision)
                {
                    WorkflowDecision wfDecision = WorkflowDecision.ConvertToReallyType(to);
                    Transition       transition = wfDecision.GetTransition();
                    if (transition == null)
                    {
                        return;
                    }
                    Jump(new WorkflowContext()
                    {
                        Instance     = WorkflowInstance.GetInstance(instance.InstanceID),
                        TransitionID = transition.NID,
                        ActorID      = context.ActorID,
                        Data         = context.Data
                    });
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// 获取当前执行节点的记录
        /// </summary>
        /// <param name="instanceID"></param>
        /// <returns></returns>
        public dynamic GetJumpProcess(string instanceID)
        {
            WorkflowInstance instance = WorkflowInstance.GetInstance(instanceID);

            return(new
            {
                structure = instance.Resource,
                id = instance.Current.ID
            });
        }
        /// <summary>
        /// 获取当前执行节点的记录
        /// </summary>
        /// <param name="instanceID"></param>
        /// <returns></returns>
        public dynamic GetJumpProcess(string instanceID)
        {
            WorkflowInstance instance = WorkflowInstance.GetInstance(instanceID);
            IList <dynamic>  records  = ProcessService.Query(instanceID);

            return(new
            {
                structure = instance.Resource,
                id = instance.Current.ID,
                record = records
            });
        }
        /// <summary>
        /// 撤销
        /// </summary>
        /// <param name="context"></param>
        public void Cancel(WorkflowContext context)
        {
            WorkflowInstance instance = context.Instance;

            if (instance.State == WorkflowInstanceState.Running)
            {
                WorkflowNode current = instance.Current.GetFromNode();

                context.SetOperation(WorkflowAction.Undo);
                if (CheckAuthorization(context) == false)
                {
                    return;
                }

                //记录已经参与审批过的人信息
                current.SetActor(context.ActorID, context.ActorName, WorkflowAction.Undo);

                instance.Jump(current.IDENTIFICATION);

                ASTNode to = current.GetNode(current.IDENTIFICATION);

                OnExecuteProcess(new ExecutingContext()
                {
                    From         = current,
                    To           = to,
                    TransitionID = instance.Current.FromTransition.NID,
                    Instance     = instance,
                    Data         = context.Data,
                    Operation    = context.Operation,
                    ActorID      = context.ActorID,
                    ActorName    = context.ActorName
                });

                if (to.NodeType == WorkflowNodeCategeory.Decision)
                {
                    WorkflowNode wfDecision = WorkflowNode.ConvertToReallyType(to);
                    Transition   transition = wfDecision.FromTransition;

                    if (transition == null)
                    {
                        return;
                    }

                    Cancel(new WorkflowContext()
                    {
                        Instance = WorkflowInstance.GetInstance(instance.InstanceID),
                        ActorID  = context.ActorID,
                        Data     = context.Data
                    });
                }
            }
        }
Beispiel #6
0
 public void Kill(WorkflowInstance instance, WorkflowContext context)
 {
     if (instance.State == WorkflowInstanceState.Running)
     {
         workflowService.InstanceService.Transfer(WorkflowInstanceState.Kill, instance.InstanceID);
         workflowService.Actions.ForEach(pluin => pluin.ActionExecute(new ExecutingContext()
         {
             From     = context.Current,
             To       = context.Current,
             Instance = WorkflowInstance.GetInstance(instance.InstanceID),
             Data     = context.Data
         }));
     }
 }
        /// <summary>
        /// 进行流程跳转
        /// </summary>
        /// <param name="context"></param>
        public void Jump(WorkflowContext context)
        {
            WorkflowInstance instance = context.Instance;

            if (instance.State == WorkflowInstanceState.Running)
            {
                WorkflowNode current = instance.Current;


                string transitionTo = current.Transitions
                                      .FirstOrDefault(e => e.NID == context.TransitionID).Destination;


                instance.Jump(transitionTo);

                ASTNode to = current.GetNode(transitionTo);
                OnExecuteProcess(new ExecutingContext()
                {
                    From         = current,
                    To           = to,
                    TransitionID = context.TransitionID,
                    Instance     = instance,
                    Data         = context.Data,
                    ActorID      = context.ActorID,
                    ActorName    = context.ActorName
                });

                if (to.NodeType == WorkflowNodeCategory.End)
                {
                    instance.Transfer(WorkflowInstanceState.End);
                }
                else if (to.NodeType == WorkflowNodeCategory.Decision)
                {
                    WorkflowDecision wfDecision = WorkflowDecision.ConvertToReallyType(to);
                    Transition       transition = wfDecision.GetTransition();
                    if (transition == null)
                    {
                        return;
                    }
                    Jump(new WorkflowContext()
                    {
                        Instance     = WorkflowInstance.GetInstance(instance.InstanceID),
                        TransitionID = transition.NID,
                        ActorID      = context.ActorID,
                        Data         = context.Data
                    });
                }
            }
        }
        /// <summary>
        /// 流程被驳回
        /// </summary>
        /// <param name="instance">实例</param>
        protected void Reject(WorkflowInstance instance, WorkflowContext context)
        {
            if (instance.State == WorkflowInstanceState.Running)
            {
                workflowService.InstanceService.Transfer(WorkflowInstanceState.Reject, instance.InstanceID);
                WorkflowInstance newInstance = WorkflowInstance.GetInstance(instance.InstanceID);

                workflowService.Actions.ForEach(pluin => pluin.ActionExecute(new ExecutingContext()
                {
                    From     = newInstance.Current,
                    To       = newInstance.Current,
                    Instance = newInstance,
                    Data     = context.Data
                }));
            }
        }
        /// <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="instanceID"></param>
        /// <returns></returns>
        public dynamic GetJumpProcess(string instanceID)
        {
            WorkflowInstance instance = WorkflowInstance.GetInstance(instanceID);
            IList <dynamic>  records  = ProcessService.Query(instanceID);
            List <string>    runNodes = new List <string>();

            foreach (Node n in instance.Current)
            {
                runNodes.Add(n.ID);
            }
            return(new
            {
                structure = instance.Resource,
                link = runNodes,
                record = records
            });
        }
        protected void Invoke(WorkflowContext context, ASTNode to, string selectTransition, System.Action <ExecutingContext> executeAction)
        {
            WorkflowNode current = context.Instance.Current;

            bool validation = true;

            if (WorkflowCooperationService != null && current.Cooperation > 0)
            {
                IList <WorkflowProcess> records = ProcessService.GetLatestRecords(current.InstanceID, current.NID, current.Increment);

                validation = WorkflowCooperationService.Check(current, records);

                selectTransition = WorkflowCooperationService
                                   .SelectStrategy()
                                   .Decide(records, to.ID,
                                           (workflowProcess) => ProcessService.Persistent(workflowProcess));
            }

            if (validation)
            {
                context.Instance.Jump(to.ID);

                var next = WorkflowInstance
                           .GetInstance(current.InstanceID)
                           .Current;
                if (next.NodeType != WorkflowNodeCategory.End)
                {
                    next.DoIncrement();
                }
            }

            executeAction(new ExecutingContext()
            {
                From         = current,
                To           = to,
                TransitionID = context.TransitionID,
                Instance     = context.Instance,
                Data         = context.Data,
                ActorID      = context.ActorID,
                ActorName    = context.ActorName,
                IsValid      = validation
            });
        }
        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
                });
            }
        }