예제 #1
0
파일: Strategy.cs 프로젝트: uvbs/FullSource
        /// <summary>
        /// 更新策略
        /// </summary>
        public void Update(int strategyId, Strategy newStrategy, string name, string comment)
        {
            using (IBlazeDatabase db = DbFactory.GetDatabase())
            {
                try
                {
                    db.BeginTrans();

                    SecurityManager sm             = AdminServer.TheInstance.SecurityManager;
                    FSEyeObject     strategyObject = sm.Get(strategyId);
                    strategyObject.Name    = name;
                    strategyObject.Comment = comment;
                    sm.Set(strategyObject, db);
                    newStrategy.SecurityObject = strategyObject;

                    IBlazeTable table        = db.GetTable(TableString.StrategyTableName);
                    DataSet     strategyData = new DataSet();
                    table.Get(strategyData);
                    DataTable         strategyTable = strategyData.Tables[TableString.StrategyTableName];
                    AutomationManager am            = AdminServer.TheInstance.AutomationManager;

                    byte[]    strategyBytes = am.Save(newStrategy.Automation);
                    DataRow[] rows          = strategyTable.Select(TableString.StrategyFieldId + "=" + strategyId);
                    if (rows != null && rows.Length > 0)
                    {
                        DataRow row = rows[0];
                        row[TableString.StrategyFieldEvent]      = (int)newStrategy.Event;
                        row[TableString.StrategyFieldEnabled]    = (newStrategy.Enabled ? 1 : 0);
                        row[TableString.StrategyFieldAutomation] = strategyBytes;

                        table.Set(strategyTable);
                    }

                    for (int i = 0; i < _strategyList.Count; i++)
                    {
                        Strategy strategy = _strategyList[i] as Strategy;
                        if (strategy.SecurityObject.Id == strategyId)
                        {
                            _strategyList.RemoveAt(i);
                            _strategyList.Add(newStrategy);
                            break;
                        }
                    }

                    db.CommitTrans();
                }
                catch (Exception ex)
                {
                    if (db != null)
                    {
                        db.RollbackTrans();
                    }

                    throw ex;
                }
            }
        }
예제 #2
0
파일: Strategy.cs 프로젝트: uvbs/FullSource
        /// <summary>
        /// 添加策略
        /// </summary>
        public bool Add(Strategy strategy, string name, string comment)
        {
            using (IBlazeDatabase db = DbFactory.GetDatabase())
            {
                try
                {
                    db.BeginTrans();

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

                    if (newObject != null && strategyBytes != null)
                    {
                        newObject.Comment = comment;
                        sm.Set(newObject);
                        strategy.SecurityObject = newObject;

                        IBlazeTable table        = db.GetTable(TableString.StrategyTableName);
                        DataSet     strategyData = new DataSet();
                        table.Get(strategyData);
                        DataTable strategyTable = strategyData.Tables[TableString.StrategyTableName];

                        DataRow newRow = strategyTable.NewRow();
                        newRow[TableString.StrategyFieldId]         = newObject.Id;
                        newRow[TableString.StrategyFieldEvent]      = (int)strategy.Event;
                        newRow[TableString.StrategyFieldAutomation] = strategyBytes;
                        newRow[TableString.StrategyFieldEnabled]    = (strategy.Enabled ? 1 : 0);
                        strategyTable.Rows.Add(newRow);
                        table.Set(strategyTable);

                        //设置权限
                        AdminServer.TheInstance.SecurityManager.CopyAce(newObject.Parent, newObject, true);

                        _strategyList.Add(strategy);

                        db.CommitTrans();

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

                    throw ex;
                }
            }
        }
예제 #3
0
        /// <summary>
        /// 更新计划任务
        /// </summary>
        public void Update(int taskId, IScheduledTask newTask, string name, string comment)
        {
            using (IBlazeDatabase db = DbFactory.GetDatabase())
            {
                try
                {
                    db.BeginTrans();

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

                    using (MemoryStream taskDataStream = new MemoryStream())
                    {
                        IFormatter formatter = new BinaryFormatter();
                        formatter.Serialize(taskDataStream, newTask);
                        byte[]      taskData           = taskDataStream.ToArray();
                        DataSet     ds                 = new DataSet();
                        IBlazeTable scheduledTaskTable = db.GetTable(TableString.ScheduledTaskTableName);
                        scheduledTaskTable.Get(ds);
                        DataTable table = ds.Tables[TableString.ScheduledTaskTableName];
                        DataRow[] rows  = table.Select(TableString.ScheduledTaskFieldId + "=" + newTask.SecurityObject.Id);
                        if (rows.Length > 0)
                        {
                            DataRow row = rows[0];
                            row[TableString.ScheduledTaskFieldTaskData] = taskData;
                            scheduledTaskTable.Set(table);
                        }
                    }

                    foreach (ScheduledTaskUnit unit in _taskList)
                    {
                        if (unit.Task.SecurityObject.Id == taskId)
                        {
                            unit.AvoidCheckTimeout = 0;
                            unit.Task = newTask;
                            break;
                        }
                    }

                    db.CommitTrans();
                }
                catch (Exception ex)
                {
                    if (db != null)
                    {
                        db.RollbackTrans();
                    }

                    throw ex;
                }
            }
        }
예제 #4
0
        /// <summary>
        /// 保存帐号密码
        /// </summary>
        public bool SaveAccountPassword(string accountName, string accountPassword)
        {
            IBlazeDatabase db = null;

            try
            {
                db = DbFactory.GetDatabase();
                IBlazeTable accountTable = db.GetTable(TableString.AccountInfoTableName);

                //插入数据到服务器表
                string[] fields = new string[] {
                    TableString.AccountInfoFieldName,
                    TableString.AccountInfoFieldPassword,
                };
                object[] values = new object[] {
                    accountName,
                    accountPassword
                };

                db.BeginTrans();
                if (GetSavedPassword(accountName) != null)
                {
                    //Update
                    accountTable.Set(TableString.AccountInfoFieldPassword, accountPassword,
                                     FilterFactory.CreateEqualFilter(TableString.AccountInfoFieldName, accountName));
                }
                else
                {
                    //Insert
                    accountTable.Add(fields, values);
                }
                db.CommitTrans();

                return(true);
            }
            catch (Exception ex)
            {
                if (db != null)
                {
                    db.RollbackTrans();
                }
                throw ex;
            }
            finally
            {
                if (db != null)
                {
                    db.Close();
                }
            }
        }
예제 #5
0
        public bool EditUpdateServer(FTPServer server)
        {
            IBlazeDatabase db = null;

            try
            {
                db = DbFactory.GetDatabase();
                db.BeginTrans();

                IBlazeTable table    = db.GetTable(TableString.UpdateServerTableName);
                DataSet     taskData = new DataSet();
                table.Get(taskData);
                DataTable taskTable = taskData.Tables[TableString.UpdateServerTableName];

                foreach (DataRow row in taskTable.Rows)
                {
                    if ((int)row[TableString.UpdateServerFieldId] == server.ID)
                    {
                        row.BeginEdit();
                        row[TableString.UpdateServerFieldAddress]  = server.Address;
                        row[TableString.UpdateServerFieldPort]     = server.Port;
                        row[TableString.UpdateServerFieldUsername] = server.UserName;
                        row[TableString.UpdateServerFieldPassword] = server.Password;
                        row[TableString.UpdateServerFieldLiteral]  = server.Literal;
                        row.EndEdit();
                        break;
                    }
                }
                table.Set(taskTable);
                db.CommitTrans();

                return(true);
            }
            catch (Exception)
            {
                if (db != null)
                {
                    db.RollbackTrans();
                }
            }
            finally
            {
                if (db != null)
                {
                    db.Close();
                }
            }
            return(false);
        }
예제 #6
0
        public bool DeleteUpdateServer(FTPServer server)
        {
            IBlazeDatabase db = null;

            try
            {
                db = DbFactory.GetDatabase();
                db.BeginTrans();

                IBlazeTable table    = db.GetTable(TableString.UpdateServerTableName);
                DataSet     taskData = new DataSet();
                table.Get(taskData);
                DataTable taskTable = taskData.Tables[TableString.UpdateServerTableName];

                foreach (DataRow row in taskTable.Rows)
                {
                    if ((int)row[TableString.UpdateServerFieldId] == server.ID)
                    {
                        row.Delete();
                        break;
                    }
                }
                table.Set(taskTable);

                AdminServer.TheInstance.SecurityManager.Delete(server.ID, db);

                db.CommitTrans();

                this._FTPServerList.Remove(server);

                return(true);
            }
            catch (Exception)
            {
                if (db != null)
                {
                    db.RollbackTrans();
                }
            }
            finally
            {
                if (db != null)
                {
                    db.Close();
                }
            }
            return(false);
        }
예제 #7
0
        /// <summary>
        /// 添加计划任务
        /// </summary>
        public void Add(IScheduledTask task, string name, string comment)
        {
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (comment == null)
            {
                throw new ArgumentNullException("comment");
            }

            using (IBlazeDatabase db = DbFactory.GetDatabase())
            {
                try
                {
                    db.BeginTrans();

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

                    MemoryStream taskDataStream = new MemoryStream();
                    IFormatter   formatter      = new BinaryFormatter();
                    formatter.Serialize(taskDataStream, task);
                    byte[] taskData = taskDataStream.ToArray();
                    if (newObject != null && automationData != null && taskData != null)
                    {
                        newObject.Comment = comment;
                        sm.Set(newObject);
                        task.SecurityObject = newObject;

                        IBlazeTable scheduledTaskTable = db.GetTable(TableString.ScheduledTaskTableName);
                        DataSet     ds = new DataSet();
                        scheduledTaskTable.Get(ds);
                        DataTable table = ds.Tables[TableString.ScheduledTaskTableName];
                        DataRow   row   = table.NewRow();
                        row[TableString.ScheduledTaskFieldId]       = newObject.Id;
                        row[TableString.ScheduledTaskFieldTaskData] = taskData;
                        table.Rows.Add(row);
                        scheduledTaskTable.Set(table);

                        ScheduledTaskUnit unit = new ScheduledTaskUnit();
                        unit.Task = task;
                        unit.AvoidCheckTimeout = 0;
                        _taskList.Add(unit);

                        //设置权限
                        AdminServer.TheInstance.SecurityManager.CopyAce(newObject.Parent, newObject, true);

                        db.CommitTrans();
                    }
                }
                catch (Exception)
                {
                    db.RollbackTrans();
                }
            }
        }
예제 #8
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);
                }
            }
        }
예제 #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);
        }