Ejemplo n.º 1
0
        public static AreaCodeMap ParseAreaCodeMap(Stream stream)
        {
            var areaCodeMapTemp = new SortedDictionary <int, string>();

            using (var lines = new StreamReader(stream, Encoding.UTF8))
            {
                string line;
                while ((line = lines.ReadLine()) != null)
                {
                    line = line.Trim();
                    if (line.Length <= 0 || line[0] == '#')
                    {
                        continue;
                    }
                    var indexOfPipe = line.IndexOf('|');
                    if (indexOfPipe == -1)
                    {
                        continue;
                    }
                    var areaCode = line.Substring(0, indexOfPipe);
                    var location = line.Substring(indexOfPipe + 1);
                    areaCodeMapTemp[int.Parse(areaCode)] = location;
                }
                // Build the corresponding area code map and serialize it to the binary format.
                var areaCodeMap = new AreaCodeMap();
                areaCodeMap.ReadAreaCodeMap(areaCodeMapTemp);
                return(areaCodeMap);
            }
        }
 public static AreaCodeMap ParseAreaCodeMap(Stream stream)
 {
     SortedDictionary<int, String> areaCodeMapTemp = new SortedDictionary<int, String>();
     using (var lines = new StreamReader(stream, Encoding.UTF8))
     {
         String line;
         while ((line = lines.ReadLine()) != null)
         {
             line = line.Trim();
             if (line.Length <= 0 || line[0] == '#')
                 continue;
             var indexOfPipe = line.IndexOf('|');
             if (indexOfPipe == -1)
             {
                 continue;
             }
             String areaCode = line.Substring(0, indexOfPipe);
             String location = line.Substring(indexOfPipe + 1);
             areaCodeMapTemp[int.Parse(areaCode)] = location;
         }
         // Build the corresponding area code map and serialize it to the binary format.
         AreaCodeMap areaCodeMap = new AreaCodeMap();
         areaCodeMap.readAreaCodeMap(areaCodeMapTemp);
         return areaCodeMap;
     }
 }
Ejemplo n.º 3
0
        private String GetAreaDescriptionForNumber(
            PhoneNumber number, String lang, String script, String region)
        {
            int countryCallingCode = number.CountryCode;
            // As the NANPA data is split into multiple files covering 3-digit areas, use a phone number
            // prefix of 4 digits for NANPA instead, e.g. 1650.
            //int phonePrefix = (countryCallingCode != 1) ?
            //    countryCallingCode : (1000 + (int) (number.NationalNumber / 10000000));
            int phonePrefix = countryCallingCode;

            AreaCodeMap phonePrefixDescriptions =
                GetPhonePrefixDescriptions(phonePrefix, lang, script, region);
            String description = (phonePrefixDescriptions != null)
                ? phonePrefixDescriptions.Lookup(number)
                : null;

            // When a location is not available in the requested language, fall back to English.
            if ((description == null || description.Length == 0) && MayFallBackToEnglish(lang))
            {
                AreaCodeMap defaultMap = GetPhonePrefixDescriptions(phonePrefix, "en", "", "");
                if (defaultMap == null)
                {
                    return("");
                }
                description = defaultMap.Lookup(number);
            }
            return(description != null ? description : "");
        }