Ejemplo n.º 1
0
    void SetBatchTask(BatchTask task)
    {
        if (task != null)
        {
            int[] serverIds = task.Servers;
            foreach (int serverId in serverIds)
            {
                GameServerCheckBoxList1.SetServerSelected(serverId, true);
            }

            TextBoxName.Text = task.SecurityObject.Name;
            TextBoxDesc.Text = task.SecurityObject.Comment;
            AutomationEditor1.Automation = task.Automation;
            foreach (ListItem item in DropDownListStepSize.Items)
            {
                if (item.Value == task.Step.ToString())
                {
                    item.Selected = true;
                    break;
                }
            }
            LinkButtonApply.Text = StringDef.Modify;
        }
        else
        {
            TextBoxDesc.Text = StringDef.Untitled;
            AutomationEditor1.Automation = null;
            LinkButtonApply.Text = StringDef.Add;
        }
    }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!WebUtil.CheckPrivilege(WebConfig.FunctionAutomationEditBatchTask, OpType.READ, Session))
        {
            Response.Redirect(WebConfig.PageNotEnoughPrivilege, true);
        }

        if ((Request.Params[WebConfig.ParamOperation] as string) == "modify")
        {
            int taskId = int.Parse(Request.Params[WebConfig.ParamTaskId]);
            _task = TheAdminServer.BatchTaskManager.GetBatchTask(taskId);
        }

        if (!IsPostBack)
        {
            SetBatchTask(_task);
        }
    }
Ejemplo n.º 4
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);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 添加任务
        /// </summary>
        public bool AddTask(BatchTask task, string name, string comment)
        {
            if (!_batchTaskList.Contains(task))
            {
                using (IBlazeDatabase db = DbFactory.GetDatabase())
                {
                    try
                    {
                        db.BeginTrans();

                        SecurityManager sm                  = AdminServer.TheInstance.SecurityManager;
                        FSEyeObject     newObject           = sm.Get(SecurityObject.FullPath + SecurityManager.ObjectPathDelimiter + name, db);
                        byte[]          taskAutomationBytes = AdminServer.TheInstance.AutomationManager.Save(task.Automation);

                        if (newObject != null && taskAutomationBytes != null)
                        {
                            IBlazeTable table       = db.GetTable(TableString.BatchTaskTableName);
                            DataSet     taskDataSet = new DataSet();
                            table.Get(taskDataSet);
                            DataTable taskTable = taskDataSet.Tables[TableString.BatchTaskTableName];

                            DataRow newRow = taskTable.NewRow();
                            newRow[TableString.BatchTaskId]         = newObject.Id;
                            newRow[TableString.BatchTaskAutomation] = taskAutomationBytes;
                            newRow[TableString.BatchTaskStep]       = task.Step;

                            StringBuilder serverIdText = new StringBuilder();
                            foreach (int serverId in task.Servers)
                            {
                                serverIdText.Append(serverId);
                                serverIdText.Append(',');
                            }

                            newRow[TableString.BatchTaskServerIds] = SystemConfig.Current.DefaultEncoding.GetBytes(serverIdText.Length == 0 ? string.Empty : serverIdText.ToString(0, serverIdText.Length - 1));
                            taskTable.Rows.Add(newRow);
                            table.Set(taskTable);

                            //设置权限并更新SecurityObject
                            AdminServer.TheInstance.SecurityManager.CopyAce(newObject.Parent, newObject, true);
                            newObject.Comment = comment;
                            sm.Set(newObject);
                            task.SecurityObject = newObject;

                            _batchTaskList.Add(task);

                            db.CommitTrans();
                            return(true);
                        }
                    }
                    catch (Exception)
                    {
                        if (db != null)
                        {
                            db.RollbackTrans();
                        }
                        return(false);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 6
0
	void SetTask(BatchTask task)
	{
		if (task != null)
		{
            LiteralName.Text = task.SecurityObject.Name;
			LiteralDesc.Text = task.SecurityObject.Comment;
			if (task.StartTime != DateTime.MinValue)
			{
				LiteralBeginTime.Text = task.StartTime.ToString();
			}
			else
			{
				LiteralBeginTime.Text = StringDef.NotStarted;
			}
			if (task.StartTime != DateTime.MinValue)
			{
				if (task.EndTime != DateTime.MinValue)
				{
					LiteralEscapedTime.Text = ((TimeSpan)(task.EndTime.Subtract(task.StartTime))).ToString();
				}
				else
				{
					LiteralEscapedTime.Text = ((TimeSpan)(DateTime.Now.Subtract(task.StartTime))).ToString();
				}
			}
			else
			{
				LiteralEscapedTime.Text = StringDef.NotStarted;
			}
			if (task.EndTime != DateTime.MinValue)
			{
				LiteralEndTime.Text = task.EndTime.ToString();
			}
			else
			{
				LiteralEndTime.Text = StringDef.NotFinished;
			}

			TableServerList.Rows.Clear();

			int[] serverIds = task.Servers;
			if (serverIds != null)
			{
				TableHeaderRow headerRow = new TableHeaderRow();
				TableHeaderCell headerCell = null;

				headerCell = new TableHeaderCell();
				headerCell.Text = StringDef.GameServer;
				headerRow.Cells.Add(headerCell);

				headerCell = new TableHeaderCell();
				headerCell.Text = StringDef.State;
				headerRow.Cells.Add(headerCell);

				TableServerList.Rows.Add(headerRow);

				for (int i = 0; i < serverIds.Length; i++)
				{
					GameServer server = TheAdminServer.GameServerManager.GetGameServer(serverIds[i]);
					if (server != null)
					{
						TableRow row = new TableRow();
						TableCell cell = null;

						cell = new TableCell();
						cell.Text = server.Name;
						row.Cells.Add(cell);

						cell = new TableCell();
						cell.Text = task.GetUnitState(i).ToString();
						row.Cells.Add(cell);

						TableServerList.Rows.Add(row);
					}
				}
			}
		}
	}
Ejemplo n.º 7
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;
        }
    }
Ejemplo n.º 8
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;
            }
        }
Ejemplo n.º 9
0
		/// <summary>
		/// 添加任务
		/// </summary>
        public bool AddTask(BatchTask task, string name, string comment)
		{
			if (!_batchTaskList.Contains(task))
			{
                using (IBlazeDatabase db = DbFactory.GetDatabase())
                {
                    try
                    {
                        db.BeginTrans();

                        SecurityManager sm = AdminServer.TheInstance.SecurityManager;
                        FSEyeObject newObject = sm.Get(SecurityObject.FullPath + SecurityManager.ObjectPathDelimiter + name, db);
                        byte[] taskAutomationBytes = AdminServer.TheInstance.AutomationManager.Save(task.Automation);

                        if (newObject != null && taskAutomationBytes != null)
                        {
                            IBlazeTable table = db.GetTable(TableString.BatchTaskTableName);
                            DataSet taskDataSet = new DataSet();
                            table.Get(taskDataSet);
                            DataTable taskTable = taskDataSet.Tables[TableString.BatchTaskTableName];

                            DataRow newRow = taskTable.NewRow();
                            newRow[TableString.BatchTaskId] = newObject.Id;
                            newRow[TableString.BatchTaskAutomation] = taskAutomationBytes;
                            newRow[TableString.BatchTaskStep] = task.Step;

                            StringBuilder serverIdText = new StringBuilder();
                            foreach (int serverId in task.Servers)
                            {
                                serverIdText.Append(serverId);
                                serverIdText.Append(',');
                            }

                            newRow[TableString.BatchTaskServerIds] = SystemConfig.Current.DefaultEncoding.GetBytes(serverIdText.Length == 0 ? string.Empty : serverIdText.ToString(0, serverIdText.Length - 1));
                            taskTable.Rows.Add(newRow);
                            table.Set(taskTable);

                            //设置权限并更新SecurityObject
                            AdminServer.TheInstance.SecurityManager.CopyAce(newObject.Parent, newObject, true);
                            newObject.Comment = comment;
                            sm.Set(newObject);
                            task.SecurityObject = newObject;                            

                            _batchTaskList.Add(task);

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