ReadFileConfigs() public method

public ReadFileConfigs ( SortedDictionary availableDataFiles ) : void
availableDataFiles SortedDictionary
return void
Esempio n. 1
0
        private void LoadMappingFileProvider()
        {
            var files = new SortedDictionary <int, HashSet <string> >();

#if NET40
            var asm = Assembly.GetExecutingAssembly();
#else
            var asm = typeof(PhoneNumberOfflineGeocoder).GetTypeInfo().Assembly;
#endif
            var allNames = asm.GetManifestResourceNames();
            var prefix   = asm.GetName().Name + "." + phonePrefixDataDirectory;
            var names    = allNames.Where(n => n.StartsWith(prefix));
            foreach (var n in names)
            {
                var name = n.Substring(prefix.Length);
                var pos  = name.IndexOf("_", StringComparison.Ordinal);
                int country;
                try
                {
                    country = int.Parse(name.Substring(0, pos));
                }
                catch (FormatException)
                {
                    throw new Exception("Failed to parse geocoding file name: " + name);
                }
                var language = name.Substring(pos + 1);
                if (!files.ContainsKey(country))
                {
                    files[country] = new HashSet <string>();
                }
                files[country].Add(language);
            }
            mappingFileProvider = new MappingFileProvider();
            mappingFileProvider.ReadFileConfigs(files);
        }
        private void LoadMappingFileProvider()
        {
            var files    = new SortedDictionary <int, HashSet <String> >();
            var asm      = Redirections.GetAssembly();
            var allNames = asm.GetManifestResourceNames();
            var prefix   = asm.GetName().Name + "." + phonePrefixDataDirectory;
            var names    = allNames.Where(n => n.StartsWith(prefix));

            foreach (var n in names)
            {
                var name = n.Substring(prefix.Length);
                var pos  = name.IndexOf("_");
                int country;
                try
                {
                    country = int.Parse(name.Substring(0, pos));
                }
                catch (FormatException)
                {
                    throw new Exception("Failed to parse geocoding file name: " + name);
                }
                var language = name.Substring(pos + 1);
                if (!files.ContainsKey(country))
                {
                    files[country] = new HashSet <String>();
                }
                files[country].Add(language);
            }
            mappingFileProvider = new MappingFileProvider();
            mappingFileProvider.ReadFileConfigs(files);
        }
        /* OLD */

        /*
         * private void LoadMappingFileProvider()
         * {
         *  var files = new SortedDictionary<int, HashSet<string>>();
         #if (NET35 || NET40)
         *  var asm = Assembly.GetExecutingAssembly();
         #else
         *  var asm = typeof(PhoneNumberOfflineGeocoder).GetTypeInfo().Assembly;
         #endif
         *  var allNames = asm.GetManifestResourceNames();
         *  var prefix = asm.GetName().Name + "." + phonePrefixDataDirectory;
         *  var names = allNames.Where(n => n.StartsWith(prefix));
         *  foreach (var n in names)
         *  {
         *      var name = n.Substring(prefix.Length);
         *      var pos = name.IndexOf("_", StringComparison.Ordinal);
         *      int country;
         *      try
         *      {
         *          country = int.Parse(name.Substring(0, pos));
         *      }
         *      catch(FormatException)
         *      {
         *          throw new Exception("Failed to parse geocoding file name: " + name);
         *      }
         *      var language = name.Substring(pos + 1);
         *      if (!files.ContainsKey(country))
         *          files[country] = new HashSet<string>();
         *      files[country].Add(language);
         *  }
         *  mappingFileProvider = new MappingFileProvider();
         *  mappingFileProvider.ReadFileConfigs(files);
         * }*/

        /* CHANGE */
        private void LoadMappingFileProvider(bool forceEmbedded = false)
        {
            var files = new SortedDictionary <int, HashSet <string> >();

            string[] names;
            string   prefix;

            if (string.IsNullOrEmpty(PhoneNumberUtil.ExternalResourcesRootDirectory) || forceEmbedded)
            {
#if (NET35 || NET40)
                var asm = Assembly.GetExecutingAssembly();
#else
                var asm = typeof(PhoneNumberOfflineGeocoder).GetTypeInfo().Assembly;
#endif
                string[] allNames = asm.GetManifestResourceNames();
                prefix = asm.GetName().Name + "." + phonePrefixDataDirectory;
                names  = allNames.Where(n => n.StartsWith(prefix)).ToArray();
            }
            else
            {
                prefix = "prod_";
                names  = Directory.GetFiles(PhoneNumberUtil.ExternalResourcesRootDirectory, prefix + "*");
                if (names.Length == 0)
                {
                    LoadMappingFileProvider(true);
                    return;
                }
                for (int i = 0; i < names.Length; i++)
                {
                    names[i] = Path.GetFileName(names[i]);
                }
            }

            foreach (var n in names)
            {
                var name = n.Substring(prefix.Length);
                var pos  = name.IndexOf("_", StringComparison.Ordinal);
                int country;
                try
                {
                    country = int.Parse(name.Substring(0, pos));
                }
                catch (FormatException)
                {
                    throw new Exception("Failed to parse geocoding file name: " + name);
                }
                var language = name.Substring(pos + 1);
                if (!files.ContainsKey(country))
                {
                    files[country] = new HashSet <string>();
                }
                files[country].Add(language);
            }
            mappingFileProvider = new MappingFileProvider();
            mappingFileProvider.ReadFileConfigs(files);
        }
Esempio n. 4
0
        // @VisibleForTesting
        public PhoneNumberOfflineGeocoder(string phonePrefixDataDirectory, Assembly asm = null)
        {
            var files = new SortedDictionary <int, HashSet <string> >();

#if NETSTANDARD1_3 || PORTABLE
            asm ??= typeof(PhoneNumberOfflineGeocoder).GetTypeInfo().Assembly;
#else
            asm ??= typeof(PhoneNumberOfflineGeocoder).Assembly;
#endif
            var allNames = asm.GetManifestResourceNames();
            var prefix   = asm.GetName().Name + "." + phonePrefixDataDirectory;
            var names    = allNames.Where(n => n.StartsWith(prefix, StringComparison.Ordinal));
            foreach (var n in names)
            {
                var name = n.Substring(prefix.Length).Split('.');
                int country;
                try
                {
                    country = int.Parse(name[1], CultureInfo.InvariantCulture);
                }
                catch (FormatException)
                {
                    throw new Exception("Failed to parse geocoding file name: " + name);
                }
                var language = name[0];
                if (!files.TryGetValue(country, out var languages))
                {
                    files[country] = languages = new HashSet <string>();
                }
                languages.Add(language);
            }
            mappingFileProvider = new MappingFileProvider();
            mappingFileProvider.ReadFileConfigs(files);
            this.assembly = asm;
            this.phonePrefixDataDirectory = prefix;
        }
 private void LoadMappingFileProvider()
 {
     var files = new SortedDictionary<int, HashSet<String>>();
     var asm = Assembly.GetExecutingAssembly();
     var allNames = asm.GetManifestResourceNames();
     var prefix = asm.GetName().Name + "." + phonePrefixDataDirectory;
     var names = allNames.Where(n => n.StartsWith(prefix));
     foreach (var n in names)
     {
         var name = n.Substring(prefix.Length);
         var pos = name.IndexOf("_");
         int country;
         try
         {
             country = int.Parse(name.Substring(0, pos));
         }
         catch(FormatException)
         {
             throw new Exception("Failed to parse geocoding file name: " + name);
         }
         var language = name.Substring(pos + 1);
         if (!files.ContainsKey(country))
             files[country] = new HashSet<String>();
         files[country].Add(language);
     }
     mappingFileProvider = new MappingFileProvider();
     mappingFileProvider.ReadFileConfigs(files);
 }