Example #1
0
        /// <summary>
        /// 得到已保存的帐号密码
        /// </summary>
        public string GetSavedPassword(string accountName)
        {
            IBlazeDatabase db = null;

            try
            {
                db = DbFactory.GetDatabase();
                DataSet dataSet = new DataSet();

                IBlazeTable accountTable = db.GetTable(TableString.AccountInfoTableName);
                accountTable.Get(dataSet, FilterFactory.CreateEqualFilter(TableString.AccountInfoFieldName, accountName));
                DataRowCollection rows = dataSet.Tables[TableString.AccountInfoTableName].Rows;
                if (rows.Count != 0)
                {
                    return(rows[0][TableString.AccountInfoFieldPassword] as string);
                }
                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (db != null)
                {
                    db.Close();
                }
            }
        }
Example #2
0
        /// <summary>
        /// 得到玩家数量信息
        /// </summary>
        PlayerCountStatisticInfo[] GetPlayerCountInfo(DateTime startTime, DateTime endTime)
        {
            using (IBlazeDatabase db = DbFactory.GetDatabase())
            {
                IBlazeTable table = db.GetTable(TableString.PlayerCountTableName);
                DataSet     ds    = new DataSet();
                table.Get(ds,
                          FilterFactory.CreateAndFilter(
                              FilterFactory.CreateEqualFilter(TableString.PlayerCountFieldServerId, _server.Id),
                              FilterFactory.CreateAndFilter(
                                  FilterFactory.CreateLargerEqualFilter(TableString.PlayerCountFieldRecordTime, startTime),
                                  FilterFactory.CreateLesserEqualFilter(TableString.PlayerCountFieldRecordTime, endTime)
                                  )
                              )
                          );

                DataTable dt       = ds.Tables[TableString.PlayerCountTableName];
                int       rowCount = dt.Rows.Count;
                PlayerCountStatisticInfo[] infos = new PlayerCountStatisticInfo[rowCount];
                for (int i = 0; i < rowCount; i++)
                {
                    DataRow row = dt.Rows[i];
                    PlayerCountStatisticInfo info = new PlayerCountStatisticInfo();
                    info.Time         = (DateTime)row[TableString.PlayerCountFieldRecordTime];
                    info.MaxCount     = (int)row[TableString.PlayerCountFieldMaxPlayerCount];
                    info.MinCount     = (int)row[TableString.PlayerCountFieldMinPlayerCount];
                    info.AverageCount = (int)row[TableString.PlayerCountFieldAveragePlayerCount];
                    infos[i]          = info;
                }

                return(infos);
            }
        }
Example #3
0
        /// <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;
                }
            }
        }
Example #4
0
        /// <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;
                }
            }
        }
Example #5
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;
                }
            }
        }
Example #6
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);
            }
        }
Example #7
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);
        }
Example #8
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);
        }
Example #9
0
        /// <summary>
        /// 载入计划任务
        /// </summary>
        public void Load()
        {
            this.SecurityObject = AdminServer.TheInstance.SecurityManager.Get(SecurityObjectScheduledTaskManager);
            _taskList.Clear();

            using (IBlazeDatabase db = DbFactory.GetDatabase())
            {
                IBlazeTable scheduledTaskTable = db.GetTable(TableString.ScheduledTaskTableName);
                DataSet     ds = new DataSet();
                scheduledTaskTable.Get(ds);
                DataTable table = ds.Tables[TableString.ScheduledTaskTableName];
                foreach (DataRow row in table.Rows)
                {
                    try
                    {
                        int    id       = (int)row[TableString.ScheduledTaskFieldId];
                        byte[] taskData = (byte[])row[TableString.ScheduledTaskFieldTaskData];

                        MemoryStream   taskDataStream = new MemoryStream(taskData);
                        IFormatter     formatter      = new BinaryFormatter();
                        IScheduledTask task           = (IScheduledTask)formatter.Deserialize(taskDataStream);
                        if (task != null)
                        {
                            FSEyeObject secObj = AdminServer.TheInstance.SecurityManager.Get(id);
                            if (secObj != null)
                            {
                                task.SecurityObject = secObj;

                                ScheduledTaskUnit unit = new ScheduledTaskUnit();
                                unit.Task = task;
                                unit.AvoidCheckTimeout = 0;
                                _taskList.Add(unit);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Util.DebugLog(e.StackTrace);
                        continue;
                    }
                }
            }
        }
Example #10
0
        public bool LoadUpdateServer()
        {
            lock (this)
            {
                IBlazeDatabase db = null;
                try
                {
                    db = DbFactory.GetDatabase();
                    IBlazeTable table = db.GetTable(TableString.UpdateServerTableName);

                    DataSet data = new DataSet();
                    table.Get(data);
                    DataRowCollection rows = data.Tables[TableString.UpdateServerTableName].Rows;
                    foreach (DataRow row in rows)
                    {
                        int    id       = (int)row[TableString.UpdateServerFieldId];
                        string address  = row[TableString.UpdateServerFieldAddress] as string;
                        int    port     = (int)row[TableString.UpdateServerFieldPort];
                        string username = row[TableString.UpdateServerFieldUsername] as string;
                        string password = row[TableString.UpdateServerFieldPassword] as string;
                        string literal  = row[TableString.UpdateServerFieldLiteral] as string;
                        FTPServer.FTPServerType type = (FTPServer.FTPServerType)Enum.Parse(typeof(FTPServer.FTPServerType), row[TableString.UpdateServerFieldUpdateServerType].ToString());
                        FTPServer server             = new FTPServer(id, address, port, username, password, literal, type);
                        server.SecurityObject = AdminServer.TheInstance.SecurityManager.Get(id);
                        _FTPServerList.Add(server);
                    }
                }
                catch (Exception)
                {
                    return(false);
                }
                finally
                {
                    if (db != null)
                    {
                        db.Close();
                    }
                }
            }
            return(true);
        }
Example #11
0
        /// <summary>
        /// 载入策略配置
        /// </summary>
        public void Load()
        {
            this.SecurityObject = AdminServer.TheInstance.SecurityManager.Get(SecurityObjectStrategyManager);
            _strategyList.Clear();

            using (IBlazeDatabase db = DbFactory.GetDatabase())
            {
                IBlazeTable table        = db.GetTable(TableString.StrategyTableName);
                DataSet     strategyData = new DataSet();
                table.Get(strategyData);
                DataTable         strategyTable = strategyData.Tables[TableString.StrategyTableName];
                StrategyManager   sm            = AdminServer.TheInstance.StrategyManager;
                AutomationManager am            = AdminServer.TheInstance.AutomationManager;
                foreach (DataRow row in strategyTable.Rows)
                {
                    int strategyId = (int)row[TableString.StrategyFieldId];

                    try
                    {
                        Strategy strategy = new Strategy();
                        strategy.Event      = (FSEyeEvent)row[TableString.StrategyFieldEvent];
                        strategy.Automation = am.Load((byte[])row[TableString.StrategyFieldAutomation]);
                        strategy.Enabled    = ((int)row[TableString.StrategyFieldEnabled]) == 0 ? false : true;

                        FSEyeObject secObj = AdminServer.TheInstance.SecurityManager.Get(strategyId);
                        if (secObj != null)
                        {
                            strategy.SecurityObject = secObj;
                            _strategyList.Add(strategy);
                        }
                    }
                    catch (Exception e)
                    {
                        Util.DebugLog(e.StackTrace);
                        continue;
                    }
                }
            }
        }
Example #12
0
        /// <summary>
        /// 获取某日的最大人数
        /// </summary>
        /// <param name="day"></param>
        /// <returns></returns>
        int GetDayMaxPlayer(DateTime day)
        {
            DateTime startTime = DateTime.Parse(day.ToShortDateString() + " 00:00:00");
            DateTime endTime   = DateTime.Parse(day.ToShortDateString() + " 23:59:59");
            int      maxPlayer = 0;
            int      rowMax    = 0;

            using (IBlazeDatabase db = DbFactory.GetDatabase())
            {
                IBlazeTable table = db.GetTable(TableString.PlayerCountTableName);
                DataSet     ds    = new DataSet();
                table.Get(ds,
                          FilterFactory.CreateAndFilter(
                              FilterFactory.CreateEqualFilter(TableString.PlayerCountFieldServerId, _server.Id),
                              FilterFactory.CreateAndFilter(
                                  FilterFactory.CreateLargerEqualFilter(TableString.PlayerCountFieldRecordTime, startTime),
                                  FilterFactory.CreateLesserEqualFilter(TableString.PlayerCountFieldRecordTime, endTime)
                                  )
                              )
                          );

                DataTable dt = ds.Tables[TableString.PlayerCountTableName];

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow row = dt.Rows[i];
                    PlayerCountStatisticInfo info = new PlayerCountStatisticInfo();

                    rowMax = (int)row[TableString.PlayerCountFieldMaxPlayerCount];
                    if (maxPlayer < rowMax)
                    {
                        maxPlayer = rowMax;
                    }
                }

                return(maxPlayer);
            }
        }
Example #13
0
        public IList <IBShopScript> GetScript()
        {
            IBlazeDatabase       db         = null;
            IList <IBShopScript> resultList = new List <IBShopScript>();

            try
            {
                db = DbFactory.GetDatabase();
                DataSet dataSet = new DataSet();

                IBlazeTable ibShopTable = db.GetTable(TableString.IbShopTableName);
                ibShopTable.Get(dataSet);

                DataRowCollection rows = dataSet.Tables[TableString.IbShopTableName].Rows;
                foreach (DataRow row in rows)
                {
                    IBShopScript ibShopScript = new IBShopScript();
                    ibShopScript.ID        = (int)row[TableString.IbShopFieldId];
                    ibShopScript.TimeStamp = (DateTime)row[TableString.IbShopFieldTimeStamp];
                    ibShopScript.Script    = Encoding.Default.GetString(row[TableString.IbShopFieldScript] as byte[]);
                    resultList.Add(ibShopScript);
                }
                return(resultList);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (db != null)
                {
                    db.Close();
                }
            }
        }
Example #14
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();
                }
            }
        }
Example #15
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);
                }
            }
        }
    //按照filter来查询数据库,并对结果处理,将各个int值转化为对应的可读的string信息,
    //并且使其结构于页面中的ResultDataGrid一致。
    //将处理后生成的datatable返回,ResultDataGrid只须与其绑定即可。
    private DataTable QueryAndReturnResultDataTable(DbFilter filter)
    {
        //开始查询了
        using (IBlazeDatabase db = DbFactory.GetDatabase())
        {
            IBlazeTable table = db.GetTable(TableString.ServerOperationLogTableName);
            DataSet     ds    = new DataSet();
            table.Get(ds, filter);
            DataTable dt = ds.Tables[TableString.ServerOperationLogTableName];

            if (dt.Rows.Count == 0)
            {
                return(null);
            }

            //按照log_time升序进行排序
            dt.DefaultView.Sort = TableString.ServerOperationLogFieldLogTime + " ASC";

            DataTable finalDataTable = new DataTable();
            finalDataTable.Columns.Add(new DataColumn("operation_id", typeof(String)));
            finalDataTable.Columns.Add(new DataColumn("user_name", typeof(String)));
            finalDataTable.Columns.Add(new DataColumn("target_type", typeof(String)));
            finalDataTable.Columns.Add(new DataColumn("target_name", typeof(String)));
            finalDataTable.Columns.Add(new DataColumn("operation_type", typeof(String)));
            finalDataTable.Columns.Add(new DataColumn("operation_result", typeof(String)));
            finalDataTable.Columns.Add(new DataColumn("description", typeof(String)));
            finalDataTable.Columns.Add(new DataColumn("log_time", typeof(DateTime)));


            foreach (DataRow row in dt.Rows)
            {
                //新的datarow,要加入到finalDataTable中去的
                DataRow newRow = finalDataTable.NewRow();

                //设置显示结果中的操作流水号
                Int64 opId = (Int64)row[TableString.ServerOperationLogFieldOperationId];
                if (opId <= 0)
                {
                    newRow["operation_id"] = "不合法的操作流水号:必须为正整数";
                }
                else
                {
                    newRow["operation_id"] = opId.ToString();
                }

                //设置平台用户名
                int userId = (int)row[TableString.ServerOperationLogFieldUserId];
                FSEye.Security.User user = AdminServer.TheInstance.SecurityManager.GetUser(userId);
                if (user == null)
                {
                    newRow["user_name"] = "无此用户";
                }
                else
                {
                    newRow["user_name"] = user.UserName;
                }

                //设置操作对象类型和操作对象名称
                //targetId = -2表示对多个组开始进行操作,多个组名存在description字段中
                int isServerGroup = (int)row[TableString.ServerOperationLogFieldServerOrGroup];
                int targetId      = (int)row[TableString.ServerOperationLogFieldTargetId];
                if (isServerGroup == 1)
                {
                    newRow["target_type"] = "服务器组";
                    if (targetId == -2)
                    {
                        newRow["target_name"] = "";
                    }
                    else
                    {
                        ServerGroup serverGroup = AdminServer.TheInstance.GameServerManager.GetGameServerGroup(targetId);
                        if (serverGroup == null)
                        {
                            newRow["target_name"] = "无此服务器组";
                        }
                        else
                        {
                            newRow["target_name"] = serverGroup.Name;
                        }
                    }
                }
                else if (isServerGroup == 0)
                {
                    newRow["target_type"] = "服务器";
                    GameServer server = AdminServer.TheInstance.GameServerManager.GetGameServer(targetId);
                    if (server == null)
                    {
                        newRow["target_name"] = "无此服务器";
                    }
                    else
                    {
                        newRow["target_name"] = server.Name;
                    }
                }
                else
                {
                    newRow["target_type"] = "不合法的对象类型";
                    newRow["target_name"] = "不合法的操作对象";
                }

                //设置操作类型
                int opTypeInt = (int)row[TableString.ServerOperationLogFieldOperationType];
                GameServer.ServerOperationType opTypeEnum = (GameServer.ServerOperationType)Enum.Parse(typeof(GameServer.ServerOperationType), opTypeInt.ToString());
                switch (opTypeEnum)
                {
                case GameServer.ServerOperationType.Start:
                    newRow["operation_type"] = "启动";
                    break;

                case GameServer.ServerOperationType.Close:
                    newRow["operation_type"] = "关闭";
                    break;

                case GameServer.ServerOperationType.Update:
                    newRow["operation_type"] = "更新";
                    break;

                case GameServer.ServerOperationType.Download:
                    newRow["operation_type"] = "下载更新包";
                    break;

                case GameServer.ServerOperationType.UpdateConfigFile:
                    newRow["operation_type"] = "上传配置文件";
                    break;

                default:
                    newRow["operation_type"] = "未知操作类型";
                    break;
                }

                //设置操作结果
                int resultSuccess = (int)row[TableString.ServerOperationLogFieldOperationResult];
                if (resultSuccess == 1)
                {
                    newRow["operation_result"] = "成功";
                }
                else if (resultSuccess == 0)
                {
                    newRow["operation_result"] = "失败";
                }
                else
                {
                    newRow["operation_result"] = "不合法的操作结果";
                }

                //设置操作描述
                newRow["description"] = (String)row[TableString.ServerOperationLogFieldDescription];


                //设置日志记录时间
                newRow["log_time"] = (DateTime)row[TableString.ServerOperationLogFieldLogTime];

                //将newrow加入到finaldatatable中
                finalDataTable.Rows.Add(newRow);
            }

            return(finalDataTable);
        }
    }
Example #17
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);
        }
Example #18
0
    private string CreateStatisticMoneyImage(GameServer server, string dateFrom, string dateTo, ChartType type, bool showSymbol)
    {
        using (IBlazeDatabase db = DbFactory.GetDatabase())
        {
            IBlazeTable gameLogTable = db.GetTable(TableString.GameLogTableName);
            DataSet     data         = new DataSet();

            gameLogTable.Get(
                data,
                FilterFactory.CreateAndFilter(
                    FilterFactory.CreateEqualFilter(TableString.GameLogFieldGameServerId, server.Id),
                    FilterFactory.CreateAndFilter(
                        FilterFactory.CreateLargerEqualFilter(TableString.GameLogFieldDate, dateFrom),
                        FilterFactory.CreateLesserEqualFilter(TableString.GameLogFieldDate, dateTo)
                        )
                    )
                );

            DataTable table = data.Tables[0];

            int      count      = table.Rows.Count;
            double[] money      = new double[count];
            double[] moneyInBox = new double[count];
            double[] moneyTotal = new double[count];
            double[] date       = new double[count];
            for (int i = 0; i < count; i++)
            {
                DataRow row = table.Rows[i];
                money[i]      = (long)row[TableString.GameLogFieldTotalMoney];
                moneyInBox[i] = (long)row[TableString.GameLogFieldTotalMoneyInBox];
                moneyTotal[i] = money[i] + moneyInBox[i];
                DateTime currentDate = (DateTime)row[TableString.GameLogFieldDate];
                date[i] = new XDate(currentDate.Year, currentDate.Month, currentDate.Day);
            }

            bool success = true;

            if (success)
            {
                //»æÖÆͼ±í
                GraphPane graphPane = new GraphPane();

                graphPane.Title.Text = StringDef.MoneyStatistic;
                graphPane.Fill       = new Fill(WebConfig.GraphPaneBgColor);

                graphPane.Legend.Fill.IsVisible   = false;
                graphPane.Legend.Border.IsVisible = false;

                graphPane.XAxis.Title.Text          = StringDef.Date;
                graphPane.XAxis.MajorGrid.Color     = WebConfig.GraphXAxisGridColor;
                graphPane.XAxis.Type                = AxisType.DateAsOrdinal;
                graphPane.XAxis.MinorTic.Size       = 0;
                graphPane.XAxis.Scale.MajorStep     = 1;
                graphPane.XAxis.Scale.MajorUnit     = DateUnit.Day;
                graphPane.XAxis.Scale.FontSpec.Size = 12;
                graphPane.XAxis.Scale.Format        = "M-d";

                graphPane.YAxis.Title.Text          = StringDef.Money;
                graphPane.YAxis.MajorGrid.IsVisible = true;
                graphPane.YAxis.MajorGrid.DashOff   = 0;
                graphPane.YAxis.MajorGrid.Color     = Color.Gray;
                graphPane.YAxis.MinorGrid.IsVisible = true;
                graphPane.YAxis.MinorGrid.Color     = Color.LightGray;
                graphPane.YAxis.MinorGrid.DashOff   = 0;

                if (type == ChartType.Bar)
                {
                    graphPane.BarSettings.Type = BarType.Stack;

                    BarItem barItemMoney      = graphPane.AddBar(StringDef.Money, date, money, Colors[0]);
                    BarItem barItemMoneyInBox = graphPane.AddBar(StringDef.MoneyInBox, date, moneyInBox, Colors[1]);
                    barItemMoney.Bar.Fill      = new Fill(Colors[0]);
                    barItemMoneyInBox.Bar.Fill = new Fill(Colors[1]);
                }
                else if (type == ChartType.Line)
                {
                    LineItem lineItemMoney      = graphPane.AddCurve(StringDef.Money, date, money, Colors[0], (showSymbol ? WebConfig.GraphSymbols[0] : SymbolType.None));
                    LineItem lineItemMoneyInBox = graphPane.AddCurve(StringDef.MoneyInBox, date, moneyInBox, Colors[1], (showSymbol ? WebConfig.GraphSymbols[1] : SymbolType.None));
                    LineItem lineItemMoneyTotal = graphPane.AddCurve(StringDef.MoneyTotal, date, moneyTotal, Colors[2], (showSymbol ? WebConfig.GraphSymbols[2] : SymbolType.None));
                }

                Bitmap bitmap = new Bitmap(1, 1);
                using (Graphics g = Graphics.FromImage(bitmap))
                {
                    graphPane.AxisChange(g);
                }

                bitmap = graphPane.GetImage(WebConfig.StatisticRoleCountByLevelGraphWidth, WebConfig.StatisticRoleCountByLevelGraphHeight, 75.0f);
                string imageName = WebUtil.CreateRandomName("Statistic", WebConfig.GraphFileSuffix);
                string file      = WebConfig.WebsiteRootPath + WebConfig.TempGraphPath + imageName;
                try
                {
                    bitmap.Save(file, WebConfig.GraphImageFormat);
                    TempFileManager.TheInstance.AddTempFile(file, 5000 * WebConfig.TempGraphDeleteDelayMultiple);

                    return(imageName);
                }
                catch (Exception)
                {
                    //TODO ¼Ç¼´íÎó
                    return(null);
                }
            }

            return(null);
        }
    }