public static void LoadTables(IObjectDatabase Database, string DatabaseName) { List <string> typeNames = new List <string>(); foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { foreach (Type type in assembly.GetTypes()) { if (type.IsClass != true) { continue; } try { DataTable[] attrib = (DataTable[])type.GetCustomAttributes(typeof(DataTable), true); if (attrib.Length > 0 && attrib[0].DatabaseName == DatabaseName) { Database.RegisterDataObject(type); typeNames.Add(type.Name); } } catch (Exception e) { Log.Error("DBManager", "Can not load : " + e); } } } Log.Info("DBManager", "Registered table: " + string.Join(", ", typeNames)); }
public static void LoadTables(IObjectDatabase Database,string DatabaseName) { foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { foreach (Type type in assembly.GetTypes()) { if (type.IsClass != true) continue; try { DataTable[] attrib = (DataTable[])type.GetCustomAttributes(typeof(DataTable), true); if (attrib.Length > 0 && attrib[0].DatabaseName == DatabaseName) { Log.Info("DBManager", "Registering table: " + type.FullName); Database.RegisterDataObject(type); } } catch(Exception e) { Log.Error("DBManager", "Can not load : " + e.ToString()); } } } }
static public void LoadTables(IObjectDatabase Database, string DatabaseName) { foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { foreach (Type type in assembly.GetTypes()) { if (type.IsClass != true) { continue; } try { DataTable[] attrib = (DataTable[])type.GetCustomAttributes(typeof(DataTable), true); if (attrib.Length > 0 && attrib[0].DatabaseName == DatabaseName) { Log.Info("DBManager", "Registering table: " + type.FullName); Database.RegisterDataObject(type); } } catch (Exception e) { Log.Error("DBManager", "Can not load : " + e.ToString()); } } } }
private void LoadServerProperties() { // open data connection and grab datas sp.Clear(); sc.Clear(); try { db = ObjectDatabase.GetObjectDatabase(currentConfig.DBType, currentConfig.DBConnectionString); db.RegisterDataObject(typeof(ServerProperty)); db.RegisterDataObject(typeof(ServerPropertyCategory)); sp = db.SelectAllObjects <ServerProperty>().ToList(); sc = db.SelectAllObjects <ServerPropertyCategory>().ToList(); } catch { toolstrip_status_label.Text = "Unable to connect/read SQL database !"; return; } // reset display tv_spShow.Nodes.Clear(); // no SP_C table if (sc.Count == 0) { foreach (var current in sp) { tv_spShow.Nodes.Add(FormatNodeText(0, current.Key, current.Value)); tv_spShow.Nodes[tv_spShow.Nodes.Count - 1].ForeColor = Color.Blue; } } else { // creation of the SP map CreateSPMap(null, tv_spShow.Nodes, 0); } // how many SP we have ? 1.6millions ? :D toolstrip_status_label.Text = "Loaded: " + sp.Count() + " server properties."; }
public static void SetDatabaseConnection(IProgress <int> progress = null) { //Create a connection string using the string builder MySqlConnectionStringBuilder sb = ConnectionStringService.ConnectionString; sb.ConnectionTimeout = 2; var connectionString = sb.ConnectionString; Database = new MySQLObjectDatabase(connectionString); for (int i = 0; i < RegisteredObjects.Length; i++) { Database.RegisterDataObject(RegisteredObjects[i]); var perc = ((i + 1) / (decimal)RegisteredObjects.Length) * 100; progress?.Report((int)perc); } }
/*public static MySQLObjectDatabase Start(FileInfo configfile, ConnectionType Type, string DBName) * { * Log.Info("IObjectDatabase", "Starting..."); * XMLConfigFile xmlConfig = XMLConfigFile.ParseXMLFile(configfile); * if (xmlConfig == null) * { * Log.Error("IOBjectDatabase", "Invalid file : " + configfile); * return null; * } * * * string sqlconfig = xmlConfig["Database"]["DBInfo"].GetString(""); * * if (sqlconfig.Length <= 0) * { * Log.Error("IOBjectDatabase", "Invalid configuration : " + configfile); * return null; * } * * return Start(sqlconfig, Type, DBName); * }*/ public static MySQLObjectDatabase Start(string sqlconfig, ConnectionType Type, string DBName) { Log.Debug("IObjectDatabase", DBName + "->Start " + sqlconfig + "..."); IObjectDatabase _database = null; if (_database == null) { _database = ObjectDatabase.GetObjectDatabase(Type, sqlconfig); try { foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { foreach (Type type in assembly.GetTypes()) { if (type.IsClass != true) { continue; } DataTable[] attrib = (DataTable[])type.GetCustomAttributes(typeof(DataTable), true); if (attrib.Length > 0 && attrib[0].DatabaseName == DBName) { Log.Info("DBManager", "Registering table: " + type.FullName); _database.RegisterDataObject(type); } } } } catch (DatabaseException e) { Log.Error("DBManager", "Error at registering tables " + e.ToString()); return(null); } } return((MySQLObjectDatabase)_database); }
public void InitDB() { if (m_database == null) { m_database = ObjectDatabase.GetObjectDatabase(dolConfig.DBType, dolConfig.DBConnectionString); try { //We will search our assemblies for DataTables by reflection so //it is not neccessary anymore to register new tables with the //server, it is done automatically! foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { // Walk through each type in the assembly foreach (Type type in assembly.GetTypes()) { // Pick up a class if (type.IsClass != true) { continue; } object[] attrib = type.GetCustomAttributes(typeof(DataTable), true); if (attrib.Length > 0) { //Log.Info("Registering table: " + type.FullName); m_database.RegisterDataObject(type); } } } } catch (DatabaseException e) { QuestDesignerMain.HandleException(e); return; } } }
/// <summary> /// Initializes the database /// </summary> /// <returns>True if the database was successfully initialized</returns> public bool InitDB() { if (m_database == null) { m_database = ObjectDatabase.GetObjectDatabase(Configuration.DBType, Configuration.DBConnectionString); try { //We will search our assemblies for DataTables by reflection so //it is not neccessary anymore to register new tables with the //server, it is done automatically! foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { // Walk through each type in the assembly foreach (Type type in assembly.GetTypes()) { // Pick up a class // Aredhel: Ok, I know checking for InventoryArtifact type // is a hack, but I currently have no better idea. if (type.IsClass != true || type == typeof (InventoryArtifact)) continue; object[] attrib = type.GetCustomAttributes(typeof (DataTable), true); if (attrib.Length > 0) { if (log.IsInfoEnabled) log.Info("Registering table: " + type.FullName); m_database.RegisterDataObject(type); } } } } catch (DatabaseException e) { if (log.IsErrorEnabled) log.Error("Error registering Tables", e); return false; } } if (log.IsInfoEnabled) log.Info("Database Initialization: true"); return true; }
/// <summary> /// Initializes the database /// </summary> /// <returns>True if the database was successfully initialized</returns> public bool InitDB() { if (m_database == null) { m_database = ObjectDatabase.GetObjectDatabase(Configuration.DBType, Configuration.DBConnectionString); try { //We will search our assemblies for DataTables by reflection so //it is not neccessary anymore to register new tables with the //server, it is done automatically! foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { // Walk through each type in the assembly foreach (Type type in assembly.GetTypes()) { if (!type.IsClass || type.IsAbstract) continue; var attrib = type.GetCustomAttributes<DataTable>(false); if (attrib.Any()) { if (log.IsInfoEnabled) log.InfoFormat("Registering table: {0}", type.FullName); m_database.RegisterDataObject(type); } } } } catch (DatabaseException e) { if (log.IsErrorEnabled) log.Error("Error registering Tables", e); return false; } } if (log.IsInfoEnabled) log.Info("Database Initialization: true"); return true; }
public void InitDB() { if (m_database == null) { m_database = ObjectDatabase.GetObjectDatabase(dolConfig.DBType, dolConfig.DBConnectionString); try { //We will search our assemblies for DataTables by reflection so //it is not neccessary anymore to register new tables with the //server, it is done automatically! foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { // Walk through each type in the assembly foreach (Type type in assembly.GetTypes()) { // Pick up a class if (type.IsClass != true) continue; object[] attrib = type.GetCustomAttributes(typeof(DataTable), true); if (attrib.Length > 0) { //Log.Info("Registering table: " + type.FullName); m_database.RegisterDataObject(type); } } } } catch (DatabaseException e) { QuestDesignerMain.HandleException(e); return; } } }