private static bool CompleteMessage(SysWorkflowMessage msg, DataContext db)
        {
            if (msg.State != SysWorkflowMessageStateEnum.Running)
            {
                throw new Exception(string.Format("消息ID:{0}的状态不为Running", msg.MessageId));
            }
            string sql = string.Format("UPDATE SysWorkflowMessage SET STATE = {0} WHERE MESSAGEID = {1} AND STATE = {2}", db.AddPrefixToParameterName("NewState"), db.AddPrefixToParameterName("MessageId"), db.AddPrefixToParameterName("OldState"));
            int    num = db.ExecuteNonQuery(sql, new DbParameter[] { db.CreateParameterWithPrefix("NewState", Convert.ToInt32(SysWorkflowMessageStateEnum.Completed), (int?)null), db.CreateParameterWithPrefix("MessageId", msg.MessageId, (int?)null), db.CreateParameterWithPrefix("OldState", Convert.ToInt32(SysWorkflowMessageStateEnum.Running), (int?)null) });

            if (num > 0)
            {
                Console.WriteLine("将消息状态改为Completed");
                msg.State = SysWorkflowMessageStateEnum.Completed;
            }
            return(num > 0);
        }
Exemplo n.º 2
0
 private void SaveWorkflowMessage(SysWorkflowMessage msg)
 {
     Trace.Assert(msg.MessageId > 0);
     if (msg.NextApproveUserList.Count > 0)
     {
         foreach (IApproveUser user in msg.NextApproveUserList)
         {
             MessageApproveUser user2 = new MessageApproveUser(user)
             {
                 WorkflowMessageId    = msg.MessageId,
                 MessageApproveUserId = this._context.GetNextIdentity_Int(false)
             };
             this._context.Insert(user2);
         }
     }
     this._context.Insert(msg);
 }
Exemplo n.º 3
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;
     }
 }
Exemplo n.º 4
0
 internal virtual int StartProcessAsync(int startUserId, int relativeObjectId, List <IApproveUser> nextApproveUserList)
 {
     using (BizDataContext context = new BizDataContext(true))
     {
         SysProcessInstance instance = new SysProcessInstance {
             StartTime         = new DateTime?(DateTime.Now),
             InstanceStatus    = 0,
             ObjectId          = relativeObjectId,
             ProcessId         = new long?(this._process.ProcessId),
             ProcessInstanceId = context.GetNextIdentity_Int(false),
             StartUserId       = new int?(startUserId)
         };
         this._pi = instance;
         SysWorkflowMessage message = new SysWorkflowMessage {
             ProcessId         = this._process.ProcessId,
             ProcessInstanceId = this._pi.ProcessInstanceId,
             CreateTime        = DateTime.Now,
             MessageId         = context.GetNextIdentity_Int(false),
             MessageType       = WorkflowMessageTypeEnum.StartingProcess,
             OperationUserId   = startUserId,
             State             = SysWorkflowMessageStateEnum.Inited
         };
         foreach (IApproveUser user in nextApproveUserList)
         {
             MessageApproveUser user2 = new MessageApproveUser(user)
             {
                 //WorkflowMessageId = message.MessageId,
                 WorkflowMessageId = context.GetNextIdentity_Int(false)
             };
             context.Insert(user2);
         }
         context.Insert(message);
         context.Insert(this._pi);
     }
     return(this._pi.ProcessInstanceId);
 }
Exemplo n.º 5
0
 public abstract void ProcessMessage(SysWorkflowMessage msg);
        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);
            }
        }