} // end of method pnlWidget_MouseDown #endregion #region PictureBox Controls private void picRefresh_Click(object sender, EventArgs e) { long updatePeriod = UtilityMethod.SubtractTime(new DateTime(), UtilityMethod.lastUpdated); if (updatePeriod < 10) { }// end of if block else { btnLocation.Text = "Refreshing..."; ws = new WidgetUpdateService(false, this); ws.Run(); } // end of else block } // end of method picRefresh_Click
}// end of default constructor public void Run() { try { // keep track of Internet connectivity if (UtilityMethod.TimeForConnectivityCheck()) { WeatherLionMain.connectedToInternet = UtilityMethod.HasInternetConnection(); }// end of if block // If the program is not connected to the Internet, wait for a connection if (WeatherLionMain.connectedToInternet) { // if there was no previous Internet connection, check for a return in connectivity // and refresh the widget if (currentWidget.usingPreviousData && UtilityMethod.UpdateRequired()) { // run the weather service WidgetUpdateService ws = new WidgetUpdateService(false, currentWidget); ws.Run(); } // end of if block } // end of if block if (WeatherLionMain.connectedToInternet) { currentWidget.picOffline.Visible = false; }// end of if block else { currentWidget.picOffline.Visible = true; }// end of else block currentWidget.CheckAstronomy(); }// end of try block catch (Exception e) { UtilityMethod.LogMessage(UtilityMethod.LogLevel.SEVERE, e.Message, $"{TAG}::Run"); } // end of catch block } // end of method Run
} // end of method tmrPreferenceUpdate_Tick /// <summary> /// Update the widget at the time interval specified by the user /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tmrUpdate_Tick(object sender, EventArgs e) { ws = new WidgetUpdateService(false, this); ws.Run(); }// end of method tmrUpdate_Tick
}// end of method tmrIconUpdater_Tick private void tmrPreferenceUpdate_Tick(object sender, EventArgs e) { if (applyPreferenceUpdates) { if (preferenceUpdated.Count > 0) { foreach (string preference in preferenceUpdated.Keys) { switch (preference) { case WeatherLionMain.CURRENT_LOCATION_PREFERENCE: // update the local preference file Preference.SaveProgramConfiguration("prefs", preference, preferenceUpdated[preference]); // update running data WeatherLionMain.storedPreferences.StoredPreferences.Location = preferenceUpdated[preference]; // reset the re-attempted flag before running the service reAttempted = false; // run the weather service ws = new WidgetUpdateService(false, this); ws.Run(); break; case WeatherLionMain.WEATHER_SOURCE_PREFERENCE: // update the local preference file Preference.SaveProgramConfiguration("prefs", preference, preferenceUpdated[preference]); // update running data WeatherLionMain.storedPreferences.StoredPreferences.Provider = preferenceUpdated[preference]; // reset the re-attempted flag before running the service reAttempted = false; // run the weather service ws = new WidgetUpdateService(false, this); ws.Run(); break; case WeatherLionMain.UPDATE_INTERVAL: // update the local preference file Preference.SaveProgramConfiguration("prefs", preference, preferenceUpdated[preference]); // update running data WeatherLionMain.storedPreferences.StoredPreferences.Interval = int.Parse(preferenceUpdated[preference]); break; case WeatherLionMain.USE_SYSTEM_LOCATION_PREFERENCE: // update the local preference file Preference.SaveProgramConfiguration("prefs", preference, preferenceUpdated[preference].ToLower()); // update running data WeatherLionMain.storedPreferences.StoredPreferences.UseSystemLocation = bool.Parse(preferenceUpdated[preference].ToLower()); // reset the re-attempted flag before running the service reAttempted = false; // run the weather service ws = new WidgetUpdateService(false, this); ws.Run(); break; case WeatherLionMain.USE_METRIC_PREFERENCE: // update the local preference file Preference.SaveProgramConfiguration("prefs", preference, preferenceUpdated[preference].ToLower()); // update running data WeatherLionMain.storedPreferences.StoredPreferences.UseMetric = bool.Parse(preferenceUpdated[preference].ToLower()); // update the units displayed on the widget ws = new WidgetUpdateService(true, this); ws.Run(); break; case WeatherLionMain.ICON_SET_PREFERENCE: // update the local preference file Preference.SaveProgramConfiguration("prefs", preference, preferenceUpdated[preference]); // update running data WeatherLionMain.storedPreferences.StoredPreferences.IconSet = preferenceUpdated[preference]; WeatherLionMain.iconSet = WeatherLionMain.storedPreferences.StoredPreferences.IconSet; UpdateIconSet(); break; case WeatherLionMain.WIDGET_BACKGROUND_PREFERENCE: // update the local preference file Preference.SaveProgramConfiguration("prefs", preference, preferenceUpdated[preference]); // update running data WeatherLionMain.storedPreferences.StoredPreferences.WidgetBackground = preferenceUpdated[preference]; switch (WeatherLionMain.storedPreferences.StoredPreferences.WidgetBackground) { case "default": default: BlendedBackground = (Bitmap)Image.FromFile(WeatherLionMain.DEFAULT_BACKGROUND_IMAGE); Refresh(); break; case "android": BlendedBackground = (Bitmap)Image.FromFile(WeatherLionMain.ANDROID_BACKGROUND_IMAGE); Refresh(); break; case "rabalac": BlendedBackground = (Bitmap)Image.FromFile(WeatherLionMain.RABALAC_BACKGROUND_IMAGE); Refresh(); break; } // end of switch block BackgroundUpdate(); break; default: break; } // end of switch block } // end of for each loop // remove all items from the object preferenceUpdated.Clear(); // refresh the UI immediately Refresh(); // reset flag to perfom changes applyPreferenceUpdates = false; } // end of if block } // end of if block } // end of method tmrPreferenceUpdate_Tick
}// end of method frmWidget_FormClosing private void frmWidget_Load(object sender, EventArgs e) { bool exists = File.Exists(Preference.CONFIG_FILE); // load the appropriate background Image bgImage = Image.FromFile( $@"{IMAGE_PATH}\backgrounds\{WeatherLionMain.storedPreferences.StoredPreferences.WidgetBackground}_bg.png"); BlendedBackground = (Bitmap)bgImage; // update the form's blended background image BackgroundUpdate(); UpdateLayeredBackground(); if (exists) { if (WeatherLionMain.storedPreferences.ConfigData.StartPosition.X != 0 || WeatherLionMain.storedPreferences.ConfigData.StartPosition.Y != 0) { Location = WeatherLionMain.storedPreferences.ConfigData.StartPosition; }// end of if block else { StartPosition = FormStartPosition.CenterScreen; } // end of else block } // end of if block // check the update interval stored in the user preferences if (WeatherLionMain.storedPreferences.StoredPreferences.Interval != 0) { tmrUpdate.Interval = WeatherLionMain.storedPreferences.StoredPreferences.Interval; }// end of if block else { tmrUpdate.Interval = WeatherLionMain.DEFAULT_WIDGET_UPDATE_INTERVAL; }// end of else block // setup the refresh timer WidgetUpdateService.currentRefreshInterval = tmrUpdate.Interval; ws = new WidgetUpdateService(false, this); string wxDataFile = $"{WeatherLionMain.DATA_DIRECTORY_PATH}{WeatherLionMain.WEATHER_DATA_XML}"; if (File.Exists(wxDataFile)) { // Load old data into the widget first before contacting the provider ws.LoadPreviousWeatherData(); }// end of if block // start the weather 'service' ws.Run(); // start the weather refresh timer tmrUpdate.Start(); // update the widget clock tmrCurrentTime.Start(); // start the time that monitors user preference changes tmrPreferenceUpdate.Start(); // position form on screen Left = Location.X; Top = Location.Y; }// end of method frmWidget_Load