public async Task <WeatherInfo> GetWeatherInfo(string lat, string lon) { var weatherResponse = await _weatherService.GetByLatLon(lat, lon, AppSetting.WeatherKey); var weatherInfo = new WeatherInfo(); if (weatherResponse.IsSuccessStatusCode) { var json = await weatherResponse.Content.ReadAsStringAsync(); var weather = JsonConvert.DeserializeObject <WeatherResponse>(json); weatherInfo.Location = weather.Name; weatherInfo.Date = Helper.UnixTimeStampToDateTime(weather.Dt); weatherInfo.FeelsLike = weather.Main.FeelsLike; weatherInfo.Humidity = weather.Main.Humidity; weatherInfo.Temp = weather.Main.Temp; weatherInfo.SkyStatus = weather.Weather[0]?.Main; weatherInfo.WindInfo = new WeatherInfo.Wind { Speed = weather.Wind.Speed, Degree = weather.Wind.Deg, }; Barrel.Current.Add(LastWeatherReportKey, weather, TimeSpan.FromDays(1)); } else { var cached = Barrel.Current.Get <WeatherResponse>(LastWeatherReportKey); if (cached != null) { weatherInfo.Location = cached.Name; weatherInfo.Date = Helper.UnixTimeStampToDateTime(cached.Dt); weatherInfo.FeelsLike = cached.Main.FeelsLike; weatherInfo.Humidity = cached.Main.Humidity; weatherInfo.Temp = cached.Main.Temp; weatherInfo.SkyStatus = cached.Weather[0]?.Main; weatherInfo.WindInfo = new WeatherInfo.Wind { Speed = cached.Wind.Speed, Degree = cached.Wind.Deg, }; } } return(weatherInfo); }
public async Task <HttpResponseMessage> GetByLatLon(string lat, string lon, string appid) { var request = Api.GetByLatLon(lat, lon, appid); return(await ExecRequest(request)); }