private void RefreshWeatherHistoryButton_Click(object sender, RoutedEventArgs e) { try { //create table StringTable table = new StringTable(); table.ColumnNames.Add("Observed On"); table.ColumnNames.Add("Location"); table.ColumnNames.Add("Temperature"); table.ColumnNames.Add("Forecast"); //add rows var history = WeatherHistoryDAC.FetchAll(); foreach (var entry in history) { table.Add(table.Count, new StringRow() { { "Observed On", entry.FetchedOn.ToString() }, { "Location", entry.Latitude + ", " + entry.Longitude }, { "Temperature", entry.Temperature == double.MaxValue ? string.Empty : entry.Temperature.ToString() }, { "Forecast", entry.Forecast.ToString() } }); } DataGridHelper.Bind(ref WeatherHistoryGrid, table); //show summary WeatherSummaryTextBox.Text = string.Format("{0} Records", history.Count); } catch (Exception exception) { WeatherSummaryTextBox.Text = "Unable to Load Weather-History: " + exception.Message; } }
private void ClearWeatherHistoryButton_Click(object sender, RoutedEventArgs e) { var result = MessageBox.Show("Clear Weather History?", Constants.APP_ID, MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { WeatherHistoryDAC.Clear(); RefreshWeatherHistoryButton_Click(null, null); } }
public async static Task ReadWeather() { WeatherRead = false; //ignore if weather is read very recently if (CurrentWeather != null && DateTime.Now.Subtract(CurrentWeather.FetchedOn).TotalMinutes < Constants.WEATHER_READ_INTERVAL) { return; } try { if (LocationHelper.CurrentPosition == null) { await LocationHelper.ReadLocation(false); } if (LocationHelper.CurrentPosition != null) { WeatherEntry entry = new WeatherEntry(); entry.Latitude = LocationHelper.CurrentPosition.Coordinate.Latitude; entry.Longitude = LocationHelper.CurrentPosition.Coordinate.Longitude; WeatherDetails weatherDetails = Wunderground.GetWeather(entry.Latitude, entry.Longitude); if (weatherDetails != null) { entry.Temperature = Math.Round(weatherDetails.CurrentWeather.Temperature_C_Min, 2); } entry.Forecast = Wunderground.GetForecast(entry.Latitude, entry.Longitude); entry.FetchedOn = DateTime.Now; CurrentWeather = entry; WeatherHistoryDAC.Insert(CurrentWeather); WeatherRead = true; } } catch (Exception exception) { Log.Error(exception); } }