} // end of method btnDeleteKey_Click private void btnFinish_Click(object sender, EventArgs e) { LionSecurityManager.LoadAccessProviders(); if (LionSecurityManager.keysMissing != null) { if (LionSecurityManager.keysMissing.Count > 0) { DialogResult answer = LionSecurityManager.CheckForMissingKeys(); LionSecurityManager.accessGranted = false; if (answer == DialogResult.Yes) { if (!Visible) { Visible = true; }// end of if block else { txtKeyName.Focus(); } // end of else block } // end of if block else { string wp = null; //string[] keys = null; if (LionSecurityManager.keysMissing.Count > 1) { List <string> missingHereKeys = new List <string>(); List <string> missingYahooKeys = new List <string>(); foreach (string keyName in LionSecurityManager.keysMissing) { if (LionSecurityManager.hereMapsRequiredKeys.Contains(keyName)) { missingHereKeys.Add(keyName); }// end of if block else if (LionSecurityManager.hereMapsRequiredKeys.Contains(keyName)) { missingYahooKeys.Add(keyName); } // end of else if block } // end of for each loop if (missingHereKeys.Count > 0) { string hKeys = string.Join(", ", missingHereKeys); string fs = null; if (UtilityMethod.NumberOfCharacterOccurences(',', hKeys) > 1) { fs = UtilityMethod.ReplaceLast(",", ", and", hKeys); }// end of if block else if (UtilityMethod.NumberOfCharacterOccurences(',', hKeys) == 1) { fs = hKeys.Replace(",", " and"); }// end of else block else { fs = hKeys; }// end of else block wp = WeatherLionMain.HERE_MAPS; string kc = missingHereKeys.Count > 1 ? "keys" : "key"; UtilityMethod.ShowMessage($"{wp} cannot be used as a weather source without\n" + $"first adding the missing {kc} {fs}.", this, $"{WeatherLionMain.PROGRAM_NAME} - Missing Key", MessageBoxButtons.OK, MessageBoxIcon.Error); }// end of if block if (missingYahooKeys.Count > 0) { string hKeys = string.Join(", ", missingHereKeys); string fs = null; if (UtilityMethod.NumberOfCharacterOccurences(',', hKeys) > 1) { fs = UtilityMethod.ReplaceLast(",", ", and", hKeys); }// end of if block else if (UtilityMethod.NumberOfCharacterOccurences(',', hKeys) == 1) { fs = hKeys.Replace(",", " and"); }// end of else block else { fs = hKeys; }// end of else block wp = WeatherLionMain.YAHOO_WEATHER; string kc = missingHereKeys.Count > 1 ? "keys" : "key"; UtilityMethod.ShowMessage($"{wp} cannot be used as a weather source without\n" + $"first adding the missing {kc} {fs}.", this, title: $"{WeatherLionMain.PROGRAM_NAME} - Missing Key", buttons: MessageBoxButtons.OK, mbIcon: MessageBoxIcon.Error); } // end of if block } // end of if block } // end of else block } // end of if block } // end of if block if (LionSecurityManager.webAccessGranted.Count >= 1 && !LionSecurityManager.webAccessGranted.Contains("GeoNames")) { UtilityMethod.ShowMessage("This program requires a geonames username" + " which was not stored in the database.\nIT IS FREE!", this, title: $"{WeatherLionMain.PROGRAM_NAME} - Missing Key", buttons: MessageBoxButtons.OK, mbIcon: MessageBoxIcon.Error); }// end of else if block else if (LionSecurityManager.webAccessGranted.Count == 2 && LionSecurityManager.webAccessGranted.Contains("GeoNames") && LionSecurityManager.webAccessGranted.Contains("Yr.no (Norwegian Metrological Institute)")) { UtilityMethod.ShowMessage("The program will only display weather data from" + " Yr.no (Norwegian Metrological Institute).\nObtain access keys for" + " the others if you wish to use them.", this, title: $"{WeatherLionMain.PROGRAM_NAME} - Single Weather Providery", buttons: MessageBoxButtons.OK, mbIcon: MessageBoxIcon.Information); LionSecurityManager.accessGranted = true; Close(); }// end of else if block else { LionSecurityManager.accessGranted = true; Close(); } // end of else block } // end of method btnFinish_Click
private void btnAdd_Click(object sender, EventArgs e) { if (txtKeyName == null || txtKeyName.Text.Length == 0 || txtKeyName.Text.Equals("")) { UtilityMethod.ShowMessage("Please enter a valid key name as given by the provider!", this, WeatherLionMain.PROGRAM_NAME + " - No Key Name", MessageBoxButtons.OK, MessageBoxIcon.Error); txtKeyName.Focus(); }// end of if block else if (pwdKeyValue == null || pwdKeyValue.Text.Length == 0 || pwdKeyValue.Text.Equals("")) { UtilityMethod.ShowMessage("Please enter a valid key value as given by the provider!", this, WeatherLionMain.PROGRAM_NAME + " - No Key Value", MessageBoxButtons.OK, MessageBoxIcon.Error); pwdKeyValue.Focus(); }// end of else if block else { string[] encryptedKey = LionSecurityManager.Encrypt(pwdKeyValue.Text, true).Split(':'); string selectedProvider = cboAccessProvider.SelectedItem.ToString(); switch (selectedProvider) { case "Here Maps Weather": if (!LionSecurityManager.hereMapsRequiredKeys.Contains(txtKeyName.Text.ToLower())) { UtilityMethod.ShowMessage($"The {selectedProvider} does not require a key \"{ txtKeyName.Text}\"!", this, $"{WeatherLionMain.PROGRAM_NAME} - Invalid Key Type", MessageBoxButtons.OK, MessageBoxIcon.Error); txtKeyName.Focus(); return; } // end of if block break; case "Yahoo! Weather": if (!LionSecurityManager.yahooRequiredKeys.Contains(txtKeyName.Text.ToLower())) { UtilityMethod.ShowMessage($"The {selectedProvider} does not require a key \"{ txtKeyName.Text}\"!", this, $"{WeatherLionMain.PROGRAM_NAME} - Invalid Key Type", MessageBoxButtons.OK, MessageBoxIcon.Error); txtKeyName.Focus(); return; } // end of if block break; default: break; }// end of switch block if (UtilityMethod.AddSiteKeyToDatabase(cboAccessProvider.SelectedItem.ToString(), txtKeyName.Text, encryptedKey[0], encryptedKey[1]) == 1) { if (txtKeyName.Enabled) { txtKeyName.Text = (""); } pwdKeyValue.Text = ""; UtilityMethod.ShowMessage("The key was successfully added to the database.", this, WeatherLionMain.PROGRAM_NAME + " - Success", MessageBoxButtons.OK, MessageBoxIcon.Information); txtKeyName.Focus(); }// end of if block else { UtilityMethod.ShowMessage("The key could not be added to the database!" + "\nPlease recheck the key and try again.", this, WeatherLionMain.PROGRAM_NAME + " - Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtKeyName.Focus(); } // end of else block } // end of else block } // end of method btnAdd_Click
/// <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