public int Handle(WoeIdByCoordinates query) { if (query == null) { throw new ArgumentNullException("query"); } return(HandleFakeWoeIdByCoordinatesInternal.Handle(query, _geoNames, _geoPlanet)); }
public int Handle(WoeIdByCoordinates query) { if (query == null) { throw new ArgumentNullException("query"); } int? woeId = null; var retries = 0; const int retryLimit = 6; Result placeFinderResult = null; // ReSharper disable PossibleInvalidOperationException var latitude = query.Coordinates.Latitude.Value; var longitude = query.Coordinates.Longitude.Value; // ReSharper restore PossibleInvalidOperationException while (!woeId.HasValue && retries++ < retryLimit) { placeFinderResult = _placeFinder.Find( new PlaceByCoordinates(latitude, longitude)).FirstOrDefault(); if (placeFinderResult != null) { woeId = placeFinderResult.WoeId; } if (!woeId.HasValue) { latitude += 0.00001; longitude += 0.00001; } } if (!woeId.HasValue && placeFinderResult != null) { var freeformText = string.Format("{0} {1}", placeFinderResult.CityName, placeFinderResult.CountryName); if (!string.IsNullOrWhiteSpace(freeformText)) { var result = _placeFinder.Find(new PlaceByFreeformText(freeformText)).FirstOrDefault(); if (result != null) { woeId = result.WoeId; } } else { woeId = HandleFakeWoeIdByCoordinatesInternal.Handle(query, _geoNames, _geoPlanet); } } if (woeId.HasValue) { return(woeId.Value); } return(GeoPlanetPlace.EarthWoeId); }