Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        public string GetServiceId()
        {
            IElevationService service = GetService();

            return(service.GetServiceId());
        }