protected bool Equals(GeoTagsEntry other) { if (other == null) { return(false); } return(IsEmptyOrInvalid ? other.IsEmptyOrInvalid : !other.IsEmptyOrInvalid && LatitudeValue.Equals(other.LatitudeValue) && LongitudeValue.Equals(other.LongitudeValue)); }
private void Model_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (_skipNext) return; switch (e.PropertyName) { case nameof(Model.Latitude): case nameof(Model.Longitude): var pair = new GeoTagsEntry(Model.Latitude, Model.Longitude); if (!pair.IsEmptyOrInvalid) { MapWebBrowser.InvokeScript(@"moveTo", pair.LatitudeValue + @";" + pair.LongitudeValue); } break; } }
public static async Task<TimeZoneInfo> TryToDetermineAsync(GeoTagsEntry geoTags) { var key = Key + geoTags; if (CacheStorage.Contains(key)) { return CacheStorage.GetTimeZoneInfo(key); } try { var result = await GoogleApiProvider.DetermineTimeZoneAsync(geoTags); CacheStorage.Set(key, result); return result; } catch (WebException e) { Logging.Warning("TryToDetermineAsync(): " + e.Message); return null; } catch (Exception e) { Logging.Warning("TryToDetermineAsync(): " + e); CacheStorage.Set(key, ""); return null; } }
public static async Task<WeatherDescription> TryToGetWeatherAsync(GeoTagsEntry geoTags) { CleanUpCache(); CachedEntry cached; if (LocalCache.TryGetValue(geoTags, out cached)) { return cached.Item2; } try { var result = await new OpenWeatherApiProvider().GetWeatherAsync(geoTags); LocalCache.Add(geoTags, new CachedEntry(DateTime.Now, result)); return result; } catch (WebException e) { Logging.Warning("TryToGetWeather(): " + e.Message); return null; } catch (Exception e) { Logging.Warning("TryToGetWeather(): " + e); return null; } }
public static async Task<TimeZoneInfo> DetermineTimeZoneAsync(GeoTagsEntry geoTags) { var requestUri = string.Format(RequestTimeZoneUri, geoTags.LatitudeValue, geoTags.LongitudeValue, DateTime.Now.ToUnixTimestamp()); Logging.Debug(requestUri); using (var order = KillerOrder.Create(new WebClient(), 5000)) { var data = await order.Victim.DownloadStringTaskAsync(requestUri); var doc = XDocument.Parse(data); var zoneId = doc.Descendants(@"time_zone_id").FirstOrDefault()?.Value; if (zoneId == null) throw new Exception("Invalid response"); try { return TimeZoneInfo.FindSystemTimeZoneById(zoneId); } catch (TimeZoneNotFoundException) { var rawOffset = doc.Descendants(@"raw_offset").FirstOrDefault()?.Value; var zoneName = doc.Descendants(@"time_zone_name").FirstOrDefault()?.Value; if (rawOffset == null || zoneName == null) throw new Exception("Invalid response"); return TimeZoneInfo.CreateCustomTimeZone(zoneId, TimeSpan.FromSeconds(FlexibleParser.ParseDouble(rawOffset)), zoneName, zoneName); } } }
public static JArray ToJObject(this GeoTagsEntry geoTagsEntry) { return(new JArray(geoTagsEntry.Latitude, geoTagsEntry.Longitude)); }
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); } }
protected bool Equals(GeoTagsEntry other) { if (other == null) return false; return IsEmptyOrInvalid ? other.IsEmptyOrInvalid : !other.IsEmptyOrInvalid && LatitudeValue.Equals(other.LatitudeValue) && LongitudeValue.Equals(other.LongitudeValue); }