예제 #1
0
        /// <summary>
        /// 获取指定工作流、角色、时间段的实例集合
        /// </summary>
        /// <param name="workflowName">流程名称</param>
        /// <param name="userIdentity">用户身份</param>
        /// <param name="role">审批角色</param>
        /// <param name="startDate">时间段起始时间</param>
        /// <param name="endDate">时间段截止时间</param>
        /// <returns></returns>
        public InstanceCollection Distill(string workflowName, IUserIdentity userIdentity, ApprovalRole role, DateTime startDate, DateTime endDate)
        {
            //提取实例集合的过程,先遍历每一个提取者对象进行实例提取,后遍历每个过滤器进行实例过滤,最后返回剩余的实例的集合
            InstanceCollection   instances = new InstanceCollection();
            StateMachineWorkflow workflow  = (StateMachineWorkflow)WorkflowRuntime.Current.GetService <IWorkFlowDefinePersistService>().GetWorkflowDefine(workflowName);

            foreach (InstanceDistiller distiller in InstanceDistillers)
            {
                instances.AddRange(distiller.InternalDistill(workflowName, userIdentity, role, startDate, endDate));
            }
            if (Filters != null)
            {
                foreach (InstanceFilter filter in Filters)
                {
                    if (filter is IInstanceCollectionFilter)
                    {
                        IInstanceCollectionFilter collFilter = (IInstanceCollectionFilter)filter;
                        collFilter.Filter(instances, role, userIdentity);
                    }
                    else
                    {
                        for (int i = instances.Count - 1; i >= 0; i--)
                        {
                            if (filter.InternalIsMatch(instances[i].Instance, role, userIdentity))
                            {
                                instances.RemoveAt(i);
                            }
                        }
                    }
                }
            }
            return(instances);
        }
예제 #2
0
        /// <summary>
        /// 获取某用户对某流程的角色-实例集合字典
        /// </summary>
        /// <param name="workflowName">流程名称</param>
        /// <param name="userId">用户Id</param>
        /// <param name="startDate">其实时间</param>
        /// <param name="endDate">终止时间</param>
        /// <returns></returns>
        private InstanceCollection DistillInstances(string workflowName, string userId, DateTime startDate, DateTime endDate)
        {
            List <ApprovalRole> roles        = WorkflowUtility.GetUserRoles(workflowName, userId);
            IUserIdentity       userIdentity = identityService.GetUserIdentity(userId);
            InstanceCollection  rtn          = new InstanceCollection();

            //对本流程中每一个角色遍历得到实例集合后合并入角色-实例集合字典
            foreach (ApprovalRole role in roles)
            {
                rtn.AddRange(DistillInstances(workflowName, userId, role.Name, startDate, endDate));
            }
            return(rtn);
        }
예제 #3
0
        /// <summary>
        /// 获取某用户对某流程的任务列表
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="startDate">其实时间</param>
        /// <param name="endDate">终止时间</param>
        /// <returns></returns>
        public InstanceCollection DistillInstances(string userId, DateTime startDate, DateTime endDate)
        {
            InstanceCollection instances = new InstanceCollection();

            foreach (string workflowName in this.workflowNames)
            {
                //对每一个流程中每一个角色遍历得到实例集合后合并入角色-实例集合字典
                List <ApprovalRole> roles = WorkflowUtility.GetUserRoles(workflowName, userId);
                foreach (ApprovalRole role in roles)
                {
                    instances.AddRange(DistillInstances(workflowName, userId, role.Name, startDate, endDate));
                }
            }
            return(instances);
        }
예제 #4
0
        /// <summary>
        /// 获取角色和对应实例集合的键-值对
        /// </summary>
        /// <param name="workflowName">流程名称</param>
        /// <param name="userId">用户Id</param>
        /// <param name="roleName">角色名称</param>
        /// <param name="startDate">时间段起始时间</param>
        /// <param name="endDate">时间段截止时间</param>
        /// <returns></returns>
        private InstanceCollection DistillInstances(string workflowName, string userId, string roleName, DateTime startDate, DateTime endDate)
        {
            IUserIdentity userIdentity = identityService.GetUserIdentity(userId);
            //获取流程对应的审批角色对象,并从角色-提取者字典中获取角色对应的提取者
            InstanceCollection instances = new InstanceCollection();
            ApprovalRole       role      = WorkflowUtility.GetUserRoleByName(workflowName, roleName);

            if (role != null)
            {
                //用户不在该角色
                if (!userInRole.IsUserInRole(userIdentity.GetUserId(), role.Name))
                {
                    throw new ApplicationException(string.Format("{0} is not in role {1}", userIdentity.GetUserId(), role.Name));
                }
                //取得角色的任务提取器
                TaskDistiller distiller = GetRoleDistiller(roleName);
                instances.AddRange(distiller.Distill(workflowName, userIdentity, role, startDate, endDate));
            }
            return(instances);
        }