Пример #1
0
        // Build the PhoneMetadataCollection from the input XML file.
        public static PhoneMetadataCollection BuildPhoneMetadataCollection(string name,
                                                                           bool liteBuild, bool specialBuild, bool isShortNumberMetadata,
                                                                           bool isAlternateFormatsMetadata)
        {
            XDocument document;

#if (NET35 || NET40)
            var asm = Assembly.GetExecutingAssembly();
#else
            var asm = typeof(PhoneNumberUtil).GetTypeInfo().Assembly;
#endif
            using (var input = asm.GetManifestResourceStream(name))
            {
#if NET35
                document = XDocument.Load(new XmlTextReader(input));
#else
                document = XDocument.Load(input);
#endif
            }

            var metadataCollection = new PhoneMetadataCollection.Builder();
            var metadataFilter     = GetMetadataFilter(liteBuild, specialBuild);
            foreach (var territory in document.GetElementsByTagName("territory"))
            {
                // For the main metadata file this should always be set, but for other supplementary data
                // files the country calling code may be all that is needed.
                var regionCode = territory.GetAttribute("id");
                var metadata   = LoadCountryMetadata(regionCode, territory,
                                                     isShortNumberMetadata, isAlternateFormatsMetadata);
                metadataFilter.FilterMetadata(metadata);
                metadataCollection.AddMetadata(metadata);
            }
            return(metadataCollection.Build());
        }
 // Build the PhoneMetadataCollection from the input XML file.
 public static PhoneMetadataCollection BuildPhoneMetadataCollection(Stream input, bool liteBuild)
 {
     using (var reader = XmlReader.Create(input, new XmlReaderSettings()
     {
         DtdProcessing = DtdProcessing.Ignore
     }))
     {
         var document = new XmlDocument();
         document.Load(reader);
         document.Normalize();
         var metadataCollection = new PhoneMetadataCollection.Builder();
         foreach (XmlElement territory in document.GetElementsByTagName("territory"))
         {
             String regionCode = "";
             // For the main metadata file this should always be set, but for other supplementary data
             // files the country calling code may be all that is needed.
             if (territory.HasAttribute("id"))
             {
                 regionCode = territory.GetAttribute("id");
             }
             PhoneMetadata metadata = LoadCountryMetadata(regionCode, territory, liteBuild);
             metadataCollection.AddMetadata(metadata);
         }
         return(metadataCollection.Build());
     }
 }
Пример #3
0
 // Build the PhoneMetadataCollection from the input XML file.
 public static PhoneMetadataCollection BuildPhoneMetadataCollection(Stream input, bool liteBuild) {
     var document = XDocument.Load(input);
     var metadataCollection = new PhoneMetadataCollection.Builder();
     foreach (XElement territory in document.GetElementsByTagName("territory")) {
         String regionCode = "";
         // For the main metadata file this should always be set, but for other supplementary data
         // files the country calling code may be all that is needed.
         if (territory.HasAttribute("id"))
             regionCode = territory.GetAttribute("id");
         PhoneMetadata metadata = LoadCountryMetadata(regionCode, territory, liteBuild);
         metadataCollection.AddMetadata(metadata);
     }
     return metadataCollection.Build();
 }
        // Build the PhoneMetadataCollection from the input XML file.
        /* OLD */

        /*public static PhoneMetadataCollection BuildPhoneMetadataCollection(string name,
         *  bool liteBuild, bool specialBuild, bool isShortNumberMetadata,
         *  bool isAlternateFormatsMetadata)
         * {
         *  XDocument document;
         #if NET35
         *  document = XDocument.Load(name);
         #else
         #if  NET40
         *  var asm = Assembly.GetExecutingAssembly();
         #else
         *  var asm = typeof(PhoneNumberUtil).GetTypeInfo().Assembly;
         #endif
         *  using (var input = asm.GetManifestResourceStream(name))
         *  {
         *      document = XDocument.Load(input);
         *  }
         #endif
         *
         *  var metadataCollection = new PhoneMetadataCollection.Builder();
         *  var metadataFilter = GetMetadataFilter(liteBuild, specialBuild);
         *  foreach (var territory in document.GetElementsByTagName("territory"))
         *  {
         *      // For the main metadata file this should always be set, but for other supplementary data
         *      // files the country calling code may be all that is needed.
         *      var regionCode = territory.GetAttribute("id");
         *      var metadata = LoadCountryMetadata(regionCode, territory,
         *          isShortNumberMetadata, isAlternateFormatsMetadata);
         *      metadataFilter.FilterMetadata(metadata);
         *      metadataCollection.AddMetadata(metadata);
         *  }
         *  return metadataCollection.Build();
         * }*/

        /* CHANGE */
        public static PhoneMetadataCollection BuildPhoneMetadataCollection(string name,
                                                                           bool liteBuild, bool specialBuild, bool isShortNumberMetadata,
                                                                           bool isAlternateFormatsMetadata, bool forceEmbedded = false)
        {
            XDocument document;

            if (string.IsNullOrEmpty(PhoneNumberUtil.ExternalResourcesRootDirectory) || forceEmbedded)
            {
#if NET35
                document = XDocument.Load(name);
#else
#if NET40
                var asm = Assembly.GetExecutingAssembly();
#else
                var asm = typeof(PhoneNumberUtil).GetTypeInfo().Assembly;
#endif
                using (var input = asm.GetManifestResourceStream(name))
                {
                    document = XDocument.Load(input);
                }
#endif
            }
            else
            {
                var _name = Path.Combine(PhoneNumberUtil.ExternalResourcesRootDirectory, name);
                if (!File.Exists(_name))
                {
                    return(BuildPhoneMetadataCollection(name, liteBuild, specialBuild, isShortNumberMetadata, isAlternateFormatsMetadata, true));
                }
                document = XDocument.Load(_name);
            }

            var metadataCollection = new PhoneMetadataCollection.Builder();
            var metadataFilter     = GetMetadataFilter(liteBuild, specialBuild);
            foreach (var territory in document.GetElementsByTagName("territory"))
            {
                // For the main metadata file this should always be set, but for other supplementary data
                // files the country calling code may be all that is needed.
                var regionCode = territory.GetAttribute("id");
                var metadata   = LoadCountryMetadata(regionCode, territory,
                                                     isShortNumberMetadata, isAlternateFormatsMetadata);
                metadataFilter.FilterMetadata(metadata);
                metadataCollection.AddMetadata(metadata);
            }
            return(metadataCollection.Build());
        }
        // @VisibleForTesting
        private static PhoneMetadataCollection BuildPhoneMetadataCollection(XDocument document,
                                                                            bool liteBuild, bool specialBuild, bool isShortNumberMetadata,
                                                                            bool isAlternateFormatsMetadata)
        {
            var metadataCollection = new PhoneMetadataCollection.Builder();
            var metadataFilter     = GetMetadataFilter(liteBuild, specialBuild);

            foreach (var territory in document.GetElementsByTagName("territory"))
            {
                // For the main metadata file this should always be set, but for other supplementary data
                // files the country calling code may be all that is needed.
                var regionCode = territory.GetAttribute("id");
                var metadata   = LoadCountryMetadata(regionCode, territory,
                                                     isShortNumberMetadata, isAlternateFormatsMetadata);
                metadataFilter.FilterMetadata(metadata);
                metadataCollection.AddMetadata(metadata);
            }
            return(metadataCollection.Build());
        }
        // Build the PhoneMetadataCollection from the input XML file.
        public static PhoneMetadataCollection BuildPhoneMetadataCollection(Stream input, bool liteBuild)
        {
            var document           = XDocument.Load(input);
            var metadataCollection = new PhoneMetadataCollection.Builder();

            foreach (XElement territory in document.GetElementsByTagName("territory"))
            {
                String regionCode = "";
                // For the main metadata file this should always be set, but for other supplementary data
                // files the country calling code may be all that is needed.
                if (territory.HasAttribute("id"))
                {
                    regionCode = territory.GetAttribute("id");
                }
                PhoneMetadata metadata = LoadCountryMetadata(regionCode, territory, liteBuild);
                metadataCollection.AddMetadata(metadata);
            }
            return(metadataCollection.Build());
        }
        internal static PhoneMetadataCollection BuildPhoneMetadata(string name, Assembly asm = null,
                                                                   bool liteBuild            = false, bool specialBuild = false, bool isShortNumberMetadata = false, bool isAlternateFormatsMetadata = false,
                                                                   bool nameSuffix           = true)
        {
            XDocument document;

#if NETSTANDARD1_3 || PORTABLE
            asm ??= typeof(PhoneNumberUtil).GetTypeInfo().Assembly;
#else
            asm ??= typeof(PhoneNumberUtil).Assembly;
#endif

            if (nameSuffix)
            {
                name = asm.GetManifestResourceNames().FirstOrDefault(n => n.EndsWith(name, StringComparison.Ordinal)) ?? throw new ArgumentException(name + " resource not found");
            }

            using (var input = asm.GetManifestResourceStream(name))
            {
#if NET35
                document = XDocument.Load(new XmlTextReader(input));
#else
                document = XDocument.Load(input);
#endif
            }

            var metadataCollection = new PhoneMetadataCollection.Builder();
            var metadataFilter     = GetMetadataFilter(liteBuild, specialBuild);
            foreach (var territory in document.Root.Element("territories").Elements())
            {
                // For the main metadata file this should always be set, but for other supplementary data
                // files the country calling code may be all that is needed.
                var regionCode = territory.GetAttribute("id");
                var metadata   = LoadCountryMetadata(regionCode, territory,
                                                     isShortNumberMetadata, isAlternateFormatsMetadata);
                metadataFilter.FilterMetadata(metadata);
                metadataCollection.AddMetadata(metadata);
            }
            return(metadataCollection.Build());
        }
Пример #8
0
 // Build the PhoneMetadataCollection from the input XML file.
 public static PhoneMetadataCollection BuildPhoneMetadataCollection(Stream input, bool liteBuild)
 {
     BuildMetadataFromXml.LiteBuild = liteBuild;
     var documentTemp = XElement.Load(input);
     var document = new XmlElement(documentTemp);
     var metadataCollection = new PhoneMetadataCollection.Builder();
     foreach (XmlElement territory in document.GetElementsByTagName("territory"))
     {
         var regionCode = territory.GetAttribute("id");
         PhoneMetadata metadata = LoadCountryMetadata(regionCode, territory);
         metadataCollection.AddMetadata(metadata);
     }
     return metadataCollection.Build();
 }