/// <summary>
        /// 判断某用户是否能撤销实例的上一步操作
        /// </summary>
        /// <param name="instance">工作流实例</param>
        /// <returns></returns>
        public virtual bool CanCancel(WorkflowInstance instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }
            IUserIdentity userIdentity = WorkflowRuntime.Current.GetService <IIdentityService>().GetUserIdentity();
            StateMachineWorkflowInstance stateMachine = (StateMachineWorkflowInstance)WorkflowRuntime.Current.GetInstance(instance.Id);

            if (stateMachine == null)
            {
                return(false);
            }
            if (stateMachine.LastActivity == null)
            {
                return(false);
            }

            //逐个判断activity的执行用户,如果有一个和当前匹配,那么允许撤销
            string[] users       = stateMachine.LastActivity.UserId.Trim().Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            string   currentUser = userIdentity.GetUserId().Trim();

            for (int i = 0; i < users.Length; i++)
            {
                if (users[i].Equals(currentUser, StringComparison.OrdinalIgnoreCase))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// 撤销操作时进行的相关审批记录操作,如果要用不同的记录,必须重写该方法
        /// </summary>
        /// <param name="instance">The instance.</param>
        protected virtual void TrackUndo(WorkflowInstance instance)
        {
            ApprovalRecord       record          = new ApprovalRecord();
            IIdentityService     service         = WorkflowRuntime.Current.GetService <IIdentityService>();
            IApprovalSaveService approvalService = WorkflowRuntime.Current.GetService <IApprovalSaveService>();

            if (service == null)
            {
                throw new WorkflowExecuteExeception("身份信息提供服务为空");
            }
            IUserIdentity userInfo = service.GetUserIdentity();

            record.OperatorTime       = DateTime.Now;
            record.WorkflowInstanceId = instance.Id;
            record.OperatorId         = userInfo.GetUserId();
            record.OperatorName       = userInfo.GetUserName();
            record.OperatorUnitCode   = userInfo.GetUserUnitCode();
            record.OperatorRole       = this.UserApprovalRole;
            record.EaId = instance.EaId;

            StateMachineWorkflowInstance stateMachine = instance as StateMachineWorkflowInstance;

            record.ApprovalType = GetUndoName(instance);
            record.StateName    = stateMachine.CurrentState.Description;
            if (recordId != 0)
            {
                ApprovalRecord historyRecord = approvalService.GetRecordById(recordId);
                historyRecord.IsCanceled = true;
                approvalService.SaveRecord(historyRecord);
            }
            WorkflowRuntime.Current.GetService <IApprovalSaveService>().InsertRecord(record);
        }
        private void OnChildFinished(StateMachineWorkflowInstance instance)
        {
            bool isAllFinished = true;

            if (childrenId != null)
            {
                foreach (Guid oneChild in childrenId)
                {
                    StateMachineWorkflowInstance childInstance = WorkflowRuntime.Current.GetService <IWorkflowPersistService>().GetWorkflowInstance(oneChild);
                    if (childInstance.id == instance.id)
                    {
                        continue;
                    }
                    if (childInstance.CurrentStatus != WorkflowExecutionStatus.Closed)
                    {
                        isAllFinished = false;
                    }
                }
                if (isAllFinished)
                {
                    if (CurrentState is InvokeWorkflowState)
                    {
                        MoveOn(((InvokeWorkflowState)CurrentState).CompletedTransitionState);
                    }
                    else
                    {
                        //顺序动作,从动作针对的事件名称中获取状态
                        MoveOn(CurrentState.Events[0].NextStateNames[0]);
                    }
                    childrenId = null;
                    Save();
                }
            }
        }
        /// <summary>
        /// 获取指定工作流、角色、时间段的实例集合
        /// </summary>
        /// <param name="workflowName">流程名称</param>
        /// <param name="userIdentity">用户身份</param>
        /// <param name="role">审批角色</param>
        /// <param name="startDate">时间段起始时间</param>
        /// <param name="endDate">时间段截止时间</param>
        /// <returns></returns>
        protected override InstanceCollection Distill(string workflowName, IUserIdentity userIdentity, ApprovalRole role, DateTime startDate, DateTime endDate)
        {
            InstanceCollection        collection  = new InstanceCollection();
            List <ApprovalAssignment> assignments = WorkflowRuntime.Current.SaveService.GetAssignmentByToUnit(workflowName, userIdentity.GetUserUnitCode());
            List <Guid> ids = new List <Guid>();

            collection = new InstanceCollection();
            foreach (ApprovalAssignment assignment in assignments)
            {
                if (string.IsNullOrEmpty(assignment.ToUserId))
                {
                    if (!ids.Contains(assignment.WorkflowInstanceId))
                    {
                        ids.Add(assignment.WorkflowInstanceId);
                    }
                }
            }
            foreach (Guid id in ids)
            {
                StateMachineWorkflowInstance instance = (StateMachineWorkflowInstance)WorkflowRuntime.Current.GetInstance(id);
                if (instance.PersistTime > startDate && instance.PersistTime < endDate)
                {
                    collection.Add(new InstanceWithRole(instance, role, false));
                }
            }
            return(collection);
        }
Beispiel #5
0
 /// <summary>
 /// 保存工作流实例
 /// </summary>
 /// <param name="instance"></param>
 StateMachineWorkflowInstance IWorkflowPersistService.SaveWorkflowInstance(StateMachineWorkflowInstance instance)
 {
     if (instance == null)
     {
         throw new ArgumentNullException("instance");
     }
     return(SaveWorkflowInstance(instance));
 }
Beispiel #6
0
        /// <summary>
        /// 判断指定实例是否需要满足过滤条件,满足则返回True,否则返回False
        /// </summary>
        /// <param name="instance">工作流实例</param>
        /// <param name="role">用户的审批角色</param>
        /// <param name="userIdentity">用户的身份</param>
        /// <returns>满足则返回True,否则返回False</returns>
        protected override bool IsMatch(StateMachineWorkflowInstance instance, ApprovalRole role, IUserIdentity userIdentity)
        {
            List <ApprovalAssignment> assignmentList = WorkflowRuntime.Current.GetService <IApprovalSaveService>().GetAssignment(instance.Id);

            if (assignmentList.Count == 0)
            {
                return(false);
            }

            return(IsOthers(userIdentity, assignmentList));
        }
Beispiel #7
0
        /// <summary>
        /// Gets the sub unit role list.
        /// </summary>
        /// <param name="taskStateList">The task state list.</param>
        /// <param name="taskName">Name of the task.</param>
        /// <returns></returns>
        protected override List <StateMachineWorkflowInstance> GetSubUnitRoleList(List <string> taskStateList, string taskName)
        {
            List <StateMachineWorkflowInstance> instanceList = new List <StateMachineWorkflowInstance>();

            foreach (string stateName in taskStateList)
            {
                ApprovalEvent taskEvent = new ApprovalEvent();
                ApprovalState state     = Workflow.GetStateByName(stateName);
                if (state != null)
                {
                    foreach (ApprovalEvent approvalEvent in state.Events)
                    {
                        foreach (EventRole role in approvalEvent.Roles)
                        {
                            if (role.Name == Rules.UserRole.Name && taskName == role.TaskName)
                            {
                                taskEvent = approvalEvent;
                                break;
                            }
                        }
                    }
                    //如果用户为二级单位专办员
                    if (Rules.IsCreator())
                    {
                        //如果该任务只允许立项创建者办理
                        if (taskEvent.Authorization != Authorization.DenyOwner.ToString())
                        {
                            instanceList.AddRange(GetOwnerList(new string[] { stateName }));
                        }
                    }
                    else
                    {
                        instanceList.AddRange(GetUnitList(new string[] { stateName }));
                    }
                    //非用户创建,但是属于指定专办的实例,且实例为指定状态
                    if (taskEvent.Authorization == Authorization.DenyOwner.ToString())
                    {
                        //其它二级单位专办员获得专办立项列表
                        List <ApprovalAssignment> assignmentList = WorkflowRuntime.Current.GetService <IApprovalSaveService>().GetAssignmentByToUnit(this.Workflow.Name, UnitCode);
                        foreach (ApprovalAssignment assignment in assignmentList)
                        {
                            StateMachineWorkflowInstance assignInstance = (StateMachineWorkflowInstance)WorkflowRuntime.Current.GetInstance(assignment.WorkflowInstanceId);
                            if (assignInstance.StateName == stateName)
                            {
                                instanceList.Add(assignInstance);
                            }
                        }
                    }
                }
            }
            return(instanceList);
        }
 /// <summary>
 /// Removes the children.
 /// </summary>
 public void RemoveChildren()
 {
     if (childrenId != null && childrenId.Count > 0)
     {
         foreach (Guid oneChild in childrenId)
         {
             StateMachineWorkflowInstance childInstance = WorkflowRuntime.Current.GetService <IWorkflowPersistService>().GetWorkflowInstance(oneChild);
             childInstance.RemoveChildren();
             WorkflowRuntime.Current.GetService <IWorkflowPersistService>().DeleteWorkflowInstance(childInstance);
         }
         this.childrenId = null;
     }
 }
 /// <summary>
 /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
 /// </summary>
 /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
 /// <returns>
 ///     <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
 /// </returns>
 /// <exception cref="T:System.NullReferenceException">
 /// The <paramref name="obj"/> parameter is null.
 /// </exception>
 public override bool Equals(object obj)
 {
     if (obj is StateMachineWorkflowInstance)
     {
         StateMachineWorkflowInstance o = (StateMachineWorkflowInstance)obj;
         if (o.id == this.id)
         {
             return(true);
         }
         return(false);
     }
     return(false);
 }
Beispiel #10
0
        /// <summary>
        /// 判断指定实例是否需要满足过滤条件,满足则返回True,否则返回False
        /// </summary>
        /// <param name="instance">工作流实例</param>
        /// <param name="role">用户的审批角色</param>
        /// <param name="userIdentity">用户的身份</param>
        /// <returns>满足则返回True,否则返回False</returns>
        protected override bool IsMatch(StateMachineWorkflowInstance instance, ApprovalRole role, IUserIdentity userIdentity)
        {
            List <ApprovalRecord> records = WorkflowRuntime.Current.SaveService.GetRecord(instance.WorkflowName, instance.EaId);

            foreach (ApprovalRecord record in records)
            {
                if (record.OperatorId == userIdentity.GetUserId() &&
                    record.OperatorRole == role.Name)
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #11
0
 /// <summary>
 /// 判断指定实例是否需要满足过滤条件,满足则返回True,否则返回False
 /// </summary>
 /// <param name="instance">工作流实例</param>
 /// <param name="role">用户的审批角色</param>
 /// <param name="userIdentity">用户的身份</param>
 /// <returns>满足则返回True,否则返回False</returns>
 protected override bool IsMatch(StateMachineWorkflowInstance instance, ApprovalRole role, IUserIdentity userIdentity)
 {
     if (string.IsNullOrEmpty(this.StateNames))
     {
         throw new ApplicationException("请配置需要过滤的状态名");
     }
     string[] stateList = this.StateNames.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
     foreach (string one in stateList)
     {
         if (instance.CurrentState.Name.Equals(one.Trim(), StringComparison.OrdinalIgnoreCase))
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #12
0
 /// <summary>
 /// 判断指定实例是否需要满足过滤条件,满足则返回True,否则返回False
 /// </summary>
 /// <param name="instance">工作流实例</param>
 /// <param name="role">用户的审批角色</param>
 /// <param name="userIdentity">用户的身份</param>
 /// <returns>
 /// 满足则返回True,否则返回False
 /// </returns>
 internal bool InternalIsMatch(StateMachineWorkflowInstance instance, ApprovalRole role, IUserIdentity userIdentity)
 {
     if (instance == null)
     {
         throw new ArgumentNullException("instance");
     }
     if (role == null)
     {
         throw new ArgumentNullException("role");
     }
     if (userIdentity == null)
     {
         throw new ArgumentNullException("userIdentity");
     }
     return(IsMatch(instance, role, userIdentity));
 }
        /// <summary>
        /// 获取实例的操作项目集合,方法是从工作流配置xml文件中定义的操作(动作),如果是作为工具条形式提取,那么自动<see cref="GetToolbarAddtionActionItems"/>方法,附加额外的自定义项目.
        /// </summary>
        /// <param name="instance">某实例</param>
        /// <param name="isTooBar">if set to <c>true</c> 工具条形式提取.</param>
        /// <returns></returns>
        public List <ITaskActionItem> GetInstanceActionItems(StateMachineWorkflowInstance instance, bool isTooBar)
        {
            List <ITaskActionItem> items = new List <ITaskActionItem>();
            List <ApprovalRole>    roles = WorkflowUtility.GetUserRoles(instance.WorkflowName, userIdentity.GetUserId());

            //如是任务栏,则先添加任务栏相关的动作项目
            if (isTooBar)
            {
                items.AddRange(GetToolbarAddtionActionItems(instance));
            }
            //遍历当前用户所有角色,添加每个角色对应的动作项目
            foreach (ApprovalRole role in roles)
            {
                items.AddRange(GetInstanceActionItems(instance, role));
            }
            return(items);
        }
 /// <summary>
 /// Executes the specified activity.
 /// </summary>
 /// <param name="activity">The activity.</param>
 protected override void ExecuteActivity(Activity activity)
 {
     activity.OnInitialize(this);
     //执行当前动作
     activity.OnExecute(this);
     //如果工作流动作完成,那么移动到下一步状态
     if (activity.ExecutionStatus == ActivityExecutionStatus.Closed)
     {
         //添加当前动作到动作列表中
         executedActivities.Add(activity);
         if (activity is IBranchAction)
         {
             //分支动作,需要获取分支执行后选定的状态
             IBranchAction branch = (IBranchAction)activity;
             MoveOn(branch.GetSelectedState());
         }
         else
         {
             //顺序动作,从动作针对的事件名称中获取状态
             ApprovalEvent currentEvent = CurrentState.GetEventByName(activity.EventName);
             MoveOn(currentEvent.NextStateNames[0]);
         }
     }
     //保存
     Save();
     if (this.stateRecordNames.Count > 0)
     {
         WorkflowRuntime.Current.OnWorkflowExecuted(new StateChangedEventArgs(this, this.stateRecordNames[stateRecordNames.Count - 1], stateName));
     }
     //如果是子流程的执行完成,那么还有判断其父流程是否也已经执行完毕,如果执行完毕,那么设置其父流程的下一步状态
     if (this.CurrentStatus == WorkflowExecutionStatus.Closed && parentId != null && parentId != Guid.Empty)
     {
         StateMachineWorkflowInstance parentInstance = (StateMachineWorkflowInstance)WorkflowRuntime.Current.GetInstance(parentId);
         parentInstance.OnChildFinished(this);
     }
     else if (this.CurrentStatus == WorkflowExecutionStatus.Aborted)
     {
         WorkflowRuntime.Current.OnWorkflowTerminated(new StateChangedEventArgs(this, this.stateRecordNames[stateRecordNames.Count - 1], stateName));
     }
     if (IsEnd())
     {
         WorkflowRuntime.Current.OnWorkflowCompleted(new StateChangedEventArgs(this, this.stateRecordNames[stateRecordNames.Count - 1], stateName));
     }
 }
        /// <summary>
        /// 从任务类表中除去已经指派给他人专办的项目
        /// </summary>
        /// <param name="instanceList">The instance list.</param>
        protected virtual void RemoveAssignedInstance(List <StateMachineWorkflowInstance> instanceList)
        {
            //去除已指定他人专办的实例
            for (int i = instanceList.Count - 1; i >= 0; i--)
            {
                StateMachineWorkflowInstance instance       = instanceList[i];
                List <ApprovalAssignment>    assignmentList = approvalService.GetAssignmentByAssignToRole(this.workflow.Name, rules.UserRole.Name, instance.Id, instance.StateName);

                //是否已指定同角色中他人专办标识
                bool isAssignedToCurrentUser = true;
                if (assignmentList.Count > 0)
                {
                    foreach (ApprovalAssignment assignment in assignmentList)
                    {
                        if (assignment.ToUserId != null)
                        {
                            if (assignment.ToUserId.ToLower() == userIdentity.GetUserId().ToLower())
                            {
                                isAssignedToCurrentUser = true;
                                break;
                            }
                            //如果遍历所有委派列表没有当前用互的记录,则该任务未指定当前用户
                            else
                            {
                                isAssignedToCurrentUser = false;
                            }
                        }
                    }
                }
                //无指定记录则某认指定了所有人
                else
                {
                    isAssignedToCurrentUser = true;
                }
                //已指定专办标识为假,从List中除去该实例
                if (!isAssignedToCurrentUser)
                {
                    instanceList.Remove(instance);
                }
            }
        }
Beispiel #16
0
        /// <summary>
        /// 判断指定实例是否需要满足过滤条件,满足则返回True,否则返回False
        /// </summary>
        /// <param name="instance">工作流实例</param>
        /// <param name="role">用户的审批角色</param>
        /// <param name="userIdentity">用户的身份</param>
        /// <returns>满足则返回True,否则返回False</returns>
        protected override bool IsMatch(StateMachineWorkflowInstance instance, ApprovalRole role, IUserIdentity userIdentity)
        {
            //最后一个Activity的执行者是否为当前用户如果是返回false
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }
            StateMachineWorkflowInstance stateMachine = (StateMachineWorkflowInstance)WorkflowRuntime.Current.GetInstance(instance.Id);

            //最后一个activity为空 返回true
            if (stateMachine.LastActivity == null)
            {
                return(true);
            }
            //最后一个activity执行者与用户身份和角色匹配,返回false
            if (string.Equals(stateMachine.LastActivity.UserId.Trim(), userIdentity.GetUserId().Trim(), StringComparison.OrdinalIgnoreCase) &&
                string.Equals(stateMachine.LastActivity.UserApprovalRole, role.Name))
            {
                return(false);
            }
            return(true);
        }
Beispiel #17
0
        /// <summary>
        /// 执行审批操作时进行的相关审批记录操作,如果要用不同的记录,必须重写该方法
        /// </summary>
        /// <param name="instance">The instance.</param>
        protected virtual void TrackExecute(WorkflowInstance instance)
        {
            ApprovalRecord   record  = new ApprovalRecord();
            IIdentityService service = WorkflowRuntime.Current.GetService <IIdentityService>();

            if (service == null)
            {
                throw new WorkflowExecuteExeception("身份信息提供服务为空");
            }
            IUserIdentity userInfo = service.GetUserIdentity();

            record.OperatorTime       = DateTime.Now;
            record.WorkflowInstanceId = instance.Id;
            string currentUserId = userInfo.GetUserId();

            record.OperatorId       = userId;
            record.OperatorName     = userInfo.GetUserName();
            record.OperatorUnitCode = userInfo.GetUserUnitCode();

            ResetRecordAndUserId(record);

            record.OperatorRole = this.UserApprovalRole;
            record.EaId         = instance.EaId;
            StateMachineWorkflowInstance stateMachine = instance as StateMachineWorkflowInstance;

            //如果没有定义活动的名称,那么从时间的描述中取出来
            if (string.IsNullOrEmpty(this.activityName))
            {
                this.activityName = stateMachine.CurrentState.GetEventByName(eventName).Description;
            }
            record.ApprovalType = this.ActivityName;
            record.StateName    = stateMachine.CurrentState.Description;
            record.SolutionInfo = solutionInfo;
            WorkflowRuntime.Current.GetService <IApprovalSaveService>().InsertRecord(record);
            this.recordId = record.Id;
        }
Beispiel #18
0
 /// <summary>
 /// 插入一条新的工作流
 /// </summary>
 /// <param name="instance"></param>
 StateMachineWorkflowInstance IWorkflowPersistService.InsertWorkflowInstance(StateMachineWorkflowInstance instance)
 {
     return(InsertWorkflowInstance(instance));
 }
Beispiel #19
0
 /// <summary>
 /// 判断指定实例是否需要满足过滤条件,满足则返回True,否则返回False
 /// </summary>
 /// <param name="instance">工作流实例</param>
 /// <param name="role">用户的审批角色</param>
 /// <param name="userIdentity">用户的身份</param>
 /// <returns>满足则返回True,否则返回False</returns>
 protected override bool IsMatch(StateMachineWorkflowInstance instance, ApprovalRole role, IUserIdentity userIdentity)
 {
     return(instance.CurrentState.Name == "Receiving" || instance.CurrentState.Name == "HandoutApplyPassport");
 }
 /// <summary>
 /// 获取实例中,指定的角色的可以执行的操作项目集合.即:从工作流配置文件xml中,如何提取可执行操作.
 /// </summary>
 /// <param name="instance">某实例</param>
 /// <param name="role">某角色</param>
 /// <returns></returns>
 public abstract List <ITaskActionItem> GetInstanceActionItems(StateMachineWorkflowInstance instance, ApprovalRole role);
 /// <summary>
 ///  获取工具栏附加操作项目.在提取工作流实例可执行的操作集合,并呈现为工具条时(如:在立项详情页面的下面显示可执行的动作),除了在xml文件中定义的操作(动作)外,需要额外附加的动作项目.
 /// </summary>
 /// <param name="instance">某实例</param>
 /// <returns></returns>
 public abstract List <ITaskActionItem> GetToolbarAddtionActionItems(StateMachineWorkflowInstance instance);
 /// <summary>
 ///获取某实例查询结果的操作项目集合
 /// </summary>
 /// <param name="instance">某实例</param>
 /// <returns></returns>
 public abstract List <ITaskActionItem> GetQueryPageViewActionItems(StateMachineWorkflowInstance instance);
 /// <summary>
 /// Initializes a new instance of the <see cref="InstanceWithRole"/> class.
 /// </summary>
 /// <param name="instance">The instance.</param>
 /// <param name="role">The role.</param>
 /// <param name="isOwner">当前的实例是否是用户自己的实例,还是别人指派实例</param>
 public InstanceWithRole(StateMachineWorkflowInstance instance, ApprovalRole role, bool isOwner)
 {
     this.role     = role;
     this.instance = instance;
     this.isOwner  = isOwner;
 }
Beispiel #24
0
 /// <summary>
 /// 判断指定实例是否需要满足过滤条件,满足则返回True,否则返回False
 /// </summary>
 /// <param name="instance">工作流实例</param>
 /// <param name="role">用户的审批角色</param>
 /// <param name="userIdentity">用户的身份</param>
 /// <returns>
 /// 满足则返回True,否则返回False
 /// </returns>
 protected abstract bool IsMatch(StateMachineWorkflowInstance instance, ApprovalRole role, IUserIdentity userIdentity);
Beispiel #25
0
 /// <summary>
 /// 判断指定实例是否需要满足过滤条件,满足则返回True,否则返回False
 /// </summary>
 /// <param name="instance">工作流实例</param>
 /// <param name="role">用户的审批角色</param>
 /// <param name="userIdentity">用户的身份</param>
 /// <returns>满足则返回True,否则返回False</returns>
 protected override bool IsMatch(StateMachineWorkflowInstance instance, ApprovalRole role, IUserIdentity userIdentity)
 {
     return(instance.IsTerminated());
 }
Beispiel #26
0
 /// <summary>
 /// 插入一条新的工作流
 /// </summary>
 /// <param name="instance"></param>
 protected abstract StateMachineWorkflowInstance InsertWorkflowInstance(StateMachineWorkflowInstance instance);
Beispiel #27
0
 /// <summary>
 /// 判断指定实例是否需要满足过滤条件,满足则返回True,否则返回False
 /// </summary>
 /// <param name="instance">工作流实例</param>
 /// <param name="role">用户的审批角色</param>
 /// <param name="userIdentity">用户的身份</param>
 /// <returns>满足则返回True,否则返回False</returns>
 protected override bool IsMatch(StateMachineWorkflowInstance instance, ApprovalRole role, IUserIdentity userIdentity)
 {
     return(WorkflowRuntime.Current.GetService <IWorkflowSecurityService>().IsMyTaskInstance(instance, userIdentity.GetUserId()));
 }