/// <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 #2
0
        /// <summary>
        /// 上一个执行跳转节点
        /// </summary>
        /// <returns></returns>
        public WorkflowNode GetFromNode()
        {
            if (FromTransition == null)
            {
                return(null);
            }
            ASTNode node = GetNode(FromTransition.Origin);

            return(WorkflowNode.ConvertToReallyType(node));
        }
        /// <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 #4
0
        public static WorkflowNode ConvertToReallyType(ASTNode node)
        {
            WorkflowNode wfNode = new WorkflowNode();

            wfNode.NID            = node.NID;
            wfNode.IDENTIFICATION = node.IDENTIFICATION;
            wfNode.APPELLATION    = node.APPELLATION;
            wfNode.NodeType       = node.NodeType;
            wfNode.INSTANCEID     = node.INSTANCEID;
            wfNode.Transitions    = wfNode.QueryWorkflowNode(node.NID);
            wfNode.FromTransition = wfNode.GetHistoryTransition();
            wfNode.Groups         = wfNode.GetGroup();
            return(wfNode);
        }
        /// <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
                    });
                }
            }
        }
Beispiel #6
0
        public static WorkflowNode ConvertToReallyType(ASTNode node)
        {
            WorkflowNode wfNode = new WorkflowNode();

            wfNode.NID            = node.NID;
            wfNode.ID             = node.ID;
            wfNode.Name           = node.Name;
            wfNode.NodeType       = node.NodeType;
            wfNode.InstanceID     = node.InstanceID;
            wfNode.Transitions    = wfNode.QueryWorkflowNode(node.NID);
            wfNode.FromTransition = wfNode.GetHistoryTransition();
            wfNode.Groups         = wfNode.GetGroup();

            return(wfNode);
        }
Beispiel #7
0
        private List <IWorkflowAction> GetWorkflowActions(ASTNode to)
        {
            List <IWorkflowAction> partAction = new List <IWorkflowAction>();
            WorkflowNode           nodes      = WorkflowNode.ConvertToReallyType(to);

            nodes.Actions.ForEach(el =>
            {
                IWorkflowAction defaultAction = this.Scan(el.ID);
                if (defaultAction != null)
                {
                    partAction.Add(defaultAction);
                }
            });
            return(partAction);
        }
        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
            });
        }
Beispiel #9
0
        /// <summary>
        /// 获取流程实例
        /// </summary>
        /// <param name="instanceID">实例ID</param>
        /// <returns>流程实例</returns>
        public static WorkflowInstance GetInstance(string instanceID)
        {
            WorkflowInstance workflowInstance = new WorkflowInstance();

            workflowInstance.InstanceID = instanceID;
            string sql = ResourceManage.GetString(ResourceManage.SQL_WORKFLOW_INSTANCE);

            try
            {
                workflowInstance = workflowInstance.Connection.Query <WorkflowInstance, ASTNode, WorkflowInstance>(sql, (instance, node) =>
                {
                    instance.Current = WorkflowNode.ConvertToReallyType(node);
                    return(instance);
                }, param: new { INSTANCEID = instanceID }, splitOn: "APPELLATION").FirstOrDefault <WorkflowInstance>();

                return(workflowInstance);
            }
            catch (Exception ex)
            {
                throw new WorkflowException(ex, instanceID);
            }
        }