Example #1
0
        public int StartProcess(string processName, int startUserId, int relativeObjectId)
        {
            int num2;

            try
            {
                int num;
                ProcessInstanceCacheFactory runtimeContext = new ProcessInstanceCacheFactory(this._context);
                SysProcess    processCache = runtimeContext.PCacheFactory.GetProcessCache(processName);
                ProcessEngine engine       = new ProcessEngine(runtimeContext, processCache);
                if (processCache.ProcessCategory == 2)
                {
                    num = engine.StartFormProcess(startUserId, relativeObjectId);
                }
                else
                {
                    num = engine.StartProcess(startUserId, relativeObjectId);
                }
                num2 = num;
            }
            catch (Exception exception)
            {
                AppLogHelper.Error(string.Format("启动流程[{0}], obj={1}失败", processName, relativeObjectId), exception);
                throw exception;
            }
            return(num2);
        }
Example #2
0
        public List <SysActivity> GetNextActivityList(string processName)
        {
            List <SysActivity> list2;

            try
            {
                List <SysActivity> list         = new List <SysActivity>();
                SysProcess         processCache = this._processCache.GetProcessCache(processName);
                if (processCache == null)
                {
                    throw new ApplicationException(string.Format("流程名称[{0}]不正确", processName));
                }
                SysActivity activity = processCache.Activities.FirstOrDefault <SysActivity>(p => p.ActivityType == 1);
                if (activity != null)
                {
                    list = (from p in activity.FromTransitions select p.PostActivity).ToList <SysActivity>();
                }
                list2 = list;
            }
            catch (Exception exception)
            {
                AppLogHelper.Error(string.Format("GetNextActivityList,processName=[{0}]失败", processName), exception);
                throw exception;
            }
            return(list2);
        }
Example #3
0
 public void CompleteWorkItemAsync(int workItemId, List <IApproveUser> nextApproveUserList)
 {
     try
     {
         this.UpdateWorkItemAsCompleting(workItemId);
         int num = this._context.GetNextIdentity_Int(false);
         SysWorkflowMessage msg = new SysWorkflowMessage {
             MessageId   = num,
             MessageType = WorkflowMessageTypeEnum.CompletingWorkItem,
             WorkItemId  = workItemId,
             State       = SysWorkflowMessageStateEnum.Inited,
             CreateTime  = DateTime.Now
         };
         if ((nextApproveUserList != null) && (nextApproveUserList.Count > 0))
         {
             msg.NextApproveUserList.AddRange(nextApproveUserList);
         }
         this.SaveWorkflowMessage(msg);
     }
     catch (Exception exception)
     {
         AppLogHelper.Error(exception, "完成工作项失败,workitem_id={0}", new object[] { workItemId });
         throw;
     }
 }
 private static void ProcessError(SysWorkflowMessage msg, Exception ex, string connectionStringOrName)
 {
     if (string.IsNullOrWhiteSpace(connectionStringOrName))
     {
         connectionStringOrName = DataContext.BizConnectionStringDefault;
     }
     try
     {
         using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress))
         {
             using (BizDataContext context = new BizDataContext(connectionStringOrName, true))
             {
                 if (msg.State != SysWorkflowMessageStateEnum.Running)
                 {
                     throw new Exception(string.Format("消息ID:{0}的状态不为Running", msg.MessageId));
                 }
                 msg.State            = SysWorkflowMessageStateEnum.Error;
                 msg.LastErrorMessage = ex.Message;
                 string sql = string.Format("UPDATE SysWorkflowMessage SET STATE = {0}, LastErrorMessage = {1} WHERE MessageId = {2} AND (STATE = {3} or STATE = {4}) ", new object[] { context.AddPrefixToParameterName("NewState"), context.AddPrefixToParameterName("LastErrorMessage"), context.AddPrefixToParameterName("MessageId"), context.AddPrefixToParameterName("OldState1"), context.AddPrefixToParameterName("OldState2") });
                 if (context.ExecuteNonQuery(sql, new DbParameter[] { context.CreateParameterWithPrefix("NewState", Convert.ToInt32(SysWorkflowMessageStateEnum.Error), typeof(int)), context.CreateParameterWithPrefix("LastErrorMessage", ex.Message, typeof(string)), context.CreateParameterWithPrefix("MessageId", msg.MessageId, typeof(int)), context.CreateParameterWithPrefix("OldState1", Convert.ToInt32(SysWorkflowMessageStateEnum.Running), typeof(int)), context.CreateParameterWithPrefix("OldState2", Convert.ToInt32(SysWorkflowMessageStateEnum.Inited), typeof(int)) }) <= 0)
                 {
                     AppLogHelper.Information("将工作流消息更改为错误状态时更新行数为0: MessageId={0}", new object[] { msg.MessageId });
                 }
             }
             scope.Complete();
         }
         Console.WriteLine(ex.Message);
     }
     catch (Exception exception)
     {
         AppLogHelper.Error(exception, "将工作流消息更改为错误状态时失败: MessageId={0}", new object[] { msg.MessageId });
         Console.WriteLine(exception.Message);
     }
 }
Example #5
0
        public int StartProcessAsync(long processId, int startUserId, int relativeObjectId)
        {
            SysProcess processCache = this._processCache.GetProcessCache(processId);

            if (processCache == null)
            {
                string errorInfo = string.Format("未找到流程,id={0}", processId);
                AppLogHelper.Error(startUserId, errorInfo, relativeObjectId.ToString());
                throw new ApplicationException(errorInfo);
            }
            return(this.StartProcessAsync(processCache, startUserId, relativeObjectId, null));
        }
Example #6
0
        private int StartProcessAsync(SysProcess process, int startUserId, int relativeObjectId, List <IApproveUser> nextApproveUserList)
        {
            int num3;

            try
            {
                int num = this._context.GetNextIdentity_Int(false);
                SysProcessInstance instance = new SysProcessInstance {
                    StartTime         = new DateTime?(DateTime.Now),
                    InstanceStatus    = 0,
                    ObjectId          = relativeObjectId,
                    ProcessId         = new long?(process.ProcessId),
                    ProcessInstanceId = num,
                    StartUserId       = new int?(startUserId)
                };
                if (process.ProcessCategory == 2)
                {
                    instance.FormInstanceId = new int?(relativeObjectId);
                    T_User user = this._context.FindById <T_User>(new object[] { startUserId });
                    if (user != null)
                    {
                        T_Department department = this._context.FindById <T_Department>(new object[] { user.Department_ID });
                        if (department != null)
                        {
                            instance.StartDeptId = new int?(department.Department_ID);
                        }
                    }
                }
                int num2 = this._context.GetNextIdentity_Int(false);
                SysWorkflowMessage msg = new SysWorkflowMessage {
                    ProcessId         = process.ProcessId,
                    ProcessInstanceId = num,
                    CreateTime        = DateTime.Now,
                    MessageId         = num2,
                    MessageType       = WorkflowMessageTypeEnum.StartingProcess,
                    OperationUserId   = startUserId,
                    State             = SysWorkflowMessageStateEnum.Inited
                };
                if ((nextApproveUserList != null) && (nextApproveUserList.Count > 0))
                {
                    msg.NextApproveUserList.AddRange(nextApproveUserList);
                }
                this.SaveWorkflowMessage(msg);
                this._context.Insert(instance);
                num3 = num;
            }
            catch (Exception exception)
            {
                AppLogHelper.Error(startUserId, exception, "启动流程[{0}]失败, 流程id={1}, 对象id={2}", new object[] { process.ProcessId, process.ProcessName, relativeObjectId });
                throw;
            }
            return(num3);
        }
Example #7
0
        public int StartProcessAsync(string processName, int startUserId, int relativeObjectId, List <IApproveUser> nextApproveUserList)
        {
            SysProcess processCache = this._processCache.GetProcessCache(processName);

            if (processCache == null)
            {
                string errorInfo = string.Format("未找到流程name={0}", processName);
                AppLogHelper.Error(startUserId, errorInfo, relativeObjectId.ToString());
                throw new ApplicationException(errorInfo);
            }
            return(this.StartProcessAsync(processCache, startUserId, relativeObjectId, nextApproveUserList));
        }
Example #8
0
 public void CompleteWorkItemSelf(int workItemId)
 {
     try
     {
         ProcessInstanceCacheFactory runtimeContext = new ProcessInstanceCacheFactory(this._context);
         SysProcessInstance          processInstanceCacheByWorkItem = runtimeContext.GetProcessInstanceCacheByWorkItem(workItemId);
         new ProcessEngine(runtimeContext, processInstanceCacheByWorkItem).CompleteWorkItemSelf(workItemId);
     }
     catch (Exception exception)
     {
         AppLogHelper.Error(string.Format("完成【普通流程】的工作项,仅完成自身[{0}]失败", workItemId), exception);
         throw exception;
     }
 }
Example #9
0
 public void RejectApproveWorkItem(int workItemId, string approveComment, long nextActivityId)
 {
     try
     {
         ProcessInstanceCacheFactory runtimeContext = new ProcessInstanceCacheFactory(this._context);
         SysProcessInstance          processInstanceCacheByWorkItem = runtimeContext.GetProcessInstanceCacheByWorkItem(workItemId);
         new ProcessEngine(runtimeContext, processInstanceCacheByWorkItem).RejectApproveWorkItem(workItemId, approveComment, nextActivityId);
     }
     catch (Exception exception)
     {
         AppLogHelper.Error(string.Format("完成【签核流程】的工作项[{0}]失败", workItemId), exception);
         throw exception;
     }
 }
Example #10
0
 public void CompleteApproveWorkItem(int workItemId, ApproveResultEnum approveResult, string approveComment, List <IApproveUser> nextApproveUserList, bool addUser = false, int?addUserId = new int?())
 {
     try
     {
         ProcessInstanceCacheFactory runtimeContext = new ProcessInstanceCacheFactory(this._context);
         SysProcessInstance          processInstanceCacheByWorkItem = runtimeContext.GetProcessInstanceCacheByWorkItem(workItemId);
         new ProcessEngine(runtimeContext, processInstanceCacheByWorkItem).CompleteApproveWorkItem(workItemId, approveResult, approveComment, nextApproveUserList, addUser, addUserId);
     }
     catch (Exception exception)
     {
         AppLogHelper.Error(string.Format("完成【签核流程】的工作项[{0}]失败", workItemId), exception);
         throw exception;
     }
 }
Example #11
0
 public void CancelProcess(int processInstanceId)
 {
     try
     {
         ProcessInstanceCacheFactory runtimeContext       = new ProcessInstanceCacheFactory(this._context);
         SysProcessInstance          processInstanceCache = runtimeContext.GetProcessInstanceCache(processInstanceId);
         new ProcessEngine(runtimeContext, processInstanceCache).CancelProcess(processInstanceId);
     }
     catch (Exception exception)
     {
         AppLogHelper.Error(string.Format("撤消流程实例[{0}]失败", processInstanceId), exception);
         throw;
     }
 }
Example #12
0
 private void secondTimer_Elapsed(object sender, ElapsedEventArgs e)
 {
     try
     {
         if (!this.mainTimer.Enabled)
         {
             this.mainTimer.Start();
         }
     }
     catch (Exception exception)
     {
         AppLogHelper.Error(exception);
         this.Init();
     }
 }
Example #13
0
        public virtual IDepartment GetDepartmentById(int departmentId)
        {
            IDepartment dept;

            try
            {
                dept = this.GetDept(departmentId);
            }
            catch (Exception exception)
            {
                AppLogHelper.Error(exception);
                throw exception;
            }
            return(dept);
        }
Example #14
0
        public virtual IUser GetUserById(int userId)
        {
            IUser user;

            try
            {
                user = this.GetUser(userId);
            }
            catch (Exception exception)
            {
                AppLogHelper.Error(exception);
                throw exception;
            }
            return(user);
        }
Example #15
0
        public int StartProcess(string processName, int startUserId, int relativeObjectId, List <IApproveUser> nextApproveUserList)
        {
            int num2;

            try
            {
                ProcessInstanceCacheFactory runtimeContext = new ProcessInstanceCacheFactory(this._context);
                SysProcess processCache = runtimeContext.PCacheFactory.GetProcessCache(processName);
                num2 = new ProcessEngine(runtimeContext, processCache).StartProcess(startUserId, relativeObjectId, nextApproveUserList);
            }
            catch (Exception exception)
            {
                AppLogHelper.Error(string.Format("启动流程[{0}], obj={1}失败", processName, relativeObjectId), exception);
                throw exception;
            }
            return(num2);
        }
Example #16
0
        public virtual List <IUser> GetUsers()
        {
            List <IUser> list2;
            DataContext  ctx = this.GetContext();

            try
            {
                list2 = ctx.FetchAll <T_User>().Cast <IUser>().ToList <IUser>();
            }
            catch (Exception exception)
            {
                AppLogHelper.Error(exception);
                throw exception;
            }
            finally
            {
                this.ReleaseContext(ctx);
            }
            return(list2);
        }
Example #17
0
        public virtual List <IRole> GetRoles()
        {
            List <IRole> list2;
            DataContext  ctx = this.GetContext();

            try
            {
                list2 = ctx.Set <T_Role>().Cast <IRole>().ToList <IRole>();
            }
            catch (Exception exception)
            {
                AppLogHelper.Error(exception);
                throw exception;
            }
            finally
            {
                this.ReleaseContext(ctx);
            }
            return(list2);
        }
Example #18
0
        public virtual IUser GetDepartmentManager(int departmentId)
        {
            IUser user2;

            try
            {
                T_Department dept = this.GetDept(departmentId);
                if ((dept != null) && dept.Manager_ID.HasValue)
                {
                    return(this.GetUser(dept.Manager_ID.Value));
                }
                user2 = null;
            }
            catch (Exception exception)
            {
                AppLogHelper.Error(exception);
                throw exception;
            }
            return(user2);
        }
Example #19
0
        public virtual List <IDepartment> GetChildDepartments(int departmentId)
        {
            List <IDepartment> list2;
            DataContext        ctx = this.GetContext();

            try
            {
                string condition = string.Format("Parent_ID = {0}", departmentId);
                list2 = ctx.Where <T_Department>(condition, new DbParameter[0]).Cast <IDepartment>().ToList <IDepartment>();
            }
            catch (Exception exception)
            {
                AppLogHelper.Error(exception);
                throw exception;
            }
            finally
            {
                this.ReleaseContext(ctx);
            }
            return(list2);
        }
Example #20
0
        public virtual List <IUser> GetDepartmentRoleUsers(int departmentId, int roleId)
        {
            List <IUser> list;
            DataContext  ctx = this.GetContext();

            try
            {
                string sql = string.Format("select a.* from T_User a left join T_User_Role b on a.User_ID = b.User_ID where b.Role_ID = {0} and a.Department_ID = {1}", roleId, departmentId);
                list = ctx.ExecuteObjectSet <T_User>(sql, new DbParameter[0]).Cast <IUser>().ToList <IUser>();
            }
            catch (Exception exception)
            {
                AppLogHelper.Error(exception);
                throw exception;
            }
            finally
            {
                this.ReleaseContext(ctx);
            }
            return(list);
        }
Example #21
0
        public virtual List <IRole> GetUserRoles(int userId)
        {
            List <IRole> list;
            DataContext  ctx = this.GetContext();

            try
            {
                string sql = string.Format("select a.* from T_Role a left join T_User_Role b on a.Role_ID = b.Role_ID where b.User_ID = {0}", userId);
                list = ctx.ExecuteObjectSet <T_Role>(sql, new DbParameter[0]).Cast <IRole>().ToList <IRole>();
            }
            catch (Exception exception)
            {
                AppLogHelper.Error(exception);
                throw exception;
            }
            finally
            {
                this.ReleaseContext(ctx);
            }
            return(list);
        }
Example #22
0
        public virtual bool IsRootDepartment(int departmentId)
        {
            bool flag2;

            try
            {
                bool         flag = false;
                T_Department dept = this.GetDept(departmentId);
                if (!(dept.Parent_ID.HasValue && (dept.Parent_ID.Value != 0)))
                {
                    flag = true;
                }
                flag2 = flag;
            }
            catch (Exception exception)
            {
                AppLogHelper.Error(exception);
                throw exception;
            }
            return(flag2);
        }
Example #23
0
 public bool DeleteRoleFunction(int roleId)
 {
     try
     {
         using (BizDataContext context = new BizDataContext(true))
         {
             List <T_Role_Function> list = context.Where <T_Role_Function>(r => r.Role_ID == roleId);
             if ((list != null) && (list.Count > 0))
             {
                 foreach (T_Role_Function function in list)
                 {
                     context.Delete(function);
                 }
             }
         }
         return(true);
     }
     catch (Exception exception)
     {
         AppLogHelper.Error(exception);
         return(false);
     }
 }
Example #24
0
        public List <SysActivity> GetNextActivityList(int workItemId)
        {
            List <SysActivity> list2;

            try
            {
                SysWorkItem        item;
                List <SysActivity> list = new List <SysActivity>();
                new ProcessInstanceCacheFactory(this._context).GetProcessInstanceCacheByWorkItem(workItemId, out item);
                SysActivity activity = item.ActivityInstance.Activity;
                if (activity != null)
                {
                    list = (from p in activity.FromTransitions select p.PostActivity).ToList <SysActivity>();
                }
                list2 = list;
            }
            catch (Exception exception)
            {
                AppLogHelper.Error(string.Format("GetNextActivityList,workItemId=[{0}]失败", workItemId), exception);
                throw exception;
            }
            return(list2);
        }
Example #25
0
 public void CompleteApproveWorkItemAsync(int workItemId, ApproveResultEnum approveResult, string approveComment, List <IApproveUser> nextApproveUserList, bool addUser = false, int?addUserId = new int?())
 {
     try
     {
         this.UpdateWorkItemAsCompleting(workItemId);
         int num = this._context.GetNextIdentity_Int(false);
         SysWorkflowMessage message = new SysWorkflowMessage {
             MessageId      = num,
             MessageType    = WorkflowMessageTypeEnum.CompletingApproveWorkItem,
             WorkItemId     = workItemId,
             State          = SysWorkflowMessageStateEnum.Inited,
             CreateTime     = DateTime.Now,
             ApproveResult  = approveResult,
             ApproveComment = approveComment,
             AddUser        = addUser,
             AddUserId      = addUserId
         };
         if ((nextApproveUserList != null) && (nextApproveUserList.Count > 0))
         {
             foreach (IApproveUser user in nextApproveUserList)
             {
                 MessageApproveUser user2 = new MessageApproveUser(user)
                 {
                     WorkflowMessageId    = num,
                     MessageApproveUserId = this._context.GetNextIdentity_Int(false)
                 };
                 this._context.Insert(user2);
             }
         }
         this._context.Insert(message);
     }
     catch (Exception exception)
     {
         AppLogHelper.Error(exception, "完成签核工作项失败,workitem_id={0}", new object[] { workItemId });
         throw;
     }
 }
        public static List <SelectControlData> GetData(DataType DataType, Type t, object parameter, int currentUseID)
        {
            List <SelectControlData> list     = new List <SelectControlData>();
            List <NameValues>        userList = new List <NameValues>();

            using (BizDataContext context = new BizDataContext(true))
            {
                if (DataType == DataType.All)
                {
                    List <T_User> list3 = context.Set <T_User>().ToList <T_User>();
                    userList = (from user in context.Set <T_User>()
                                join dep in context.Set <T_Department>() on user.Department_ID equals(int?) dep.Department_ID
                                where (user.State == 0) && (dep.State == 0)
                                orderby user.User_Name
                                select new NameValues {
                        Id = user.User_ID, Name = user.User_Name, DepID = user.Department_ID.ToInt(), DepName = dep.Department_Name, ParentDepID = dep.Parent_ID
                    }).ToList <NameValues>();
                }
                if (DataType == DataType.CurrentDep)
                {
                    T_User currentUserModel = context.FindById <T_User>(new object[] { currentUseID });
                    if ((currentUserModel != null) && (currentUserModel.User_ID > 0))
                    {
                        userList = (from dep in context.Set <T_Department>()
                                    join user in context.Set <T_User>() on dep.Department_ID equals user.Department_ID
                                    where (((dep.Department_ID == currentUserModel.Department_ID) && (user.State == 0)) && (dep.State == 0)) && (user.Department_ID != null)
                                    orderby user.User_Name
                                    select new NameValues {
                            Id = user.User_ID, Name = user.User_Name, DepID = user.Department_ID.ToInt(), DepName = dep.Department_Name, ParentDepID = dep.Parent_ID
                        }).ToList <NameValues>();
                    }
                }
                if (DataType == DataType.SubDep)
                {
                    T_User t_user = context.FindById <T_User>(new object[] { currentUseID });
                    if ((t_user != null) && (t_user.User_ID > 0))
                    {
                        T_Department currentDepModel = context.FindById <T_Department>(new object[] { t_user.Department_ID });
                        if ((currentDepModel != null) && (currentDepModel.Department_ID > 0))
                        {
                            userList = (from dep in context.Set <T_Department>()
                                        join user in context.Set <T_User>() on dep.Department_ID equals user.Department_ID into user
                                        where dep.SystemLevelCode.StartsWith(currentDepModel.SystemLevelCode)
                                        select new NameValues {
                                Id = t_user.User_ID, Name = t_user.User_Name, DepID = t_user.Department_ID.ToInt(), DepName = dep.Department_Name, ParentDepID = dep.Parent_ID
                            }).ToList <NameValues>();
                        }
                    }
                }
                if (DataType == DataType.Custom)
                {
                    try
                    {
                        userList = ((ICustomSelectUser)Activator.CreateInstance(t)).GetCustomData(parameter);
                    }
                    catch (Exception exception)
                    {
                        AppLogHelper.Error(exception);
                    }
                }
            }
            List <SelectControlData> depList = new List <SelectControlData>();

            if ((userList != null) && (userList.Count > 0))
            {
                depList = (from p in userList select new SelectControlData {
                    id = p.DepID, name = p.DepName, pId = p.ParentDepID, open = true, userlist = new List <NameValues>(), icon = "/Content/metro/images/selectuser_icon.png"
                }).ToList <SelectControlData>().Distinct <SelectControlData>(new List_DepId()).ToList <SelectControlData>();
                GetSelectControlData(userList, depList);
            }
            return(depList);
        }
Example #27
0
        public static SysUser GetUserFromToken(string token)
        {
            SysUser user;

            if (IsSsoServer)
            {
                AppLogHelper.Information("IsSsoServer=true");
                var userIdFromToken = GetUserIdFromToken(token);
                if (userIdFromToken <= 0)
                {
                    return(null);
                }
                var manager = new UserManager <SysUser>(new UserStore());
                user                   = manager.FindById(userIdFromToken.ToString());
                user.SsoToken          = token;
                user.LastTokenBeatTime = DateTime.Now;
                return(user);
            }
            if (!IsSsoClient)
            {
                return(null);
            }
            string str2;

            AppLogHelper.Information("IsSsoClient=true");
            var address = AppendTokenToUrl(TokenValidateUrl, token);
            var client  = new WebClient();

            try
            {
                var tokenKey = TokenKey;
                var data     = new NameValueCollection {
                    { tokenKey, token }
                };
                var bytes = client.UploadValues(address, data);
                if (bytes.Length > 0)
                {
                    str2 = Encoding.UTF8.GetString(bytes);
                    AppLogHelper.Information("token验证返回信息:" + str2);
                }
                else
                {
                    AppLogHelper.Information("token验证时返回信息长度为0");
                    str2 = string.Empty;
                }
            }
            catch (Exception exception)
            {
                AppLogHelper.Error(exception);
                str2 = string.Empty;
            }
            finally
            {
                if (client != null)
                {
                    client.Dispose();
                }
            }
            if (!string.IsNullOrWhiteSpace(str2))
            {
                user                   = JsonConvert.DeserializeObject <SysUser>(str2);
                user.SsoToken          = token;
                user.LastTokenBeatTime = DateTime.Now;
                return(user);
            }
            return(null);
        }
        public static void HandleMessage(SysWorkflowMessage msg, string connectionStringOrName)
        {
            if (string.IsNullOrWhiteSpace(connectionStringOrName))
            {
                connectionStringOrName = DataContext.BizConnectionStringDefault;
            }
            try
            {
                Console.WriteLine("开始处理消息ID:{0},类型:{1}", msg.MessageId, msg.MessageType);
                using (TransactionScope scope = new TransactionScope())
                {
                    using (BizDataContext context = new BizDataContext(connectionStringOrName, true))
                    {
                        if (LockMessage(msg, context))
                        {
                            try
                            {
                                ProcessInstanceCacheFactory runtimeContext  = new ProcessInstanceCacheFactory(context);
                                SysProcessInstance          processInstance = null;
                                SysWorkItem item = null;
                                switch (msg.MessageType)
                                {
                                case WorkflowMessageTypeEnum.StartingProcess:
                                    processInstance = runtimeContext.GetProcessInstanceCache(msg.ProcessInstanceId);
                                    break;

                                case WorkflowMessageTypeEnum.ExecutingActivity:
                                    throw new Exception(string.Format("暂时不支持ExecutingActivity类型的消息", new object[0]));

                                case WorkflowMessageTypeEnum.CompletingWorkItem:
                                case WorkflowMessageTypeEnum.CompletingApproveWorkItem:
                                    processInstance = runtimeContext.GetProcessInstanceCacheByWorkItem(msg.WorkItemId, out item);
                                    break;

                                default:
                                    throw new Exception(string.Format(string.Format("暂时不支持{0}类型的消息", msg.MessageType), new object[0]));
                                }
                                ProcessEngine engine = new ProcessEngine(runtimeContext, processInstance, item);
                                msg.MessageType.CreateHandler(engine).ProcessMessage(msg);
                                if (!CompleteMessage(msg, context))
                                {
                                    AppLogHelper.Information("完成工作流消息时更新行数为0: MessageId={0}", new object[] { msg.MessageId });
                                }
                                scope.Complete();
                                return;
                            }
                            catch (Exception exception)
                            {
                                AppLogHelper.Error(exception, "处理工作流消息失败1: MessageId={0}", new object[] { msg.MessageId });
                                throw new MessageHandleException(exception);
                            }
                        }
                        AppLogHelper.Information("锁定工作流消息时更新行数为0: MessageId={0}", new object[] { msg.MessageId });
                    }
                }
            }
            catch (MessageHandleException exception2)
            {
                ProcessError(msg, exception2.InnerException, connectionStringOrName);
            }
            catch (Exception exception3)
            {
                AppLogHelper.Error(exception3, "处理工作流消息失败2: MessageId={0}", new object[] { msg.MessageId });
                ProcessError(msg, exception3, connectionStringOrName);
            }
        }
Example #29
0
        public List <IUser> GetParticipantUsers(long activityId, int?processInstanceId = new int?(), int?activityInstanctId = new int?())
        {
            Func <SysActivityInstance, bool> predicate = null;
            Func <SysActivityInstance, bool> func3     = null;
            List <IUser> list3;

            try
            {
                SysActivity activity;
                int?        nullable = processInstanceId;
                if ((nullable.HasValue ? nullable.GetValueOrDefault() : -1) <= 0)
                {
                    processInstanceId = null;
                }
                int?nullable2 = activityInstanctId;
                if ((nullable2.HasValue ? nullable2.GetValueOrDefault() : -1) <= 0)
                {
                    activityInstanctId = null;
                }
                List <IUser>        users = new List <IUser>();
                SysProcess          processCacheByActivity = this._processCache.GetProcessCacheByActivity(activityId, out activity);
                SysProcessInstance  pi = null;
                SysActivityInstance ai = null;
                if (processInstanceId.HasValue)
                {
                    pi = new ProcessInstanceCacheFactory(this._context).GetProcessInstanceCache(processInstanceId.Value);
                    if (pi == null)
                    {
                        throw new ApplicationException(string.Format("流程实例ID:{0}不正确", processInstanceId));
                    }
                    if (activityInstanctId.HasValue)
                    {
                        if (predicate == null)
                        {
                            predicate = p => p.ActivityInstanceId == activityInstanctId.Value;
                        }
                        ai = pi.ActivityInstances.FirstOrDefault <SysActivityInstance>(predicate);
                        if (ai == null)
                        {
                            throw new ApplicationException(string.Format("活动实例ID:{0}不正确", activityInstanctId));
                        }
                    }
                    else
                    {
                        if (func3 == null)
                        {
                            func3 = delegate(SysActivityInstance p) {
                                long?nullable1 = p.ActivityId;
                                long num       = activityId;
                                return((nullable1.GetValueOrDefault() == num) && nullable1.HasValue);
                            };
                        }
                        ai = pi.ActivityInstances.FirstOrDefault <SysActivityInstance>(func3);
                    }
                }
                using (IEnumerator <SysActivityParticipant> enumerator = activity.ActivityParticipants.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        Func <SysProcessParticipant, bool> func          = null;
                        SysActivityParticipant             activity_part = enumerator.Current;
                        if (func == null)
                        {
                            func = p => p.ParticipantId == activity_part.ParticipantId.Value;
                        }
                        SysProcessParticipant part = processCacheByActivity.ProcessParticipants.FirstOrDefault <SysProcessParticipant>(func);
                        if (part == null)
                        {
                            throw new ApplicationException("参与人为空");
                        }
                        int?         wiOwnerId  = null;
                        List <IUser> collection = ParticipantHelper.GetUsers(this._context, part, pi, ai, wiOwnerId);
                        users.AddRange(collection);
                    }
                }
                RemoveRepeatedUsers(users);
                list3 = users;
            }
            catch (Exception exception)
            {
                AppLogHelper.Error(string.Format("GetParticipantUsers,activityId=[{0}]失败", activityId), exception);
                throw exception;
            }
            return(list3);
        }