Exemplo n.º 1
0
        private void GeocodeLocationAndSave(Location matchedLocation)
        {
            // geocode - limit 900 per hour / one every 4 seconds
            var geocodeResult     = new GeocodeResult();
            var cityGeocodeResult = new GeocodeResult();
            var successFlag       = false;

            try
            {
                geocodeResult = _geocodeService.Geocode("", matchedLocation.StreetAddress, matchedLocation.City,
                                                        matchedLocation.State, matchedLocation.Zip);
                successFlag = true;
            }
            catch (Exception e)
            {
                ReportErrors.AddError(string.Format("Unable to fetch GeocodeResult for {0} {1} {2} {3}", matchedLocation.StreetAddress, matchedLocation.City, matchedLocation.State, matchedLocation.Zip));
            }
            try
            {
                cityGeocodeResult = _geocodeService.Geocode("", "", matchedLocation.City, matchedLocation.State,
                                                            matchedLocation.Zip);
                successFlag &= true;
            }
            catch (Exception e)
            {
                ReportErrors.AddError(string.Format("Unable to fetch CityGeocodeResult for {0} {1} {2} {3}", matchedLocation.StreetAddress, matchedLocation.City, matchedLocation.State, matchedLocation.Zip));
            }

            if (successFlag)
            {
                geocodeResult.SaveTo(matchedLocation);

                if (geocodeResult.IsSameAs(cityGeocodeResult))
                {
                    // geocode failure likely
                    ReportErrors.AddError(string.Format("Geocode failure for location {0}", matchedLocation.LegacyId));
                    matchedLocation.IsFailedGeocode = true;
                }

                if (matchedLocation.Id == 0 && matchedLocation.LegacyId != "0")
                {
                    _locationService.Insert(matchedLocation);
                }
                else
                {
                    _locationService.Update(matchedLocation);
                }
            }
        }
        private async Task <bool> CalculateCoords()
        {
            var cords = await _geocode.Geocode(HolderToAdd.OwnerAddress);

            if (String.IsNullOrEmpty(cords.latitude))
            {
                return(false);
            }
            HolderToAdd.OwnerLatitude  = cords.latitude;
            HolderToAdd.OwnerLongitude = cords.longitude;
            return(true);
        }
        public async Task Handle(GeocodeVacancyCommand message, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Geocoding vacancy {vacancyId}.", message.VacancyId);

            var vacancy = await _repository.GetVacancyAsync(message.VacancyId);

            if (string.IsNullOrEmpty(vacancy?.EmployerLocation?.Postcode))
            {
                _logger.LogWarning("Geocode vacancyId:{vacancyId} cannot geocode as vacancy has no postcode", vacancy.Id);
                return;
            }

            _logger.LogInformation("Attempting to geocode postcode:{postcode} for vacancyId:{vacancyId}", vacancy.EmployerLocation.Postcode, vacancy.Id);
            var geocode = await _geocodeService.Geocode(vacancy.EmployerLocation.Postcode);

            await SetVacancyGeocode(vacancy.Id, geocode);
        }