Exemplo n.º 1
0
        public bool Load()
        {
            this.SecurityObject = AdminServer.TheInstance.SecurityManager.Get(SecurityObjectBatchTaskManager);
            this._batchTaskList.Clear();

            using (IBlazeDatabase db = DbFactory.GetDatabase())
            {
                IBlazeTable table            = db.GetTable(TableString.BatchTaskTableName);
                DataSet     batchTaskDataSet = new DataSet();
                table.Get(batchTaskDataSet);
                DataTable         batchTaskTable = batchTaskDataSet.Tables[TableString.BatchTaskTableName];
                StrategyManager   sm             = AdminServer.TheInstance.StrategyManager;
                AutomationManager am             = AdminServer.TheInstance.AutomationManager;
                foreach (DataRow row in batchTaskTable.Rows)
                {
                    int batchTaskId = (int)row[TableString.BatchTaskId];

                    try
                    {
                        BatchTask batchTask = new BatchTask();
                        batchTask.Step       = (int)row[TableString.BatchTaskStep];
                        batchTask.Automation = am.Load((byte[])row[TableString.BatchTaskAutomation]);
                        string serverIds = SystemConfig.Current.DefaultEncoding.GetString((byte[])row[TableString.BatchTaskServerIds]);
                        foreach (string serverIdText in serverIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            int        serverId = int.Parse(serverIdText);
                            GameServer server   = AdminServer.TheInstance.GameServerManager.GetGameServer(serverId);
                            if (server != null)
                            {
                                batchTask.AddServer(serverId);
                            }
                        }

                        FSEyeObject secObj = AdminServer.TheInstance.SecurityManager.Get(batchTaskId);
                        if (secObj != null)
                        {
                            batchTask.SecurityObject = secObj;
                            _batchTaskList.Add(batchTask);
                        }
                    }
                    catch (Exception e)
                    {
                        Util.DebugLog(e.StackTrace);
                        continue;
                    }
                }
                return(true);
            }
        }
Exemplo n.º 2
0
    protected void LinkButtonApply_Click(object sender, EventArgs e)
    {
        try
        {
            if (!WebUtil.CheckPrivilege(TheAdminServer.BatchTaskManager.SecurityObject, OpType.WRITE, Session))
            {
                Response.Redirect(WebConfig.PageNotEnoughPrivilege, true);
            }

            GameServer[] selectedServers = GameServerCheckBoxList1.SelectedGameServers;
            if (selectedServers == null || selectedServers.Length <= 0)
            {
                LabelOpMsg.Text = string.Format(StringDef.MsgCannotBeNone, StringDef.GameServer);
                return;
            }
            IAutomation automation = AutomationEditor1.Automation;
            if (automation == null)
            {
                LabelOpMsg.Text = string.Format(StringDef.MsgCannotBeNone, StringDef.Automation);
                return;
            }

            string name = TextBoxName.Text.Trim();
            if (name.Length == 0)
            {
                LabelOpMsg.Text = string.Format(StringDef.MsgCannotBeNone, StringDef.Name);
                return;
            }

            string desc = TextBoxDesc.Text.Trim();
            if (desc.Length == 0)
            {
                LabelOpMsg.Text = string.Format(StringDef.MsgCannotBeNone, StringDef.Description);
                return;
            }

            if (_task == null)
            {
                //Ìí¼Ó
                _task = new BatchTask();
                _task.Step = int.Parse(DropDownListStepSize.SelectedValue);
                foreach (GameServer server in selectedServers)
                {
                    if (server != null)
                    {
                        _task.AddServer(server.Id);
                    }
                }
                _task.Automation = automation;

                if (TheAdminServer.BatchTaskManager.AddTask(_task, name, desc))
                {
                    Response.Redirect("BatchTask.aspx", true);                    
                }
                else
                {
                    LabelOpMsg.Text = StringDef.OperationFail + StringDef.Colon + StringDef.AddTask;
                    return;
                }
            }
            else
            {
                //ÐÞ¸Ä
                if (TheAdminServer.BatchTaskManager.EditTask(_task.ID,
                        int.Parse(DropDownListStepSize.SelectedValue),
                        automation,
                        selectedServers,
                        name,
                        desc))
                {
                    Response.Redirect("BatchTask.aspx", true);
                }
                else
                {
                    LabelOpMsg.Text = StringDef.OperationFail + StringDef.Colon + StringDef.EditBatchTask;
                    return;
                }
            }
        }
        catch (Exception ex)
        {
            LabelOpMsg.Text = StringDef.OperationFail + StringDef.Colon + ex.Message;
        }
    }
Exemplo n.º 3
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);
                }
            }
        }
Exemplo n.º 4
0
        public bool Load()
        {
            this.SecurityObject = AdminServer.TheInstance.SecurityManager.Get(SecurityObjectBatchTaskManager);
            this._batchTaskList.Clear();

            using (IBlazeDatabase db = DbFactory.GetDatabase())
            {
                IBlazeTable table = db.GetTable(TableString.BatchTaskTableName);
                DataSet batchTaskDataSet = new DataSet();
                table.Get(batchTaskDataSet);
                DataTable batchTaskTable = batchTaskDataSet.Tables[TableString.BatchTaskTableName];
                StrategyManager sm = AdminServer.TheInstance.StrategyManager;
                AutomationManager am = AdminServer.TheInstance.AutomationManager;
                foreach (DataRow row in batchTaskTable.Rows)
                {
                    int batchTaskId = (int)row[TableString.BatchTaskId];

                    try
                    {
                        BatchTask batchTask = new BatchTask();
                        batchTask.Step = (int)row[TableString.BatchTaskStep];
                        batchTask.Automation = am.Load((byte[])row[TableString.BatchTaskAutomation]);
                        string serverIds = SystemConfig.Current.DefaultEncoding.GetString((byte[])row[TableString.BatchTaskServerIds]);
                        foreach (string serverIdText in serverIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            int serverId = int.Parse(serverIdText);
                            GameServer server = AdminServer.TheInstance.GameServerManager.GetGameServer(serverId);
                            if (server != null)
                                batchTask.AddServer(serverId);
                        }

                        FSEyeObject secObj = AdminServer.TheInstance.SecurityManager.Get(batchTaskId);
                        if (secObj != null)
                        {
                            batchTask.SecurityObject = secObj;
                            _batchTaskList.Add(batchTask);
                        }
                    }
                    catch (Exception e)
                    {
                        Util.DebugLog(e.StackTrace);
                        continue;
                    }
                }
                return true;
            }
        }