/// <summary> /// Load a required assets and prepare for program execution /// </summary> public static void Launch() { #region WeatherLion launch sequence UtilityMethod.LogMessage(UtilityMethod.LogLevel.INFO, "Initiating startup...", "WeatherLionMain::Launch"); // build the required storage files if (BuildRequiredDatabases() == 1) { UtilityMethod.LogMessage(UtilityMethod.LogLevel.INFO, "All required databases constructed successfully.", "WeatherLionMain::Launch"); }// end of if block else { UtilityMethod.LogMessage(UtilityMethod.LogLevel.SEVERE, "All required databases were not constructed successfully.", "WeatherLionMain::Launch"); }// end of else block // check that the required access keys are available LionSecurityManager.Init(); // Load only the providers who have access keys assigned to them List <string> wxOnly = LionSecurityManager.webAccessGranted; wxOnly.Sort(); // sort the list // GeoNames is not a weather provider so it cannot be select here wxOnly.Remove("GeoNames"); authorizedProviders = wxOnly.ToArray(); // ensure that program has all the default assets needed for functioning properly HealthCheck(); // load user preferences storedPreferences = Preference.GetSavedPreferences(); string previousWeatherData = $"{DATA_DIRECTORY_PATH}{WEATHER_DATA_XML}"; connectedToInternet = UtilityMethod.HasInternetConnection(); // check for an Internet connection or previous weather data stored local if (!connectedToInternet && !File.Exists(previousWeatherData)) { UtilityMethod.ShowMessage("The program will not run without a working internet connection or " + "data that was previously stored locally" + "\nResolve your Internet connection and relaunch the program.", null); Application.Exit(); // terminate the program }// end of if block else if (connectedToInternet) { // obtain the current city of the connected Internet service currentCity = UtilityMethod.GetSystemLocation(); if (currentCity != null) { if (currentCity.regionCode != null) { systemLocation = $"{currentCity.cityName}, {currentCity.regionCode}"; }// end of if block else { systemLocation = $"{currentCity.cityName}, {currentCity.countryName}"; } // end of else block } // end of if block // if the user requires the current detected city location to be used as default if (storedPreferences.StoredPreferences.UseSystemLocation) { if (systemLocation != null) { // use the detected city location as the default storedPreferences.StoredPreferences.Location = systemLocation; if (!storedPreferences.StoredPreferences.Location.Equals(systemLocation)) { // update the preferences file Preference.SaveProgramConfiguration("prefs", "Location", systemLocation); // save the city to the local WorldCites database UtilityMethod.AddCityToDatabase( currentCity.cityName, currentCity.countryName, currentCity.countryCode, currentCity.regionName, currentCity.regionCode, currentCity.latitude, currentCity.longitude); JSONHelper.ExportToJSON(currentCity); XMLHelper.ExportToXML(currentCity); } // end of if block } // end of if block else { UtilityMethod.ShowMessage("The program was unable to obtain your system's location." + "\nYour location will have to be set manually using the preferences dialog.", null); PreferencesForm pf = new PreferencesForm(); pf.Show(); } // end of else block } // end of if block } // end of else if block Init(); #endregion }// end of method Launch