Exemplo n.º 1
0
        //phonelib calls
        public ParsedPhoneNumber IsPhoneNumberValid(string phoneNumber, string defaultIsoCode)
        {
            var parsedNumber = new ParsedPhoneNumber();

            if (!string.IsNullOrEmpty(phoneNumber))
            {
                var phoneNumberUtil = PhoneNumberUtil.GetInstance();
                parsedNumber.IsViablePhoneNumber   = PhoneNumberUtil.IsViablePhoneNumber(phoneNumber);
                parsedNumber.ExtractPossibleNumber = PhoneNumberUtil.ExtractPossibleNumber(phoneNumber);
                parsedNumber.NormalizedNumber      = PhoneNumberUtil.Normalize(phoneNumber);
                parsedNumber.NormalizedDigitsOnly  = PhoneNumberUtil.NormalizeDigitsOnly(phoneNumber);
                if (parsedNumber.IsViablePhoneNumber.Value)
                {
                    var numberObject = phoneNumberUtil.Parse(phoneNumber, defaultIsoCode);
                    parsedNumber.E164Format     = phoneNumberUtil.Format(numberObject, PhoneNumberFormat.E164);
                    parsedNumber.IntFormat      = phoneNumberUtil.Format(numberObject, PhoneNumberFormat.INTERNATIONAL);
                    parsedNumber.IsValidNumber  = phoneNumberUtil.IsValidNumber(numberObject);
                    parsedNumber.CountryCode    = numberObject.CountryCode;
                    parsedNumber.HasCountryCode = numberObject.HasCountryCode;
                    parsedNumber.PreferredDomesticCarrierCode = numberObject.PreferredDomesticCarrierCode;
                    var geocoder = PhoneNumbers.PhoneNumberOfflineGeocoder.GetInstance();
                    parsedNumber.GeoCoderDescription = geocoder.GetDescriptionForNumber(numberObject, PhoneNumbers.Locale.English);
                    parsedNumber.NumberType          = phoneNumberUtil.GetNumberType(numberObject).ToString();
                }
            }

            return(parsedNumber);
        }
Exemplo n.º 2
0
        private void SetPhoneNumberResultValuesToOutput(PipelineBuffer buffer, int x, ParsedPhoneNumber parsedPhoneNumberResult)
        {
            foreach (var outputColumn in _outputColumnList)
            {
                var colindex = outputColumn.ColumnIndex;
                switch (outputColumn.Name)
                {
                case PhoneLibMethodConstants.CountryCode:
                    buffer.SetInt32(colindex, parsedPhoneNumberResult.CountryCode);
                    break;

                case PhoneLibMethodConstants.E164Format:
                    buffer.SetString(colindex, parsedPhoneNumberResult.E164Format);
                    break;

                case PhoneLibMethodConstants.ExtractPossibleNumber:
                    buffer.SetString(colindex, parsedPhoneNumberResult.ExtractPossibleNumber);
                    break;

                case PhoneLibMethodConstants.GeoCoderDescription:
                    buffer.SetString(colindex, parsedPhoneNumberResult.GeoCoderDescription);
                    break;

                case PhoneLibMethodConstants.HasCountryCode:
                    buffer.SetBoolean(colindex, parsedPhoneNumberResult.HasCountryCode);
                    break;

                case PhoneLibMethodConstants.IntFormat:
                    buffer.SetString(colindex, parsedPhoneNumberResult.IntFormat);
                    break;

                case PhoneLibMethodConstants.IsValidNumber:
                    buffer.SetBoolean(colindex, parsedPhoneNumberResult.IsValidNumber);
                    break;

                case PhoneLibMethodConstants.IsViablePhoneNumber:
                    if (parsedPhoneNumberResult.IsViablePhoneNumber.HasValue)
                    {
                        buffer.SetBoolean(colindex, parsedPhoneNumberResult.IsViablePhoneNumber.Value);
                    }
                    else
                    {
                        buffer.SetBoolean(colindex, false);
                    }
                    break;

                case PhoneLibMethodConstants.NormalizedDigitsOnly:
                    buffer.SetString(colindex, parsedPhoneNumberResult.NormalizedDigitsOnly);
                    break;

                case PhoneLibMethodConstants.NormalizedNumber:
                    buffer.SetString(colindex, parsedPhoneNumberResult.NormalizedNumber);
                    break;

                case PhoneLibMethodConstants.PreferredDomesticCarrierCode:
                    buffer.SetString(colindex, parsedPhoneNumberResult.PreferredDomesticCarrierCode);
                    break;

                case PhoneLibMethodConstants.NumberType:
                    buffer.SetString(colindex, parsedPhoneNumberResult.NumberType);
                    break;
                }
            }
        }