public WeatherForecast(OWMForeCast owm) { if (owm.List == null) { throw new ArgumentException(owm.ToString()); } this.CityName = owm.City?.Name; this.Days = owm.List .GroupBy(DateSelector) .Select(grp => new WeatherForecastDay(grp.Key, grp.ToArray())) .ToArray(); }
public async Task <WeatherForecast> GetForecastAsync() { try { OWMForeCast fc = await this.GetOpenWeatherMapForecastAsync(); var result = new WeatherForecast(fc); this._cachedResult = result; return(result); } catch (Exception e) { this._logger.LogError(e, "Failed to query OpenWeatherMap forecast"); return(this._cachedResult); // might be null or outdated but our best guess. } }