private async Task LoadData() { if (_requiredListOfCities != null) { return; } _requiredListOfCities = _cityService.AvilableCities; try { //could be split to different chunks as well like 2 each or sg. foreach (City city in _requiredListOfCities) { WeatherDataRoot weatherInfo = await _darkSkyService.GetWeatherDataForCity(city); AvailableWeatherInfo.Add(weatherInfo); } //testing what is quicker in terms of loading data -> one by one is fine. //IEnumerable<WeatherDataRoot> availableWeatherInfo = await _darkSkyService.GetWeatherDataForMultipleCities(_requiredListOfCities); //AvailableWeatherInfo = new ObservableCollection<WeatherDataRoot>(availableWeatherInfo); } catch (Exception ex) { IsThereAConnectionError = true; Logger.Error("An error occured while getting data from the Dark Sky Service. Please check details in the log.", ex); } }
public async Task GetWeatherDataForCity_SuccessfullyParses_NormalJSONString() { _darkSkyService = new DarkSkyService(_weatherDataRetriever, _darkSkyConfigurationManager); WeatherDataRoot weatherData = await _darkSkyService.GetWeatherDataForCity(city); Assert.IsNotNull(weatherData); Assert.IsNotNull(weatherData.CurrentWeather); Assert.AreEqual(weatherData.CurrentWeather.Temperature, -1.73); Assert.AreEqual(weatherData.CurrentWeather.Icon, IconValue.CLOUDY); Assert.AreEqual(weatherData.CurrentWeather.Humidity, 0.96); }
public async Task <IEnumerable <WeatherDataRoot> > GetWeatherDataForMultipleCities(IEnumerable <City> cities, ExcludeParameter excludeParameter = ExcludeParameter.AllExceptDailyAndCurrently, MetricSystem metricSystem = MetricSystem.AUTO) { IList <WeatherDataRoot> weatherDataList = new List <WeatherDataRoot>(); foreach (City city in cities) { WeatherDataRoot weatherDataForCity = await ProcessCityWeatherDataQuery(city, excludeParameter, metricSystem); weatherDataList.Add(weatherDataForCity); } return(weatherDataList.ToArray()); }