}// end of default constructor public static void Init() { // create all necessary files if they are not present if (!Directory.Exists(databasePath)) { try { Directory.CreateDirectory(databasePath); File.Create(databaseFile); }// end of try black catch (Exception e) { UtilityMethod.LogMessage(UtilityMethod.LogLevel.SEVERE, e.Message, $"{TAG}::init [line: {UtilityMethod.GetExceptionLineNumber(e)}]"); } // end of catch block } // end of if block if (!File.Exists(databaseFile)) { try { File.Create(databaseFile); UtilityMethod.CreateWSADatabase(); addKeys.Show(); }// end of try block catch (Exception e) { UtilityMethod.LogMessage(UtilityMethod.LogLevel.SEVERE, e.Message, $"{TAG}::init [line: {UtilityMethod.GetExceptionLineNumber(e)}]"); } // end of catch block } // end of if block else if (!UtilityMethod.CheckIfTableExists("wak", "access_keys")) { UtilityMethod.CreateWSADatabase(); UtilityMethod.ShowMessage(announcement, addKeys, WeatherLionMain.PROGRAM_NAME + " - IMPORTANT", MessageBoxButtons.OK, MessageBoxIcon.Information); }// end of else if block LoadAccessProviders(); }// end of method init
} // end of method AttachDatabase /// <summary> /// Build all required databases that the program will use. /// </summary> /// <returns></returns> public static int BuildRequiredDatabases() { string mainStorageFile = $"{MAIN_STORAGE_DIR}{MAIN_DATABASE_NAME}"; string cityStorageFile = $"{MAIN_STORAGE_DIR}{CITIES_DATABASE_NAME}"; string wakStorageFile = $"{MAIN_STORAGE_DIR}{WAK_DATABASE_NAME}"; StringBuilder keySuccess = new StringBuilder(); StringBuilder citySuccess = new StringBuilder(); int success = 0; // create all necessary files if they are not present if (!Directory.Exists(MAIN_STORAGE_DIR)) { Directory.CreateDirectory(MAIN_STORAGE_DIR); }// end of if block if (!File.Exists(mainStorageFile)) { try { SQLiteConnection.CreateFile(mainStorageFile); }// end of try black catch (IOException e) { UtilityMethod.LogMessage(UtilityMethod.LogLevel.SEVERE, e.Message, $"{TAG}::BuildRequiredDatabases [line: {UtilityMethod.GetExceptionLineNumber(e)}]"); } // end of catch block } // end of if block if (!File.Exists(cityStorageFile)) { try { SQLiteConnection.CreateFile(cityStorageFile); citySuccess.Append("World cities database successfully created"); }// end of try black catch (IOException e) { UtilityMethod.LogMessage(UtilityMethod.LogLevel.SEVERE, e.Message, $"WeatherLionMain::BuildRequiredDatabases [line: {UtilityMethod.GetExceptionLineNumber(e)}]"); } // end of catch block } // end of if block if (!File.Exists(wakStorageFile)) { try { SQLiteConnection.CreateFile(wakStorageFile); keySuccess.Append("Weather access database successfully created"); }// end of try black catch (IOException e) { UtilityMethod.LogMessage(UtilityMethod.LogLevel.SEVERE, e.Message, $"{TAG}::BuildRequiredDatabases [line: {UtilityMethod.GetExceptionLineNumber(e)}]"); } // end of catch block } // end of if block if (File.Exists(mainStorageFile) && File.Exists(cityStorageFile) && File.Exists(wakStorageFile)) { UtilityMethod.LogMessage(UtilityMethod.LogLevel.INFO, "The required storage files are present.", $"{TAG}::BuildRequiredDatabases"); // Establish connection with the databases and open it if (conn == null) { conn = ConnectionManager.GetInstance().GetConnection(); } try { conn.Open(); }// end of try block catch (Exception e) { UtilityMethod.LogMessage(UtilityMethod.LogLevel.SEVERE, e.Message, $"{TAG}::BuildRequiredDatabases [line: {UtilityMethod.GetExceptionLineNumber(e)}]"); } // end of catch block } // end of if block else { UtilityMethod.LogMessage(UtilityMethod.LogLevel.SEVERE, "All the required storage files are not present.", $"{TAG}::BuildRequiredDatabases"); return(0); }// end of else block // attach required databases to the main database file if (AttachDatabase(wakStorageFile, "wak") == 1) { if (!UtilityMethod.CheckIfTableExists("wak", "access_keys")) { UtilityMethod.CreateWSADatabase(); }// end of if block success = 1; if (keySuccess.Length > 0) { keySuccess.Append(" and attached to main connection"); }// end of if block else { keySuccess.Append("Weather access database attached to main connection"); } // end of else block } // end of if block else { success = 0; }// end of else block if (AttachDatabase(cityStorageFile, "WorldCities") == 1) { if (!UtilityMethod.CheckIfTableExists("WorldCities", "world_cities")) { UtilityMethod.CreateWorldCitiesDatabase(); }// end of if block success = 1; if (citySuccess.Length > 0) { citySuccess.Append(" and attached to main connection"); }// end of if block else { citySuccess.Append("WorldCities database attached to main connection"); } // end of else block } // end of if block else { success = 0; }// end of else block return(success); }// end of method BuildRequiredDatabases