public static void HandleAddressGeoCoding() { //should we do all? int maxRecords = 0; LoggingHelper.DoTrace(5, thisClassName + string.Format(".HandleAddressGeoCoding - maxRecords: {0}", maxRecords)); DateTime started = DateTime.Now; string report = ""; string messages = ""; var list = new Entity_AddressManager().ResolveMissingGeodata(ref messages, maxRecords); var saveDuration = DateTime.Now.Subtract(started); LoggingHelper.DoTrace(5, thisClassName + string.Format(".NormalizeAddresses - Completed - seconds: {0}", saveDuration.Seconds)); if (!string.IsNullOrWhiteSpace(messages)) { report = string.Format("<p>Normalize Addresses. Duration: {0} seconds <br/>", saveDuration.Seconds) + messages + "</p>"; } foreach (var address in list) { string msg = string.Format(" - Unable to resolve address: Id: {0}, address1: {1}, city: {2}, region: {3}, postalCode: {4}, country: {5} ", address.Id, address.StreetAddress, address.AddressLocality, address.AddressRegion, address.PostalCode, address.AddressCountry); LoggingHelper.DoTrace(2, msg); report += System.Environment.NewLine + msg; } //no reporting of successes here }
// fix addresses missing lat/lng, and normalize //[Authorize( Roles = "Administrator, Site Staff" )] public ActionResult NormalizeAddresses(int maxRecords = 100) { var user = AccountServices.GetCurrentUser(); if (user != null && ( user.Email == "*****@*****.**" || user.Email == "*****@*****.**" ) ) { //next } else //if ( !User.Identity.IsAuthenticated // || ( User.Identity.Name != "mparsons" // && User.Identity.Name != "*****@*****.**" // && User.Identity.Name != "*****@*****.**" ) // ) { SetSystemMessage("Unauthorized Action", "You are not authorized to invoke NormalizeAddresses."); return(RedirectToAction("Index", "Message")); } string report = ""; string messages = ""; List <CM.Address> list = new Entity_AddressManager().ResolveMissingGeodata(ref messages, maxRecords: maxRecords); if (!string.IsNullOrWhiteSpace(messages)) { report = "<p>Normalize Addresses: <br/>" + messages + "</p>"; } foreach (var address in list) { string msg = string.Format(" - Unable to resolve address: Id: {0}, address1: {1}, city: {2}, region: {3}, postalCode: {4}, country: {5} ", address.Id, address.Address1, address.City, address.AddressRegion, address.PostalCode, address.Country); LoggingHelper.DoTrace(2, msg); report += System.Environment.NewLine + msg; } SetSystemMessage("Normalize Addresses", report); return(RedirectToAction("Index", "Message", new { area = "" })); }
public void NormalizeAddressesExternal(string authorization, int maxRecords, ref string message) { LoggingHelper.DoTrace(5, thisClassName + string.Format(".NormalizeAddressesExternal - starting maxRecords: {0}", maxRecords)); //do validation if ((authorization ?? "").ToLower() != "bca5a70f-cf0d-4b27-8566-9f874d88741e") { message = "You are not authorized to invoke NormalizeAddressesExternal."; return; } //may be OK from API if (UtilityManager.GetAppKeyValue("envType") == "development") { //message="Sorry the NormalizeAddresses process is not available in the development environment (not allowed by Google)." ; //return; } int addressesFixed = 0; int addressRemaining = 0; DateTime started = DateTime.Now; string messages = ""; List <Address> list = new Entity_AddressManager().ResolveMissingGeodata(ref messages, ref addressesFixed, ref addressRemaining, maxRecords); var saveDuration = DateTime.Now.Subtract(started); LoggingHelper.DoTrace(5, thisClassName + string.Format(".NormalizeAddressesExternal - Completed - seconds: {0}", saveDuration.Seconds)); int addressesNotFixed = list.Count(); message = string.Format("Normalize Addresses. Duration: {0} seconds, Addresses Fixed: {1}, Not Fixed: {2} Remaining: {3}", saveDuration.Seconds, addressesFixed, addressesNotFixed, addressRemaining); //where called externally, don't need details, just count. Could be used in a loop. //foreach ( var address in list ) //{ // if ( !string.IsNullOrWhiteSpace( address.StreetAddress ) ) // { // string msg = string.Format( " - Unable to resolve address: Id: {0}, address1: {1}, city: {2}, region: {3}, postalCode: {4}, country: {5} ", address.Id, address.StreetAddress, address.AddressLocality, address.AddressRegion, address.PostalCode, address.AddressCountry ); // LoggingHelper.DoTrace( 2, msg ); // report += System.Environment.NewLine + msg; // } //} }