private void ButtonRefreshData_Click(object sender, RoutedEventArgs e) { LocalWeather w = weatherStation.PullWeather(); if (w == null) { return; } Update(w); }
private async void UpdateWeatherStation(object sender, EventArgs e) { LocalWeather w = await GetWeather(); if (w == null) { return; } weather = w; NotifySubscribers(); }
private async Task <LocalWeather> GetWeather() { LocalWeather weather = null; HttpResponseMessage res = await client.GetAsync($"?q={this.City}&units=metric&APPID={apiKey}"); if (res.IsSuccessStatusCode) { weather = await res.Content.ReadAsAsync <LocalWeather>(); } return(weather); }
public async void NotifySubscribers() { LocalWeather weather = await GetWeather(); if (weather == null) { Console.WriteLine("Failed to get weather data."); return; } foreach (IObserver observer in observers) { observer.Update(weather); } }
public void Update(LocalWeather weather) { if (weather == null) { return; } labelLastUpdate.Content = $"Last updated: {DateTime.Now.ToString()}"; labelCity.Content = $"city: {weather.Name}"; labelTemperature.Content = $"Tempature: {weather.Main.Temp}"; labelVisibility.Content = $"visibility: {weather.Visibility}"; labelWind.Content = $"Wind speed: {weather.Wind.Speed}"; string weatherDescription = "Weather: "; foreach (Weather w in weather.Weather) { weatherDescription += $" {w.Description}"; } labelDescription.Content = weatherDescription; }