public void RetrieveWeather(GPSPoint location) { if (ApplicationState.Current.IsOffline || !ApplicationState.Current.IsPremium) {//weather conditions are retrieved only for premium or instructor accounts. also skip weather retrieving in offline mode return; } bool hasWeather = Entry.Weather != null && Entry.Weather.Temperature != null; if (weatherRetrievingStarted || hasWeather) {//run retrieving weather only once return; } weatherRetrievingStarted = true; //retrieve weather for user current location weatherService = new WorldWeatherOnline(); weatherService.WeatherLoaded += weatherService_WeatherLoaded; weatherService.BeginLoadWeather(location); }
public void RetrieveWeather() { WeatherRetrieving = true; WeatherStatus = GPSStrings.GPSTrackerViewModel_RetrievingCurrentWeather; try { var weatherService = new WorldWeatherOnline(); entry.Weather = weatherService.LoadWeather(); WeatherStatus = ""; NotifyOfPropertyChange(() => HasWeatherInfo); NotifyOfPropertyChange(() => WeatherImage); NotifyOfPropertyChange(() => CurrentTemperature); } catch (Exception) { WeatherStatus = GPSStrings.GPSTrackerViewModel_ErrRetrieveWeather; } finally { WeatherRetrieving = false; } }
void weatherService_WeatherLoaded(object sender, WeatherRetrievedEventArgs e) { weatherService.WeatherLoaded -= weatherService_WeatherLoaded; weatherService = null; Entry.Weather = e.Weather; }