示例#1
0
        /// <summary>
        /// 修改任务
        /// </summary>
        public bool EditTask(int taskId, int step, IAutomation automation, GameServer[] servers, string name, string comment)
        {
            using (IBlazeDatabase db = DbFactory.GetDatabase())
            {
                try
                {
                    BatchTask task = this.GetBatchTask(taskId);
                    if (task == null)
                    {
                        return(false);
                    }

                    db.BeginTrans();

                    SecurityManager sm         = AdminServer.TheInstance.SecurityManager;
                    FSEyeObject     taskObject = sm.Get(taskId);
                    taskObject.Name    = name;
                    taskObject.Comment = comment;
                    sm.Set(taskObject, db);

                    StringBuilder serverIdText = new StringBuilder();
                    foreach (GameServer server in servers)
                    {
                        serverIdText.Append(server.Id);
                        serverIdText.Append(',');
                    }

                    IBlazeTable batchTaskTable   = db.GetTable(TableString.BatchTaskTableName);
                    DataSet     batchTaskDataSet = new DataSet();
                    batchTaskTable.Get(batchTaskDataSet);
                    DataTable taskTable = batchTaskDataSet.Tables[TableString.BatchTaskTableName];
                    DataRow[] taskRows  = taskTable.Select(string.Concat(TableString.BatchTaskId, "=", taskId));
                    if (taskRows != null && taskRows.Length > 0)
                    {
                        taskRows[0][TableString.BatchTaskStep]       = step;
                        taskRows[0][TableString.BatchTaskAutomation] = AdminServer.TheInstance.AutomationManager.Save(automation);
                        taskRows[0][TableString.BatchTaskServerIds]  = SystemConfig.Current.DefaultEncoding.GetBytes(serverIdText.Length == 0 ? string.Empty : serverIdText.ToString(0, serverIdText.Length - 1));
                        batchTaskTable.Set(taskTable);
                    }

                    //修改内存中数据
                    task.Step       = step;
                    task.Automation = automation;
                    task.ClearServers();
                    foreach (GameServer server in servers)
                    {
                        task.AddServer(server.Id);
                    }

                    db.CommitTrans();
                    return(true);
                }
                catch (Exception)
                {
                    if (db != null)
                    {
                        db.RollbackTrans();
                    }
                    return(false);
                }
            }
        }