/// <summary> /// Closes the Conflib class instance. /// </summary> public static void Close() { if (Conflib != null) // on if initialized.. { // this disposes of the underlying SQlite database connection.. Conflib.Close(); Conflib = null; // set to null.. } }
/// <summary> /// Initializes the Conflib class instance. /// </summary> private static void Init() { if (Conflib == null) // don't initialize if already initialized.. { Conflib = new Conflib { AutoCreateSettings = true // set it to auto-create SQLite database tables.. }; // create a new instance of the Conflib class.. } }
/// <summary> /// Initializes a new instance of the <see cref="Settings"/> class. /// </summary> public Settings() { if (conflib == null) // don't initialize if already initialized.. { conflib = new Conflib { AutoCreateSettings = true // set it to auto-create SQLite database tables.. }; // create a new instance of the Conflib class.. } // get all public instance properties of this class.. PropertyInfo[] propertyInfos = GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); // loop through the properties.. for (int i = 0; i < propertyInfos.Length; i++) { try // avoid crashes.. { // get the SettingAttribute class instance of the property.. SettingAttribute settingAttribute = (SettingAttribute)propertyInfos[i].GetCustomAttribute(typeof(SettingAttribute)); // get the default value for the property.. object currentValue = propertyInfos[i].GetValue(this); // set the value for the property using the default value as a // fall-back value.. if (currentValue == null) { continue; } propertyInfos[i].SetValue(this, Convert.ChangeType(conflib[settingAttribute.SettingName, currentValue.ToString()], settingAttribute.SettingType)); } catch { // ignored.. } } // subscribe the event handler.. PropertyChanged += Settings_PropertyChanged; }
private void btOK_Click(object sender, EventArgs e) { Conflib cl = new Conflib(); cl.AutoCreateSettings = true; cl.DataDir = Path.GetDirectoryName(tbSaveConfigTo.Text); cl.DBName = Path.GetFileName(tbSaveConfigTo.Text); KeyValuePair <DBLangEngine.DatabaseType, string> v = (KeyValuePair <DBLangEngine.DatabaseType, string>)cmbDatabaseType.SelectedItem; cl["dbType"] = v.Key.ToString(); cl["dbServer"] = tbServer.Text; cl["dbDatabase"] = tbDatabase.Text; cl["dbUser"] = "******" + tbUser.Text; cl["dbPassword"] = "******" + tbPassword.Text; cl["dbSchema"] = tbSchema.Text; cl["dbPort"] = nudPort.Value.ToString(); cl["dbConnStr"] = "SECURE:" + ReplacePasswordToReal(); cl["dbConnStrOverride"] = cbOverrideConnectionString.Checked.ToString(); cl["dbNoTables"] = cbNoTables.Checked.ToString(); closedAccepted = true; Close(); }
/// <summary> /// Loads database settings from a SQLite database called dbconfig.sqlite. /// </summary> private static void LoadSettings() { Conflib cl = new Conflib(); cl.DataDir = dataDir; cl.DBName = "dbconfig.sqlite"; cl.AutoCreateSettings = true; try { KeyValuePair <DBLangEngine.DatabaseType, string> v = new KeyValuePair <DBLangEngine.DatabaseType, string>((DBLangEngine.DatabaseType)Enum.Parse(typeof(DBLangEngine.DatabaseType), cl["dbType"]), cl["dbType"]); dbType = v.Key; } catch { dbType = DatabaseType.dtSQLite; return; } dbHost = cl["dbServer"]; dbName = cl["dbDatabase"]; dbUser = cl["dbUser"]; dbPassword = cl["dbPassword"]; dbSchema = cl["dbSchema"]; dbPort = (UInt16)decimal.Parse(cl["dbPort"]); dbPassword = cl["dbPassword"]; dbConnectionStr = bool.Parse(cl["dbConnStrOverride"]) ? cl["dbConnStr"] : string.Empty; try { dbNoTables = bool.Parse(cl["dbNoTables"]); } catch { dbNoTables = false; } }
private void LoadSettings() { Conflib cl = new Conflib(); cl.AutoCreateSettings = true; cl.DataDir = Path.GetDirectoryName(tbSaveConfigTo.Text); cl.DBName = Path.GetFileName(tbSaveConfigTo.Text); DBLangEngine.DatabaseType dbType = DBLangEngine.DatabaseType.dtSQLite; try { KeyValuePair <DBLangEngine.DatabaseType, string> v = new KeyValuePair <DBLangEngine.DatabaseType, string>((DBLangEngine.DatabaseType)Enum.Parse(typeof(DBLangEngine.DatabaseType), cl["dbType"]), GetEnumDescription((DBLangEngine.DatabaseType)Enum.Parse(typeof(DBLangEngine.DatabaseType), cl["dbType"]))); for (int i = 0; i < cmbDatabaseType.Items.Count; i++) { KeyValuePair <DBLangEngine.DatabaseType, string> item = (KeyValuePair <DBLangEngine.DatabaseType, string>)cmbDatabaseType.Items[i]; if (item.Equals(v)) { dbType = v.Key; cmbDatabaseType.SelectedIndex = i; break; } } } catch { cmbDatabaseType.SelectedIndex = 0; cmbDatabaseType_SelectedIndexChanged(null, null); } string dbServer = cl["dbServer", dbType == DBLangEngine.DatabaseType.dtSQLite ? GetDefaultFileLang() : "localhost"]; dbServer = dbServer == null ? dbType == DBLangEngine.DatabaseType.dtSQLite ? GetDefaultFileLang() : "localhost" : dbServer; // down we just like this ? format tbServer.Text = dbServer; tbDatabase.Text = cl["dbDatabase"]; tbUser.Text = cl["dbUser"]; tbPassword.Text = cl["dbPassword"]; tbSchema.Text = cl["dbSchema"]; try { cbNoTables.Checked = bool.Parse(cl["dbNoTables"]); } catch { cbNoTables.Checked = false; } try { nudPort.Value = decimal.Parse(cl["dbPort"]); } catch { nudPort.Value = 0; } string pwText = new string('•', tbPassword.Text.Length); try { tbConnectionString.Text = cl["dbConnStr"].Replace(cl["dbPassword"], pwText); } catch { // Do nothing } ReplacePasswordToReal(); try { cbOverrideConnectionString.Checked = bool.Parse(cl["dbConnStrOverride"]); } catch { cbOverrideConnectionString.Checked = false; } }
/// <summary> /// Initializes a new instance of the <see cref="Settings"/> class. /// </summary> /// <param name="confLib">An instance to a ConfLib class.</param> public Settings(Conflib confLib) : base(confLib) { }