Ejemplo n.º 1
0
        internal static List <string> GetAssignedICanCancelStates(string workflowName, ApprovalRole role)
        {
            StateMachineWorkflow workflow = WorkflowRuntime.Current.GetService <IWorkFlowDefinePersistService>().GetWorkflowDefine(workflowName) as StateMachineWorkflow;
            List <string>        states   = new List <string>();

            //得到审批角色所有可撤销状态列表
            foreach (ApprovalState state in workflow.States)
            {
                foreach (ApprovalEvent oneEvent in state.Events)
                {
                    foreach (EventRole one in oneEvent.Roles)
                    {
                        if (one.Name.Equals(role.Name, StringComparison.OrdinalIgnoreCase) &&
                            (oneEvent.Authorization == Authorization.All.ToString() || oneEvent.Authorization == Authorization.DenyOwner.ToString()))
                        {
                            foreach (string nextStateName in oneEvent.NextStateNames)
                            {
                                if (workflow.GetStateByName(nextStateName).AllowedCancel)
                                {
                                    if (!states.Contains(nextStateName))
                                    {
                                        states.Add(nextStateName);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(states);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets all allowed cancel task states.
        /// </summary>
        /// <returns></returns>
        public virtual List <string> GetAllAllowedCancelTaskStates()
        {
            List <string> alloedCancelStates = new List <string>();

            //得到审批角色所有可撤销状态列表
            foreach (ApprovalState state in workflow.States)
            {
                foreach (ApprovalEvent approvalEvent in state.Events)
                {
                    foreach (EventRole eventRole in approvalEvent.Roles)
                    {
                        if (eventRole.Name == rules.UserRole.Name)
                        {
                            foreach (string nextStateName in approvalEvent.NextStateNames)
                            {
                                if (workflow.GetStateByName(nextStateName).AllowedCancel)
                                {
                                    if (!alloedCancelStates.Contains(nextStateName))
                                    {
                                        alloedCancelStates.Add(nextStateName);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(alloedCancelStates);
        }
        /// <summary>
        /// 启动工作流
        /// </summary>
        public override void Start()
        {
            StateMachineWorkflow o         = (StateMachineWorkflow)this.Workflow;
            ApprovalState        initState = o.GetStateByName(o.InitState);

            this.stateName   = initState.Name;
            this.persistTime = DateTime.Now;
            WorkflowRuntime.Current.GetService <IWorkflowPersistService>().InsertWorkflowInstance(this);
        }