private void searchButton_Click(object sender, System.EventArgs e) { if (xHelper != null && xHelper.SendCommand("connectedToInternet") == "false") { Error("Unable to search for location - You are not connected to the Internet"); return; } if (searchText.Text == "") { MessageBox.Show("Enter a valid search string", "Weather Plugin", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { string text = searchButton.Text; searchButton.Text = "Searching..."; searchButton.Enabled = false; searchResults.DataSource = WeatherRegionForecast.SearchForLocations(searchText.Text); if (searchResults.Items.Count == 0) { MessageBox.Show("No locations were found for '" + searchText.Text + "'", "Weather Plugin", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { searchText.Text = ""; } searchButton.Enabled = true; searchButton.Text = text; } }
/// <summary> /// Updates the forecasts (implemented on a seperate thread). /// </summary> private void UpdateForecastsThread() { DateTime nextUpdate = DateTime.MaxValue; // This thread never dies while (true) { if (wxRegions == null || wxRegions.Length == 0) { Trace.WriteLine("Not updating weather - No weather locations defined", "wxupdate"); } else if (xHelper != null && xHelper.SendCommand("connectedToInternet") == "false") { Trace.WriteLine("Not updating weather - No internet connection available", "wxupdate"); } else { // Start weather data update Trace.WriteLine("Starting weather forecast data update", "wxupdate"); nextUpdate = DateTime.MaxValue; foreach (WeatherRegionForecast wxRegion in wxRegions) { try { Trace.WriteLine("Retrieving weather data for " + wxRegion.LocationId, "wxupdate"); DateTime regionUpdate = wxRegion.Refresh(); if (DateTime.Compare(regionUpdate, nextUpdate) < 0) { nextUpdate = regionUpdate; } } catch (ApplicationException ex) { Trace.WriteLine("Error: " + wxRegion.LocationId + ": " + ex.Message, "wxupdate"); } }