Example #1
0
        public List <WorldObject> ObjectsInRange(Rectangle2D area, EDatabaseType type)
        {
            List <WorldObject> list = new List <WorldObject>();
            MapBlock           block;

            for (int x = area.X / Global.BLOCK_SIZE; x < area.EndX / Global.BLOCK_SIZE; ++x)
            {
                for (int y = area.Y / Global.BLOCK_SIZE; y < area.EndY / Global.BLOCK_SIZE; ++y)
                {
                    if ((block = GetBlockReal(x, y)) == null)
                    {
                        continue;
                    }

                    if (type != EDatabaseType.All)
                    {
                        foreach (WorldObject obj in block.Values)
                        {
                            if ((obj.WorldID.Type & type) > 0)
                            {
                                list.Add(obj);
                            }
                        }
                    }
                    else
                    {
                        list.AddRange(block.Values);
                    }
                }
            }
            return(list);
        }
        public IDatabaseCollector Create(EDatabaseType type)
        {
            IDatabaseCollector collector = null;

            try
            {
                switch (type)
                {
                case EDatabaseType.Oracle:
                    collector = new OracleCollector();
                    break;

                case EDatabaseType.SqlServer:
                    collector = new SqlServerCollector();
                    break;

                case EDatabaseType.Postgres:
                    collector = new PostgresCollector();
                    break;

                case EDatabaseType.Unknown:
                default:
                    throw new Exception($"Unknown database type {type}");
                }
            }
            catch (Exception ex)
            {
                ApplicationEventLog log = new ApplicationEventLog();
                log.LogError("Error in DatabaseCollectorFactory connection");
                log.Log(ex);
            }

            return(collector);
        }
Example #3
0
        /// <summary>Returns a new ID for the object type</summary>
        /// <param name="type">The object type</param>
        /// <returns>The new ID</returns>
        public static WorldID Dynamic(EDatabaseType type)
        {
            switch (type)
            {
            case EDatabaseType.Battleground:
                return(WorldID.NewBattlegroundID);

            case EDatabaseType.Chat:
                return(WorldID.NewChatID);

            case EDatabaseType.Homunculus:
                return(WorldID.NewHomunculusID);

            case EDatabaseType.Item:
                return(WorldID.NewItemID);

            case EDatabaseType.Mercenary:
                return(WorldID.NewMercenaryID);

            case EDatabaseType.Mob:
                return(WorldID.NewMobID);

            case EDatabaseType.Npc:
                return(WorldID.NewNpcID);

            case EDatabaseType.Pet:
                return(WorldID.NewPetID);

            default:
                //throw new Exception("Bad database type for world object: " + type);
                return(0);
            }
        }
Example #4
0
        /// <summary>
        /// 获取连接对象
        /// </summary>
        /// <param name="databaseType">数据提供程序</param>
        private DbConnection CreateConnection(EDatabaseType databaseType, string connectionString = "")
        {
            DbConnection conn = null;

            switch (databaseType)
            {
            case EDatabaseType.MSSQL:
                conn = new SqlConnection(connectionString);
                break;

            case EDatabaseType.MySQL:
                conn = new MySqlConnection(connectionString);
                break;

            case EDatabaseType.Oracle:
                conn = new OracleConnection(connectionString);
                break;

            case EDatabaseType.SQLite:
                conn = new SQLiteConnection(connectionString);
                break;

            default:
                throw new NotImplementedException();
            }
            return(conn);
        }
 public ConnectionInfo(string hostName,
                       int port,
                       string userName,
                       string password,
                       string databaseName,
                       EDatabaseType databaseType)
     : this(hostName, port, userName, password, databaseName, databaseType, "Default")
 {
 }
Example #6
0
        public void ForeachInRange(Rectangle2D area, EDatabaseType type, ForeachInRangeVoidDelegate callback, object[] args)
        {
            List <WorldObject> objects = ObjectsInRange(area, type);

            for (int i = 0; i < objects.Count; i++)
            {
                WorldObject obj = objects[i];
                callback(obj, args);
            }
        }
Example #7
0
 //未能加载文件或程序集“Oracle.DataAccess, Version=2.111.7.20, Culture=neutral, PublicKeyToken=89b483f429c47342”或它的某一个依赖项。系统找不到指定的文件。
 //把程序目标平台设置为x86
 public DbSession(EDatabaseType databaseType, string connectString = null)
 {
     if (connectString == null)
     {
         connectString = new System.Configuration.AppSettingsReader().GetValue("DefaultConnectString", typeof(string)).ToString();
     }
     this.DatabaseType = databaseType;
     this.Connection   = CreateConnection(databaseType, connectString);
     //this.Open();
 }
        private EDatabaseType DbTypeWhichWillBeUsedWithEF()
        {
            var firstLineOfFile = File.ReadAllLines(DatabaseForOrmConfigFileLocation)
                                  .First();

            EDatabaseType outResult;

            EDatabaseType.TryParse(firstLineOfFile, out outResult);
            return(outResult);
        }
Example #9
0
        public void getDatas(EDatabaseType dType, ref List<DatabaseObj> list, int iStart, out int iRest)
        {
            iRest = 0;

            DatabaseObj _dObj = null;
            if (EDatabaseType.EUserAccount == dType)
            {
                _dObj = new UserAccountAdapter();
            }
            else if (EDatabaseType.ESearchFactor == dType)
            {
                _dObj = new SearchFactorAdapter();
            }
            else if (EDatabaseType.EForbiddenCorp == dType)
            {
                _dObj = new ForbiddenCorpAdapter();
            }
            else
            {
                return;
            }

            string _szFileName = AutorConstPool.DATABASEPATH + _dObj.getTitle() + AutorConstPool.FILE_SUFFIX;
            ConfigFileReader _cfr = new ConfigFileReader(_szFileName);
            if (!_cfr.read())
                return;

            const int _limitedLines = 100;
            List<List<string>> _valueRows = _cfr.getValueRows();
            List<string> _attrNames = _cfr.getAttrNames();

            for (int _i = 0; _i < _valueRows.Count; _i++)
            {
                if (_i < iStart || _valueRows[_i].Count < _attrNames.Count)
                    continue;
                if (_i == _limitedLines)
                {
                    iRest = _valueRows.Count - _i;
                    break;
                }

                DatabaseObj _obj = _dObj.clone();
                if (null == _obj)
                    continue;

                for (int _j = 0; _j < _attrNames.Count; _j++)
                {
                    _obj.setValue(_attrNames[_j], _valueRows[_i][_j]);
                }
                list.Add(_obj);
            }
            return;
        }
Example #10
0
        public static string GetDatabaseConnectionString(EDatabaseType databaseType)
        {
            var databaseTypeStr = databaseType.ToString();

            if (ConnectionStringPerDatabase.ContainsKey(databaseTypeStr))
            {
                return(ConnectionStringPerDatabase[databaseTypeStr]);
            }
            else
            {
                throw new Exception("Database type does not have implementation yet");
            }
        }
Example #11
0
        private ODatabaseType Convert(EDatabaseType databaseType)
        {
            switch (databaseType)
            {
            case EDatabaseType.Document:
                return(ODatabaseType.Document);

            case EDatabaseType.Graph:
                return(ODatabaseType.Graph);

            default:
                throw new ArgumentOutOfRangeException(nameof(databaseType), databaseType, null);
            }
        }
Example #12
0
        /// <summary>
        /// 获取参数生成器
        /// </summary>
        /// <param name="databaseType">数据提供程序</param>
        IDbParameterGenerator GetParameterGenerator(EDatabaseType databaseType)
        {
            IDbParameterGenerator parameterGenerator = null;

            switch (databaseType)
            {
            case EDatabaseType.MSSQL:
            case EDatabaseType.Oracle:
            case EDatabaseType.MySQL:
                break;

            default:
                throw new NotImplementedException();
            }
            return(parameterGenerator);
        }
 public ConnectionInfo(string hostName,
                       int port,
                       string userName,
                       string password,
                       string databaseName,
                       EDatabaseType databaseType,
                       string poolAlias)
 {
     HostName     = hostName;
     UserName     = userName;
     Password     = password;
     Port         = port;
     DatabaseName = databaseName;
     DatabaseType = databaseType;
     PoolAlias    = poolAlias;
 }
Example #14
0
        /// <summary>
        /// 依資料庫類型建立資料庫命令輔助類別。
        /// </summary>
        /// <param name="databaseType">資料庫類型。</param>
        /// <param name="commandText">命令字串。</param>
        public static IDbCommandHelper CreateDbCommandHelper(EDatabaseType databaseType, string commandText)
        {
            string sMessage;

            switch (databaseType)
            {
            case EDatabaseType.SQLServer:
                return(new GSqlCommandHelper(commandText));

            case EDatabaseType.Oracle:
                return(new GOracleCommandHelper(commandText));

            default:
                sMessage = StrFunc.StrFormat(@"DatabaseType={0} Not Supported IDbCommandHelper", BaseFunc.GetEnumName(databaseType));
                throw new NotSupportedException(sMessage);
            }
        }
Example #15
0
        public void getDatas(EDatabaseType dType, ref List<Object> list, out int iRest)
        {
            List<DatabaseObj> _objList = new List<DatabaseObj>();
            m_DatabaseAccesor.getDatas(dType, ref _objList, out iRest);

            if (0 == _objList.Count)
                return;

            if (EDatabaseType.EUserAccount == dType)
            {
                foreach(DatabaseObj _obj in _objList)
                {
                    Object _ua = new SUserAccount();

                    _obj.put(ref _ua);
                    list.Add(_ua);
                }
            }
            else if (EDatabaseType.ESearchFactor == dType)
            {
                foreach (DatabaseObj _obj in _objList)
                {
                    Object _ua = new SSearchFactor();

                    _obj.put(ref _ua);
                    list.Add(_ua);
                }
            }
            else if (EDatabaseType.EForbiddenCorp == dType)
            {
                foreach (DatabaseObj _obj in _objList)
                {
                    Object _ua = new SForbiddenCorp();

                    _obj.put(ref _ua);
                    list.Add(_ua);
                }
            }
            return;
        }
Example #16
0
        public void CreateFromStringProperly()
        {
            EDatabaseType type = "SqlServer".GetDatabaseType();

            Assert.Equal(EDatabaseType.SqlServer, type);

            type = "Oracle".GetDatabaseType();
            Assert.Equal(EDatabaseType.Oracle, type);

            type = "Postgres".GetDatabaseType();
            Assert.Equal(EDatabaseType.Postgres, type);

            type = "sQLsERVER".GetDatabaseType();
            Assert.Equal(EDatabaseType.SqlServer, type);

            type = "unknown".GetDatabaseType();
            Assert.Equal(EDatabaseType.Unknown, type);

            type = "lsjfioaerkjaosdfjlkserjoivuahg".GetDatabaseType();
            Assert.Equal(EDatabaseType.Unknown, type);

            type = string.Empty.GetDatabaseType();
            Assert.Equal(EDatabaseType.Unknown, type);
        }
Example #17
0
 /// <summary>
 /// Main Constructor
 /// <para>NOTE: use <see cref="WorldID.NewItemID"/> and the other static properties!</para>
 /// </summary>
 /// <param name="WorldID"></param>
 /// <param name="type"></param>
 public WorldID(uint id, EDatabaseType type)
 {
     mWorldID     = id;
     mWorldIDType = type;
 }
Example #18
0
 public virtual void UpdateDatabaseID(uint id, EDatabaseType type)
 {
     mDatabaseID   = new DatabaseID(id, type);
     mDatabaseData = null;
 }
Example #19
0
 public WorldObject this[EDatabaseType type, int id] {
     get { return(this[type, (uint)id]); }
 }
Example #20
0
 public WorldObject this[EDatabaseType type, uint id] {
     get { return(this[new WorldID(id, type)]); }
 }
Example #21
0
		public void ForeachInRange(Rectangle2D area, EDatabaseType type, ForeachInRangeVoidDelegate callback, object[] args) {
			List<WorldObject> objects = ObjectsInRange(area, type);

			for (int i = 0; i < objects.Count; i++) {
				WorldObject obj = objects[i];
				callback(obj, args);
			}

		}
		public WorldObject this[EDatabaseType type, uint id] {
			get { return this[new WorldID(id, type)]; }
		}
Example #23
0
 public DatabaseID(long id, EDatabaseType type)
     : this((uint)id, type)
 {
 }
Example #24
0
 public DatabaseObject this[EDatabaseType type, uint id] {
     get { return(this[new DatabaseID(id, type)]); }
 }
Example #25
0
		public DatabaseObject this[EDatabaseType type, uint id] {
			get { return this[new DatabaseID(id, type)]; }
		}
Example #26
0
		public List<WorldObject> ObjectsInRange(Rectangle2D area, EDatabaseType type) {
			List<WorldObject> list = new List<WorldObject>();
			MapBlock block;
			for (int x = area.X / Global.BLOCK_SIZE; x < area.EndX / Global.BLOCK_SIZE; ++x) {
				for (int y = area.Y / Global.BLOCK_SIZE; y < area.EndY / Global.BLOCK_SIZE; ++y) {
					if ((block = GetBlockReal(x, y)) == null) {
						continue;
					}

					if (type != EDatabaseType.All) {
						foreach (WorldObject obj in block.Values) {
							if ((obj.WorldID.Type & type) > 0) {
								list.Add(obj);
							}
						}
					} else {
						list.AddRange(block.Values);
					}
				}
			}
			return list;
		}
Example #27
0
		public DatabaseObject this[EDatabaseType type, int id] {
			get { return this[type, (uint)id]; }
		}
Example #28
0
 public DbConfigItem(string dbName)
 {
     DbName           = dbName;
     ConnectingString = "";
     DbType           = EDatabaseType.None;
 }
Example #29
0
 public DatabaseID(uint id, EDatabaseType type)
 {
     ID   = id;
     Type = type;
 }
Example #30
0
 /// <summary>
 /// 依資料庫類型建立資料庫命令輔助類別。
 /// </summary>
 /// <param name="databaseType">資料庫類型。</param>
 public static IDbCommandHelper CreateDbCommandHelper(EDatabaseType databaseType)
 {
     return(CreateDbCommandHelper(databaseType, string.Empty));
 }
Example #31
0
 /// <summary>
 /// Main Constructor
 /// <para>NOTE: use <see cref="WorldID.NewItemID"/> and the other static properties!</para>
 /// </summary>
 /// <param name="WorldID"></param>
 /// <param name="type"></param>
 public WorldID(long WorldID, EDatabaseType type)
     : this((uint)WorldID, type)
 {
 }
Example #32
0
 public void getDatas(EDatabaseType dType, ref List<DatabaseObj> list, out int iRest)
 {
     getDatas(dType, ref list, 0, out iRest);
 }
Example #33
0
 /// <summary>
 /// Simplifies the bit-type checking, should be implemented for all bit-flag enums..
 /// </summary>
 /// <param name="type"></param>
 /// <param name="test"></param>
 /// <returns></returns>
 public static bool And(this EDatabaseType type, EDatabaseType test)
 {
     return((type & test) > 0);
 }
Example #34
0
 public void Init(XElement element)
 {
     ConnectingString = element.Attribute(nameof(ConnectingString)).Value;
     DbType           = (EDatabaseType)Enum.Parse(typeof(EDatabaseType), element.Attribute(nameof(DbType)).Value);
 }
Example #35
0
		/// <summary>
		/// Simplifies the bit-type checking, should be implemented for all bit-flag enums..
		/// </summary>
		/// <param name="type"></param>
		/// <param name="test"></param>
		/// <returns></returns>
		public static bool And(this EDatabaseType type, EDatabaseType test) {
			return (type & test) > 0;
		}
 private DatabaseType(EDatabaseType dbType)
 {
     this.type = dbType;
 }
Example #37
0
        static void Main(string[] args)
        {
            //gov.sandia.sld.common.logging.EventLog.GlobalSource = "COMMONCLI";

            string        ip_address                    = string.Empty;
            string        username                      = string.Empty;
            string        password                      = string.Empty;
            string        connection_string             = string.Empty;
            EDatabaseType db_type                       = EDatabaseType.Unknown;
            int           repeat_count                  = 1;
            int           pause_seconds_between_repeats = 1;
            List <string> to_collect                    = new List <string>();
            bool          show_usage                    = false;

            for (int i = 0; i < args.Length; ++i)
            {
                switch (args[i])
                {
                case "/u":
                    if (i + 1 < args.Length)
                    {
                        username = args[++i].Trim();
                    }
                    break;

                case "/p":
                    if (i + 1 < args.Length)
                    {
                        password = args[++i].Trim();
                    }
                    break;

                case "/i":
                    if (i + 1 < args.Length)
                    {
                        ip_address = args[++i].Trim();
                    }
                    break;

                case "/d":
                {
                    switch (args[++i].Trim().ToLower())
                    {
                    case "sqlserver":
                        db_type = EDatabaseType.SqlServer;
                        break;

                    case "oracle":
                        db_type = EDatabaseType.Oracle;
                        break;

                    case "postgres":
                        db_type = EDatabaseType.Postgres;
                        break;
                    }
                    break;
                }

                case "/c":
                    connection_string = args[++i];
                    break;

                case "/r":
                    int.TryParse(args[++i], out repeat_count);
                    break;

                case "/s":
                    int.TryParse(args[++i], out pause_seconds_between_repeats);
                    break;

                case "/?":
                    show_usage = true;
                    break;

                default:
                    to_collect.Add(args[i]);
                    break;
                }
            }

            RequestBus.Instance.Subscribe(new PingResponder(ip_address));
            //RequestBus.Instance.Subscribe(new SystemErrorsInfoResponder());

            Remote r           = null;
            string device_name = "local";

            if (string.IsNullOrEmpty(ip_address) == false &&
                string.IsNullOrEmpty(username) == false &&
                string.IsNullOrEmpty(password) == false)
            {
                r           = new Remote(ip_address, username, password);
                device_name = ip_address;
            }

            CollectorID c_id = new CollectorID(-1, device_name);
            Dictionary <string, DataCollector> collector_map = new Dictionary <string, DataCollector>();

            collector_map["disk"]         = new DiskUsageCollector(c_id, r);
            collector_map["disknames"]    = new DiskNameCollector(c_id, r);
            collector_map["smart"]        = new SMARTCollector(c_id, r);
            collector_map["memory"]       = new MemoryUsageCollector(c_id, r);
            collector_map["cpu"]          = new CPUUsageCollector(c_id, r);
            collector_map["nic"]          = new NICUsageCollector(c_id, r);
            collector_map["uptime"]       = new UptimeCollector(c_id, r);
            collector_map["boot"]         = new LastBootTimeCollector(c_id, r);
            collector_map["processes"]    = new ProcessesCollector(c_id, r);
            collector_map["applications"] = new ApplicationsCollector(c_id, r);
            collector_map["services"]     = new ServicesCollector(c_id, r);
            collector_map["ups"]          = new UPSCollector(c_id, r);
            collector_map["database"]     = new DatabaseSizeCollector(c_id, false, new DatabaseCollectorFactory())
            {
                DBType           = db_type,
                ConnectionString = connection_string
            };
            //collector_map["antivirus"] = new AntiVirusCollector(c_id, r);
            //collector_map["firewall"] = new FirewallCollector(c_id, r);
            collector_map["ping"]              = new PingCollector(c_id);
            collector_map["systemerrors"]      = new SystemErrorLogCollector(c_id, r);
            collector_map["applicationerrors"] = new ApplicationErrorLogCollector(c_id, r);

            if (show_usage)
            {
                ShowUsage(collector_map.Keys);
                return;
            }

            if (to_collect.Count == 0)
            {
                foreach (string collector in collector_map.Keys)
                {
                    to_collect.Add(collector);
                }
            }

            List <DataCollector> c = new List <DataCollector>();

            foreach (string collector in to_collect)
            {
                if (collector_map.TryGetValue(collector, out DataCollector c2))
                {
                    c2.AttachDataAcquiredHandler(OnDataAcquired);
                    c.Add(c2);
                }
                else
                {
                    WriteLine($"Unknown collector: {collector}");
                }
            }

            if (c.Count == 0)
            {
                ShowUsage(collector_map.Keys);
            }
            else
            {
                GlobalIsRunning.IsRunning = true;

                for (int i = 0; i < repeat_count; ++i)
                {
                    foreach (DataCollector collector in c)
                    {
                        if (collector is PingCollector)
                        {
                            WriteLine($"Pinging {ip_address}");
                        }
                        else
                        {
                            WriteLine($"Collecting {collector.Context.Name}:");
                        }

                        watch = Stopwatch.StartNew();
                        collector.Acquire();
                    }

                    if ((i + 1) < repeat_count && pause_seconds_between_repeats > 0)
                    {
                        Thread.Sleep(pause_seconds_between_repeats * 1000);
                    }
                }
            }
        }