Exemplo n.º 1
0
        /// <summary>
        /// Charge la base olson définie dans le répertoire spécifié
        /// </summary>
        /// <param name="directory">Répertoire de la base olson</param>
        private static void LoadDirectory(string directory)
        {
            if (string.IsNullOrEmpty(directory))
            {
                throw new ArgumentNullException(nameof(directory));
            }

            // Ignore backzone file
            string[] excludeFiles = new string[] { "BACKZONE", "CALENDARS", "MAKEFILE", "NEWS", "README", "VERSION" };
            string[] files        = Directory.GetFiles(directory).Where(e => !excludeFiles.Contains(Path.GetFileName(e).ToUpperInvariant())).ToArray();

            foreach (string file in files)
            {
                using (FileStream fs = new FileStream(file, FileMode.Open))
                {
                    using (TextReader reader = new StreamReader(fs))
                    {
                        if (string.IsNullOrEmpty(Path.GetExtension(file)))
                        {
                            LoadFile(reader, file);
                        }
                        else if (string.Compare(Path.GetFileName(file), "iso3166.tab", StringComparison.InvariantCultureIgnoreCase) == 0)
                        {
                            LoadCountryCode(reader);
                        }
                        else if (string.Compare(Path.GetFileName(file), "zone1970.tab", StringComparison.InvariantCultureIgnoreCase) == 0)
                        {
                            LoadZoneName(reader);
                        }
                        else if (string.Compare(Path.GetFileName(file), "windowsZones.tab", StringComparison.InvariantCultureIgnoreCase) == 0)
                        {
                            LoadMappingZones(reader);
                        }
                    }
                }
            }

            // Si le mapping windows/TZID n'est pas présent on utilise la ressource incorporée
            if (_mappingWindowsTZID.Count == 0)
            {
                using (Stream stream = MultiPlatform.GetCurrentAssembly().GetManifestResourceStream("Afk.ZoneInfo.data.windowsZones.tab"))
                {
                    using (TextReader reader = new StreamReader(stream))
                    {
                        LoadMappingZones(reader);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Load resources
        /// </summary>
        private static void LoadRessources()
        {
            Assembly a = MultiPlatform.GetCurrentAssembly();


            string[] resnames = a.GetManifestResourceNames();

            foreach (string resource in resnames)
            {
                if (resource.StartsWith("Afk.ZoneInfo.data.", StringComparison.InvariantCulture))
                {
                    string[] parts = resource.Split(new char[] { '.' }, 4);
                    if (parts.Length == 4)
                    {
                        using (Stream stream = a.GetManifestResourceStream(resource))
                        {
                            using (TextReader reader = new StreamReader(stream))
                            {
                                if (string.IsNullOrEmpty(Path.GetExtension(parts[3])))
                                {
                                    LoadFile(reader, parts[3]);
                                }
                                else if (string.Compare(Path.GetFileName(parts[3]), "iso3166.tab", StringComparison.InvariantCultureIgnoreCase) == 0)
                                {
                                    LoadCountryCode(reader);
                                }
                                else if (string.Compare(Path.GetFileName(parts[3]), "zone1970.tab", StringComparison.InvariantCultureIgnoreCase) == 0)
                                {
                                    LoadZoneName(reader);
                                }
                                else if (string.Compare(Path.GetFileName(parts[3]), "windowsZones.tab", StringComparison.InvariantCultureIgnoreCase) == 0)
                                {
                                    LoadMappingZones(reader);
                                }
                            }
                        }
                    }
                }
            }
        }