Ejemplo n.º 1
0
        public static async Task <GeoTagsEntry> TryToLocateAsync([CanBeNull] string address)
        {
            if (string.IsNullOrWhiteSpace(address))
            {
                return(null);
            }

            var key = Key + address;

            if (CacheStorage.Contains(key))
            {
                var cache = CacheStorage.GetPointNullable(key);
                return(cache.HasValue ? new GeoTagsEntry(cache.Value.X, cache.Value.Y) : null);
            }

            try {
                var result = await YahooApiProvider.LocateAsync(address);

                if (result.LatitudeValue.HasValue && result.LongitudeValue.HasValue)
                {
                    Logging.Write($"“{address}”, geo tags: ({result})");
                    CacheStorage.Set(key, new Point(result.LatitudeValue.Value, result.LongitudeValue.Value));
                    return(result);
                }

                CacheStorage.Set(key, "");
                return(null);
            } catch (WebException e) {
                Logging.Warning("TryToLocateAsync(): " + e.Message);
                return(null);
            } catch (Exception e) {
                Logging.Warning("TryToLocateAsync(): " + e);
                CacheStorage.Set(key, "");
                return(null);
            }
        }