public double GetElevation(double lat, double lng) { IElevationService service = GetService(); double elevation = service.GetElevation(lat, lng); if (elevation == 0 || elevation < -100) { // Error getting elevation so just return 0. Logger.Write( $"{service.GetServiceId()} response not reliable: {elevation.ToString()}, and will be blacklisted for one hour.", LogLevel.Warning ); BlacklistStrategy(service.GetType()); Logger.Write( $"Falling back to next elevation strategy: {GetService().GetServiceId()}.", LogLevel.Warning ); // After blacklisting, retry. return(GetElevation(lat, lng)); } return(elevation); }
public async Task <double> GetElevation(double lat, double lng) { IElevationService service = GetService(); if (service is RandomElevationService) { // Don't hit the database for random elevation service. return(await service.GetElevation(lat, lng).ConfigureAwait(false)); } ElevationLocation elevationLocation = await ElevationLocation.FindOrUpdateInDatabase(lat, lng, service).ConfigureAwait(false); if (elevationLocation == null) { Logger.Write( $"{service.GetServiceId()} response not reliable and will be blacklisted for one hour.", LogLevel.Warning ); BlacklistStrategy(service.GetType()); Logger.Write( $"Falling back to next elevation strategy: {GetService().GetServiceId()}.", LogLevel.Warning ); // After blacklisting, retry. return(await GetElevation(lat, lng).ConfigureAwait(false)); } return(BaseElevationService.GetRandomElevation(elevationLocation.Altitude)); }
public string GetServiceId() { IElevationService service = GetService(); return(service.GetServiceId()); }