private static STA.Settings.INIFile GetINI(string configFileName) { var rootPath = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName; var path = Path.Combine(rootPath, configFileName); STA.Settings.INIFile ini = new STA.Settings.INIFile(path); return(ini); }
private void cmdChangeSQLPort_Click(object sender, EventArgs e) { try { UInt16 newPort; UInt16 oldPort; if (UInt16.TryParse(txtSQLConnectionPort.Text, out newPort)) { Boolean isOccupied = DBProcess.IsListenerOnPort(newPort) || DBProcess.IsConnectionOnPort(newPort); if (!isOccupied) { oldPort = Program.IniFile.GetValue <UInt16>("DB_Server", "Port", "3306"); if (MessageBox.Show(this, "Change db-port from " + oldPort + " to " + newPort + " ?", "Aborted", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK) { // switch off the general log for the database STA.Settings.INIFile dbIniFile; if (Debugger.IsAttached) { dbIniFile = new STA.Settings.INIFile(Path.Combine(Program.IniFile.GetValue("DB_Server", "WorkingDirectory", @"..\..\..\RNDatabase\Database"), "Elite.ini"), false, true, true); } else { dbIniFile = new STA.Settings.INIFile(Program.GetDataPath(@"Database\Elite.ini"), false, true, true); } Program.IniFile.SetValue("DB_Server", "Port", newPort.ToString()); dbIniFile.SetValue("mysqld", "port", newPort.ToString()); MessageBox.Show(this, "Port changed, restart required.", "Changed configuration", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { txtSQLConnectionPort.Text = Program.IniFile.GetValue <UInt16>("DB_Server", "Port", "3306").ToString(); } } else { MessageBox.Show(this, "Selected port is already occupied", "Aborted", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtSQLConnectionPort.Text = Program.IniFile.GetValue <UInt16>("DB_Server", "Port", "3306").ToString(); } } else { MessageBox.Show(this, "Couldn't parse value as <UInt16>", "Aborted", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtSQLConnectionPort.Text = Program.IniFile.GetValue <UInt16>("DB_Server", "Port", "3306").ToString(); } } catch (Exception ex) { CErr.processError(ex, "Error while changing the tcp-port of the sql-server"); } }
public static void Save <T>(T config, string configFileName = "config.ini") where T : new() { STA.Settings.INIFile ini = GetINI(configFileName); var t = typeof(T); var props = t.GetProperties(BindingFlags.Instance | BindingFlags.Public); foreach (var p in props) { var method = ini.GetType().GetMethod("SetValue", new Type[] { typeof(string), typeof(string), p.PropertyType }); method.Invoke(ini, new object[] { "", p.Name, p.GetValue(config, null) }); } }
public static T Load <T>(string configFileName = "config.ini") where T : new() { STA.Settings.INIFile ini = GetINI(configFileName); var t = typeof(T); var props = t.GetProperties(BindingFlags.Instance | BindingFlags.Public); var config = new T(); foreach (var p in props) { var method = ini.GetType().GetMethod("GetValue", new Type[] { typeof(string), typeof(string), p.PropertyType }); p.SetValue(config, method.Invoke(ini, new object[] { "", p.Name, GetDefaultValue(p.PropertyType) }), null); } return(config); }
/// <summary> /// starts the initialization of the global objects /// </summary> public static void Init() { try { if (!m_initDone) { Program.SplashScreen.Logger = MainLog; Program.SplashScreen.InfoAdd("initializing logger..."); Program.MainLog.Log("Initialising...\n"); Program.SplashScreen.InfoAppendLast("<OK>"); Program.SplashScreen.InfoAdd("starting sql server..."); // load settings from file IniFile = new STA.Settings.INIFile(GetDataPath("ED-IBE.ini"), false, true); // prepare architecture-dependend files PrepareDepFiles(); // start database process (if not running) DBProcess.DBProcessParams newProcessParams = new DBProcess.DBProcessParams() { }; newProcessParams.Commandline = IniFile.GetValue("DB_Server", "Commandline", @"bin\mysqld.exe"); newProcessParams.Commandargs = IniFile.GetValue("DB_Server", "CommandArgs", @"--defaults-file=Elite.ini --console"); newProcessParams.Workingdirectory = IniFile.GetValue("DB_Server", "WorkingDirectory", @"..\..\..\RNDatabase\Database"); newProcessParams.Port = IniFile.GetValue <UInt16>("DB_Server", "Port", "3306"); newProcessParams.DBStartTimeout = IniFile.GetValue <Int16>("DB_Server", "DBStartTimeout", "60"); Program.SplashScreen.InfoAppendLast("on port " + newProcessParams.Port + "..."); EliteDBProcess = new DBProcess(newProcessParams); if (EliteDBProcess.WasRunning) { Program.SplashScreen.InfoAppendLast("already running...<OK>"); } else { Program.SplashScreen.InfoAppendLast("<OK>"); } // connecT to the database Program.SplashScreen.InfoAdd("connect to sql server..."); DBConnector.ConnectionParams newConnectionParams = new DBConnector.ConnectionParams() { }; newConnectionParams.Name = IniFile.GetValue("DB_Connection", "Name", "master"); newConnectionParams.Server = IniFile.GetValue("DB_Connection", "Server", "localhost"); newConnectionParams.Port = IniFile.GetValue <UInt16>("DB_Server", "Port", "3306"); newConnectionParams.Database = IniFile.GetValue("DB_Connection", "Database", "Elite_DB"); newConnectionParams.User = IniFile.GetValue("DB_Connection", "User", "RN_User"); newConnectionParams.Pass = IniFile.GetValue("DB_Connection", "Pass", "Elite"); newConnectionParams.ConnectTimeout = IniFile.GetValue <Int16>("DB_Connection", "ConnectTimeout", "60"); newConnectionParams.StayAlive = IniFile.GetValue <Boolean>("DB_Connection", "StayAlive", "false"); newConnectionParams.TimeOut = IniFile.GetValue <Int16>("DB_Connection", "TimeOut", "10000"); DBCon = new DBConnector(newConnectionParams); DBCon.Connect(); Program.SplashScreen.InfoAppendLast("<OK>"); /* **************** database is running ********************** */ /* perform updates */ Updater.DBUpdate(); if (DBCon.getIniValue <Boolean>(IBESettingsView.DB_GROUPNAME, "AutoMinimize", false.ToString(), false)) { Program.SplashScreen.AutoMinimizeAsync(); } Program.SplashScreen.InfoAdd("preparing global objects..."); // prepare colors-object Colors = new GUIColors(); // preprare main data object Data = new IBE.SQL.EliteDBIO(); Data.PrepareBaseTables(); // create global paths-object //Paths = new ProgramPaths(); // prepare settings // Settings = new Settings(); // Settings.BaseData = Data.BaseData; // prepare commanders log CommandersLog = new CommandersLog(); CommandersLog.BaseData = Data.BaseData; // prepare price analysis PriceAnalysis = new PriceAnalysis(new DBConnector(DBCon.ConfigData, true)); PriceAnalysis.BaseData = Data.BaseData; //// starting the external data interface //ExternalData = new ExternalDataInterface(); // Companion IO CompanionIO = new IBECompanion.CompanionData(Program.GetDataPath()); if (CompanionIO.ConditionalLogIn()) { CompanionIO.GetProfileDataAsync(); } // initializing the object for the actual condition actualCondition = new Condition(); // initializing the LogfileScanner //LogfileScanner = new EDLogfileScanner(); JournalScanner = new EDJournalScanner(); // EDDN Interface EDDNComm = new IBE.EDDN.EDDNCommunicator(); // EDSMComm Interface EDSMComm = new IBE.EDSM.EDStarmapInterface(Program.DBCon); CommandersLog.registerJournalScanner(JournalScanner); CommandersLog.registerExternalTool(CompanionIO); CompanionIO.registerJournalScanner(JournalScanner); PriceAnalysis.registerJournalScanner(JournalScanner); PriceAnalysis.registerExternalTool(CompanionIO); EDSMComm.registerJournalScanner(JournalScanner); actualCondition.RegisterJournalScanner(JournalScanner); EDDNComm.RegisterJournalScanner(JournalScanner); // Plausibility-Checker PlausibiltyCheck = new PlausibiltyChecker(); /// early variant of DoSpecial(); Updater.DoSpecial_Early(); Program.SplashScreen.InfoAppendLast("<OK>"); m_initDone = true; } } catch (Exception ex) { CErr.processError(ex, "Error while initializing the program object"); } }
private static void UpdateTo_0_1_5() { // switch off the general log for the database STA.Settings.INIFile dbIniFile; if (Debugger.IsAttached) dbIniFile = new STA.Settings.INIFile(Path.Combine(Program.IniFile.GetValue("DB_Server", "WorkingDirectory", @"..\..\..\RNDatabase\Database"), "Elite.ini"), false, true, true); else dbIniFile = new STA.Settings.INIFile(Program.GetDataPath(@"Database\Elite.ini"), false, true, true); dbIniFile.RemoveValue("mysqld", "general-log"); }
/// <summary> /// starts the initialization of the global objects /// </summary> public static void Init() { try { if(!m_initDone) { Program.SplashScreen = new SplashScreenForm(); Program.SplashScreen.Show(); Program.SplashScreen.InfoAdd("initializing logger..."); Program.Logger = new SingleThreadLogger(ThreadLoggerType.Form); Program.Logger.Log("Initialising...\n"); Program.SplashScreen.InfoAppendLast("<OK>"); Program.SplashScreen.InfoAdd("starting sql server..."); // load settings from file IniFile = new STA.Settings.INIFile(GetDataPath("ED-IBE.ini"), false, true); // starT database process (if not running) DBProcess.DBProcessParams newProcessParams = new DBProcess.DBProcessParams() { }; newProcessParams.Commandline = IniFile.GetValue("DB_Server", "Commandline", @"bin\mysqld.exe"); newProcessParams.Commandargs = IniFile.GetValue("DB_Server", "CommandArgs", @"--defaults-file=Elite.ini --console"); newProcessParams.Workingdirectory = IniFile.GetValue("DB_Server", "WorkingDirectory", @"..\..\..\RNDatabase\Database"); newProcessParams.Port = IniFile.GetValue<Int16>("DB_Server", "Port", "3306"); newProcessParams.DBStartTimeout = IniFile.GetValue<Int16>("DB_Server", "DBStartTimeout", "60"); EliteDBProcess = new DBProcess(newProcessParams); if (EliteDBProcess.WasRunning) Program.SplashScreen.InfoAppendLast("already running...<OK>"); else Program.SplashScreen.InfoAppendLast("<OK>"); // connecT to the database Program.SplashScreen.InfoAdd("connect to sql server..."); DBConnector.ConnectionParams newConnectionParams = new DBConnector.ConnectionParams() { }; newConnectionParams.Name = IniFile.GetValue("DB_Connection", "Name", "master"); newConnectionParams.Server = IniFile.GetValue("DB_Connection", "Server", "localhost"); newConnectionParams.Database = IniFile.GetValue("DB_Connection", "Database", "Elite_DB"); newConnectionParams.User = IniFile.GetValue("DB_Connection", "User", "RN_User"); newConnectionParams.Pass = IniFile.GetValue("DB_Connection", "Pass", "Elite"); newConnectionParams.ConnectTimeout = IniFile.GetValue<Int16>("DB_Connection", "ConnectTimeout", "60"); newConnectionParams.StayAlive = IniFile.GetValue<Boolean>("DB_Connection", "StayAlive", "false"); newConnectionParams.TimeOut = IniFile.GetValue<Int16>("DB_Connection", "TimeOut", "60"); DBCon = new DBConnector(newConnectionParams); DBCon.Connect(); Program.SplashScreen.InfoAppendLast("<OK>"); /* **************** database is running ********************** */ Program.SplashScreen.InfoAdd("preparing global objects..."); // prepare colors-object Colors = new GUIColors(); // preprare main data object Data = new IBE.SQL.EliteDBIO(); Data.PrepareBaseTables(); // create global paths-object //Paths = new ProgramPaths(); // prepare settings Settings = new Settings(); Settings.BaseData = Data.BaseData; // prepare commanders log CommandersLog = new CommandersLog(); CommandersLog.BaseData = Data.BaseData; // prepare price analysis PriceAnalysis = new PriceAnalysis(new DBConnector(DBCon.ConfigData, true)); PriceAnalysis.BaseData = Data.BaseData; // starting the external data interface ExternalData = new ExternalDataInterface(); // initializing the object for the actual condition actualCondition = new Condition(); // initializing the LogfileScanner LogfileScanner = new EDLogfileScanner(); // forwards a potentially new system or station information to database Program.LogfileScanner.LocationInfo += LogfileScanner_LocationInfo; Program.ExternalData.LocationInfo += ExternalData_LocationInfo; // register the LogfileScanner in the CommandersLog for the ExternalDataEvent-event CommandersLog.registerLogFileScanner(LogfileScanner); CommandersLog.registerExternalTool(ExternalData); PriceAnalysis.registerLogFileScanner(LogfileScanner); PriceAnalysis.registerExternalTool(ExternalData); Program.SplashScreen.InfoAppendLast("<OK>"); m_initDone = true; } } catch (Exception ex) { cErr.processError(ex, "Error while initializing the program object", true); } }
private void cmdChangeSQLPort_Click(object sender, EventArgs e) { try { UInt16 newPort; UInt16 oldPort; if (UInt16.TryParse(txtSQLConnectionPort.Text, out newPort)) { Boolean isOccupied = DBProcess.IsListenerOnPort(newPort) || DBProcess.IsConnectionOnPort(newPort); if (!isOccupied) { oldPort = Program.IniFile.GetValue<UInt16>("DB_Server", "Port", "3306"); if(MessageBox.Show(this, "Change db-port from " + oldPort + " to " + newPort + " ?", "Aborted", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK) { // switch off the general log for the database STA.Settings.INIFile dbIniFile; if(Debugger.IsAttached) dbIniFile = new STA.Settings.INIFile(Path.Combine(Program.IniFile.GetValue("DB_Server", "WorkingDirectory", @"..\..\..\RNDatabase\Database"), "Elite.ini"), false, true, true); else dbIniFile = new STA.Settings.INIFile(Program.GetDataPath(@"Database\Elite.ini"), false, true, true); Program.IniFile.SetValue("DB_Server", "Port", newPort.ToString()); dbIniFile.SetValue("mysqld", "port", newPort.ToString()); MessageBox.Show(this, "Port changed, restart required.", "Changed configuration", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { txtSQLConnectionPort.Text = Program.IniFile.GetValue<UInt16>("DB_Server", "Port", "3306").ToString(); } } else { MessageBox.Show(this, "Selected port is already occupied", "Aborted", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtSQLConnectionPort.Text = Program.IniFile.GetValue<UInt16>("DB_Server", "Port", "3306").ToString(); } } else { MessageBox.Show(this, "Couldn't parse value as <UInt16>", "Aborted", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtSQLConnectionPort.Text = Program.IniFile.GetValue<UInt16>("DB_Server", "Port", "3306").ToString(); } } catch (Exception ex) { CErr.processError(ex, "Error while changing the tcp-port of the sql-server"); } }
/// <summary> /// starts the initialization of the global objects /// </summary> public static void Init() { try { if(!m_initDone) { Program.SplashScreen = new SplashScreenForm(); Program.SplashScreen.Show(); Program.SplashScreen.Logger = MainLog; Program.SplashScreen.InfoAdd("initializing logger..."); Program.MainLog.Log("Initialising...\n"); Program.SplashScreen.InfoAppendLast("<OK>"); Program.SplashScreen.InfoAdd("starting sql server..."); // load settings from file IniFile = new STA.Settings.INIFile(GetDataPath("ED-IBE.ini"), false, true); // prepare architecture-dependend files PrepareDepFiles(); // start database process (if not running) DBProcess.DBProcessParams newProcessParams = new DBProcess.DBProcessParams() { }; newProcessParams.Commandline = IniFile.GetValue("DB_Server", "Commandline", @"bin\mysqld.exe"); newProcessParams.Commandargs = IniFile.GetValue("DB_Server", "CommandArgs", @"--defaults-file=Elite.ini --console"); newProcessParams.Workingdirectory = IniFile.GetValue("DB_Server", "WorkingDirectory", @"..\..\..\RNDatabase\Database"); newProcessParams.Port = IniFile.GetValue<UInt16>("DB_Server", "Port", "3306"); newProcessParams.DBStartTimeout = IniFile.GetValue<Int16>("DB_Server", "DBStartTimeout", "60"); Program.SplashScreen.InfoAppendLast("on port " + newProcessParams.Port + "..."); EliteDBProcess = new DBProcess(newProcessParams); if (EliteDBProcess.WasRunning) Program.SplashScreen.InfoAppendLast("already running...<OK>"); else Program.SplashScreen.InfoAppendLast("<OK>"); // connecT to the database Program.SplashScreen.InfoAdd("connect to sql server..."); DBConnector.ConnectionParams newConnectionParams = new DBConnector.ConnectionParams() { }; newConnectionParams.Name = IniFile.GetValue("DB_Connection", "Name", "master"); newConnectionParams.Server = IniFile.GetValue("DB_Connection", "Server", "localhost"); newConnectionParams.Port = IniFile.GetValue<UInt16>("DB_Server", "Port", "3306"); newConnectionParams.Database = IniFile.GetValue("DB_Connection", "Database", "Elite_DB"); newConnectionParams.User = IniFile.GetValue("DB_Connection", "User", "RN_User"); newConnectionParams.Pass = IniFile.GetValue("DB_Connection", "Pass", "Elite"); newConnectionParams.ConnectTimeout = IniFile.GetValue<Int16>("DB_Connection", "ConnectTimeout", "60"); newConnectionParams.StayAlive = IniFile.GetValue<Boolean>("DB_Connection", "StayAlive", "false"); newConnectionParams.TimeOut = IniFile.GetValue<Int16>("DB_Connection", "TimeOut", "10000"); DBCon = new DBConnector(newConnectionParams); DBCon.Connect(); Program.SplashScreen.InfoAppendLast("<OK>"); /* **************** database is running ********************** */ /* perform updates */ Updater.DBUpdate(); Program.SplashScreen.InfoAdd("preparing global objects..."); // prepare colors-object Colors = new GUIColors(); // preprare main data object Data = new IBE.SQL.EliteDBIO(); Data.PrepareBaseTables(); // create global paths-object //Paths = new ProgramPaths(); // prepare settings // Settings = new Settings(); // Settings.BaseData = Data.BaseData; // prepare commanders log CommandersLog = new CommandersLog(); CommandersLog.BaseData = Data.BaseData; // prepare price analysis PriceAnalysis = new PriceAnalysis(new DBConnector(DBCon.ConfigData, true)); PriceAnalysis.BaseData = Data.BaseData; //// starting the external data interface //ExternalData = new ExternalDataInterface(); // Companion IO CompanionIO = new IBECompanion.CompanionData(Program.GetDataPath()); if(CompanionIO.ConditionalLogIn()) CompanionIO.GetProfileDataAsync(); // initializing the object for the actual condition actualCondition = new Condition(); // initializing the LogfileScanner //LogfileScanner = new EDLogfileScanner(); JournalScanner = new EDJournalScanner(); // EDDN Interface EDDNComm = new IBE.EDDN.EDDNCommunicator(); // EDSMComm Interface EDSMComm = new IBE.EDSM.EDStarmapInterface(Program.DBCon); CommandersLog.registerJournalScanner(JournalScanner); CommandersLog.registerExternalTool(CompanionIO); CompanionIO.registerJournalScanner(JournalScanner); PriceAnalysis.registerJournalScanner(JournalScanner); PriceAnalysis.registerExternalTool(CompanionIO); EDSMComm.registerJournalScanner(JournalScanner); actualCondition.RegisterJournalScanner(JournalScanner); EDDNComm.RegisterJournalScanner(JournalScanner); // Plausibility-Checker PlausibiltyCheck = new PlausibiltyChecker(); /// early variant of DoSpecial(); Updater.DoSpecial_Early(); Program.SplashScreen.InfoAppendLast("<OK>"); m_initDone = true; } } catch (Exception ex) { CErr.processError(ex, "Error while initializing the program object"); } }