/// <summary> /// Geocodes the specified <see cref="Rock.CRM.Address"/> /// </summary> /// <param name="address">The address.</param> /// <param name="personId">The person id.</param> public void Geocode(Rock.CRM.Address address, int?personId) { Core.ServiceLogService logService = new Core.ServiceLogService(); string inputAddress = address.ToString(); // Try each of the geocoding services that were found through MEF foreach (KeyValuePair <int, Lazy <Rock.Address.GeocodeComponent, Rock.Extension.IComponentData> > service in Rock.Address.GeocodeContainer.Instance.Components) { if (!service.Value.Value.AttributeValues.ContainsKey("Active") || bool.Parse(service.Value.Value.AttributeValues["Active"].Value[0].Value)) { string result; bool success = service.Value.Value.Geocode(address, out result); // Log the results of the service Core.ServiceLog log = new Core.ServiceLog(); log.Time = DateTime.Now; log.Type = "Address Geocode"; log.Name = service.Value.Metadata.ComponentName; log.Input = inputAddress; log.Result = result; log.Success = success; logService.Add(log, personId); logService.Save(log, personId); // If succesful, set the results and stop processing if (success) { address.GeocodeService = service.Value.Metadata.ComponentName; address.GeocodeResult = result; address.GeocodeDate = DateTime.Now; break; } } } address.GeocodeAttempt = DateTime.Now; }
/// <summary> /// Geocodes the specified <see cref="Rock.CRM.Address"/> /// </summary> /// <param name="address">The address.</param> /// <param name="personId">The person id.</param> public void Geocode( Rock.CRM.Address address, int? personId ) { Core.ServiceLogService logService = new Core.ServiceLogService(); string inputAddress = address.ToString(); // Try each of the geocoding services that were found through MEF foreach ( KeyValuePair<int, Lazy<Rock.Address.GeocodeComponent, Rock.Extension.IComponentData>> service in Rock.Address.GeocodeContainer.Instance.Components ) if ( !service.Value.Value.AttributeValues.ContainsKey( "Active" ) || bool.Parse( service.Value.Value.AttributeValues["Active"].Value ) ) { string result; bool success = service.Value.Value.Geocode( address, out result ); // Log the results of the service Core.ServiceLog log = new Core.ServiceLog(); log.Time = DateTime.Now; log.Type = "Address Geocode"; log.Name = service.Value.Metadata.ComponentName; log.Input = inputAddress; log.Result = result; log.Success = success; logService.Add( log, personId ); logService.Save( log, personId ); // If succesful, set the results and stop processing if ( success ) { address.GeocodeService = service.Value.Metadata.ComponentName; address.GeocodeResult = result; address.GeocodeDate = DateTime.Now; break; } } address.GeocodeAttempt = DateTime.Now; }