private void LoadLocationFiles(FileSource source, TzdbDatabase database) { if (!source.Contains(Iso3166TabFile)) { return; } var iso3166 = source.ReadLines(Iso3166TabFile) .Where(line => line != "" && !line.StartsWith("#")) .Select(line => line.Split('\t')) .ToList(); if (source.Contains(ZoneTabFile)) { var iso3166Dict = iso3166.ToDictionary(bits => bits[0], bits => bits[1]); database.ZoneLocations = source.ReadLines(ZoneTabFile) .Where(line => line != "" && !line.StartsWith("#")) .Select(line => TzdbZoneLocationParser.ParseLocation(line, iso3166Dict)) .ToList(); } if (source.Contains(Zone1970TabFile)) { var iso3166Dict = iso3166.ToDictionary(bits => bits[0], bits => new TzdbZone1970Location.Country(code: bits[0], name: bits[1])); database.Zone1970Locations = source.ReadLines(ZoneTabFile) .Where(line => line != "" && !line.StartsWith("#")) .Select(line => TzdbZoneLocationParser.ParseEnhancedLocation(line, iso3166Dict)) .ToList(); } }
private void LoadZoneFiles(FileSource source, TzdbDatabase database) { var tzdbParser = new TzdbZoneInfoParser(); foreach (var file in ZoneFiles) { if (source.Contains(file)) { log?.WriteLine("Parsing file {0} . . .", file); using (var stream = source.Open(file)) { tzdbParser.Parse(stream, database); } } } }
private async Task <FileSource> LoadSourceAsync(string path) { if (path.StartsWith("ftp://") || path.StartsWith("http://") || path.StartsWith("https://")) { log?.WriteLine($"Downloading {path}"); var data = await FileUtility.LoadFileOrUrlAsync(path); return(FileSource.FromArchive(new MemoryStream(data), path)); } if (Directory.Exists(path)) { log?.WriteLine($"Compiling from directory {path}"); return(FileSource.FromDirectory(path)); } else { log?.WriteLine($"Compiling from archive file {path}"); using (var file = File.OpenRead(path)) { return(FileSource.FromArchive(file, path)); } } }
private string InferVersion(FileSource source) { if (source.Contains(Makefile)) { foreach (var line in source.ReadLines(Makefile)) { if (Regex.IsMatch(line, @"VERSION=\d{4}.*")) { var version = line.Substring(8).Trim(); log?.WriteLine($"Inferred version {version} from {Makefile}"); return(version); } } } var match = VersionRegex.Match(source.Origin); if (match.Success) { var version = match.Value; log?.WriteLine($"Inferred version {version} from file/directory name {source.Origin}"); return(version); } throw new InvalidDataException("Unable to determine TZDB version from source"); }
internal static IEnumerable <string> ReadLines(this FileSource source, string name) => ReadLines(() => new StreamReader(source.Open(name)));
private string InferVersion(FileSource source) { if (source.Contains(Makefile)) { foreach (var line in source.ReadLines(Makefile)) { if (line.StartsWith("VERSION=")) { var version = line.Substring(8).Trim(); log?.WriteLine($"Inferred version {version} from {Makefile}"); return version; } } } var match = VersionRegex.Match(source.Origin); if (match.Success) { var version = match.Value; log?.WriteLine($"Inferred version {version} from file/directory name {source.Origin}"); return version; } throw new InvalidDataException("Unable to determine TZDB version from source"); }