public async Task<WeatherDescription> GetWeatherAsync(GeoTagsEntry geoTags) {
var requestUri = string.Format(RequestWeatherUri, geoTags.LatitudeValue, geoTags.LongitudeValue, InternalUtils.GetOpenWeatherApiCode());
#if DEBUG
Logging.Write(requestUri);
#endif
using (var order = KillerOrder.Create(new WebClient(), 5000)) {
var data = await order.Victim.DownloadStringTaskAsync(requestUri);
XDocument doc;
try {
doc = XDocument.Parse(data);
} catch (XmlException) {
Logging.Warning("response: " + data);
throw;
}
var temperatureValue = doc.Descendants(@"temperature").FirstOrDefault()?.Attribute(@"value")?.Value;
var weatherNode = doc.Descendants(@"weather").FirstOrDefault();
if (temperatureValue == null || weatherNode == null) throw new Exception("Invalid response");
var temperature = FlexibleParser.ParseDouble(temperatureValue);
var type = OpenWeatherTypeToCommonType((OpenWeatherType)int.Parse(weatherNode.Attribute(@"number").Value, NumberStyles.Any, CultureInfo.InvariantCulture));
var description = weatherNode.Attribute(@"value").Value;
var icon = weatherNode.Attribute(@"icon")?.Value;
var iconUri = icon == null ? null : string.Format(IconUri, icon);
return new WeatherDescription(type, temperature, description, iconUri);
}
}
}