/// <summary> /// Geocodes the specified address. /// </summary> /// <param name="address">The address.</param> /// <param name="result">The result.</param> /// <returns> /// True/False value of whether the address was standardized was succesfully /// </returns> public override bool Geocode( Rock.CRM.Address address, out string result ) { if ( address != null ) { var aptc = new Rock.TeleAtlas.Authentication.AuthenticationPortTypeClient(); int encryptedId; int rc = aptc.requestChallenge( AttributeValues["UserName"].Value, 0, out encryptedId ); if ( rc == 0) { int key = elfHash(AttributeValues["Password"].Value); int unencryptedChallenge = encryptedId ^ key; int permutedChallenge = permute(unencryptedChallenge); int response = permutedChallenge ^ key; int cred; rc = aptc.answerChallenge( response, encryptedId, out cred ); if (rc == 0 ) { var addressParts = new Rock.TeleAtlas.Geocoding.NameValue[5]; addressParts[0] = NameValue( "Addr", string.Format( "{0} {1}", address.Street1, address.Street2 ) ); addressParts[1] = NameValue( "City", address.City ); addressParts[2] = NameValue( "State", address.State ); addressParts[3] = NameValue( "ZIP", address.Zip ); addressParts[4] = NameValue( "Plus4", string.Empty ); var gptc = new Rock.TeleAtlas.Geocoding.GeocodingPortTypeClient(); Rock.TeleAtlas.Geocoding.Geocode returnedGeocode; rc = gptc.findAddress( AttributeValues["EZLocateService"].Value, addressParts, cred, out returnedGeocode ); if ( rc == 0 ) { if ( returnedGeocode.resultCode == 0 ) { Rock.TeleAtlas.Geocoding.NameValue matchType = null; Rock.TeleAtlas.Geocoding.NameValue latitude = null; Rock.TeleAtlas.Geocoding.NameValue longitude = null; foreach ( var attribute in returnedGeocode.mAttributes ) switch ( attribute.name ) { case "MAT_TYPE": matchType = attribute; break; case "MAT_LAT": latitude = attribute; break; case "MAT_LONG": longitude = attribute; break; } if ( matchType != null ) { result = matchType.value; if ( matchType.value == "1" ) { address.Latitude = double.Parse( latitude.value ); address.Longitude = double.Parse( longitude.value ); return true; } } else result = "No Match"; } else result = string.Format( "No Match (requestChallenge result: {0})", rc ); } else result = string.Format( "No Match (geocode result: {0})", rc ); } else result = string.Format( "Could not authenticate (answerChallenge result: {0})", rc ); } else result = string.Format( "Could not authenticate (findAddress result: {0})", rc ); } else result = "Null Address"; return false; }
/// <summary> /// Geocodes the specified address. /// </summary> /// <param name="address">The address.</param> /// <param name="result">The result.</param> /// <returns> /// True/False value of whether the address was standardized was succesfully /// </returns> public override bool Geocode(Rock.CRM.Address address, out string result) { if (address != null) { var aptc = new Rock.TeleAtlas.Authentication.AuthenticationPortTypeClient(); int encryptedId; int rc = aptc.requestChallenge(AttributeValue("UserID"), 0, out encryptedId); if (rc == 0) { int key = elfHash(AttributeValue("Password")); int unencryptedChallenge = encryptedId ^ key; int permutedChallenge = permute(unencryptedChallenge); int response = permutedChallenge ^ key; int cred; rc = aptc.answerChallenge(response, encryptedId, out cred); if (rc == 0) { var addressParts = new Rock.TeleAtlas.Geocoding.NameValue[5]; addressParts[0] = NameValue("Addr", string.Format("{0} {1}", address.Street1, address.Street2)); addressParts[1] = NameValue("City", address.City); addressParts[2] = NameValue("State", address.State); addressParts[3] = NameValue("ZIP", address.Zip); addressParts[4] = NameValue("Plus4", string.Empty); var gptc = new Rock.TeleAtlas.Geocoding.GeocodingPortTypeClient(); Rock.TeleAtlas.Geocoding.Geocode returnedGeocode; rc = gptc.findAddress(AttributeValue("EZLocateService"), addressParts, cred, out returnedGeocode); if (rc == 0) { if (returnedGeocode.resultCode == 0) { Rock.TeleAtlas.Geocoding.NameValue matchType = null; Rock.TeleAtlas.Geocoding.NameValue latitude = null; Rock.TeleAtlas.Geocoding.NameValue longitude = null; foreach (var attribute in returnedGeocode.mAttributes) { switch (attribute.name) { case "MAT_TYPE": matchType = attribute; break; case "MAT_LAT": latitude = attribute; break; case "MAT_LONG": longitude = attribute; break; } } if (matchType != null) { result = matchType.value; if (matchType.value == "1") { address.Latitude = double.Parse(latitude.value); address.Longitude = double.Parse(longitude.value); return(true); } } else { result = "No Match"; } } else { result = string.Format("No Match (requestChallenge result: {0})", rc); } } else { result = string.Format("No Match (geocode result: {0})", rc); } } else { result = string.Format("Could not authenticate (answerChallenge result: {0})", rc); } } else { result = string.Format("Could not authenticate (findAddress result: {0})", rc); } } else { result = "Null Address"; } return(false); }