Exemple #1
0
        public int Run()
        {
            Console.WriteLine("Loading List Services address with phone numbers records...");

            var phoneNumbers = AddressCsvLoader.LoadFrom(PhoneNumbers);
            var addresses    = AlbaAddressExport.LoadFrom(Addresses);

            Console.WriteLine($"Phone Number Record Count: {phoneNumbers.Count()}");

            var results = AddressCsvLoader.AddPhoneNumbers1And2(
                numbers: phoneNumbers,
                addresses: addresses,
                territoryId: PhoneTerritoryId);

            foreach (var address in results.SuccessfulAddresses)
            {
                Console.WriteLine($"{address.Address}: {address.Notes}");
            }

            Console.WriteLine("Errors:");
            foreach (var error in results.Errors)
            {
                Console.WriteLine($"{error.Address_ID}: {error.Address} {error.Phone1}, {error.Phone2}");
            }

            LoadCsvAddresses.SaveTo(results.SuccessfulAddresses, OutputFilePath);

            return(0);
        }
        private void GeocodeCsvAddressesFrom(string path, string key)
        {
            var amWebClient = new CookieWebClient();
            var amBasePath  = new ApplicationBasePath(
                protocolPrefix: "https://",
                site: "atlas.microsoft.com",
                applicationPath: "/");

            var amClient = new AzureMapsClient(
                webClient: amWebClient,
                basePath: amBasePath,
                subscriptionKey: key);

            int geocoded       = 0;
            int alreadyGeocode = 0;
            var addresses      = LoadCsvAddresses.LoadFrom(path);

            foreach (var address in addresses)
            {
                if (address.Latitude == null ||
                    address.Longitude == null ||
                    address.Latitude == 0 ||
                    address.Longitude == 0)
                {
                    var coordinates = new AzureMapsmGeocodeAddress(view, amClient)
                                      .Geocode(address);

                    address.Latitude  = coordinates.Latitude;
                    address.Longitude = coordinates.Longitude;

                    geocoded++;
                }
                else
                {
                    alreadyGeocode++;
                }
            }

            view.AppendResultText($"\nTotal Addresses: {(geocoded + alreadyGeocode)}");
            view.AppendResultText($"\nGeocoded: {geocoded}");
            view.AppendResultText($"\nAlready Geocoded (Skipped): {alreadyGeocode}");

            var newPath = view.GetFileNameToSaveAs(path, "csv");

            if (string.IsNullOrWhiteSpace(newPath))
            {
                // Cancelled
                view.AppendResultText($"\nGeocoding not saved.");

                return;
            }

            LoadCsvAddresses.SaveTo(addresses, newPath);

            view.AppendResultText($"\nGeocoding saved to {newPath}");
        }