private async Task <Weather> getWeatherDataFromApiAsync(WeatherLookup lookup, CancellationToken ct) { logger.Info($"Weather data not cached for sensor {lookup.SensorId}."); var result = await this.m_client.GetCurrentWeatherAsync(new QueryParameters { Key = this.m_config.OpenWeatherMapApiKey, UnitSystem = "metric", Latitude = lookup.Latitude, Longitude = lookup.Longitude }, ct).ConfigureAwait(false); if (result == null) { logger.Error("Weather lookup failed!"); return(null); } logger.Info($"Got response from OpenWeatherMap API with ID {result.Id}."); if (result.Id != 0) { this.m_cache[lookup.SensorId] = result.Data; } return(result); }
private async Task lookupWeather(SensorMapping mapping, IDictionary <DateTime, DataPoint> resultSet, Location location, CancellationToken ct) { var lookup = new WeatherLookup { Longitude = location.Longitude, Latitude = location.Latitude, SensorId = mapping.Id }; var result = await this.m_openWeather.LookupAsync(lookup, ct).ConfigureAwait(false); decimal?oat = null; if (result != null) { oat = Convert.ToDecimal(result.Temperature); } foreach (var keyValuePair in resultSet) { keyValuePair.Value.OutsideAirTemperature = oat; } }
public async Task <WeatherData> LookupAsync(WeatherLookup lookup, CancellationToken ct) { var cachedValue = this.m_cache[lookup.SensorId]; if (cachedValue == null) { var result = await this.getWeatherDataFromApiAsync(lookup, ct).ConfigureAwait(false); if (result == null) { return(null); } cachedValue = result.Data; } else { logger.Info($"Using cached weather data for {lookup.SensorId}."); } return(cachedValue); }