예제 #1
0
        private static List <DateTimeZone> LoadSource(Options options, out string version)
        {
            var source = options.Source;

            if (source == null)
            {
                var tzdbSource = TzdbDateTimeZoneSource.Default;
                version = tzdbSource.TzdbVersion;
                return(tzdbSource.GetIds().Select(id => tzdbSource.ForId(id)).ToList());
            }
            if (source.EndsWith(".nzd"))
            {
                var data       = LoadFileOrUrl(source);
                var tzdbSource = TzdbDateTimeZoneSource.FromStream(new MemoryStream(data));
                version = tzdbSource.TzdbVersion;
                return(tzdbSource.GetIds().Select(id => tzdbSource.ForId(id)).ToList());
            }
            else
            {
                var compiler = new TzdbZoneInfoCompiler(log: null);
                var database = compiler.Compile(source);
                version = database.Version;
                return(database.GenerateDateTimeZones()
                       .Concat(database.Aliases.Keys.Select(database.GenerateDateTimeZone))
                       .ToList());
            }
        }
예제 #2
0
        /// <summary>
        /// Runs the compiler from the command line.
        /// </summary>
        /// <param name="arguments">The command line arguments. Each compiler defines its own.</param>
        /// <returns>0 for success, non-0 for error.</returns>
        private static int Main(string[] arguments)
        {
            CompilerOptions    options = new CompilerOptions();
            ICommandLineParser parser  = new CommandLineParser(new CommandLineParserSettings(Console.Error));

            if (!parser.ParseArguments(arguments, options))
            {
                return(1);
            }

            var writer       = CreateWriter(options);
            var tzdbCompiler = new TzdbZoneInfoCompiler();
            var tzdb         = tzdbCompiler.Compile(options.SourceDirectoryName);

            tzdb.LogCounts();
            var windowsZones = CldrWindowsZonesParser.Parse(options.WindowsMappingFile);

            LogWindowsZonesSummary(windowsZones);
            writer.Write(tzdb, windowsZones);

            Console.WriteLine("Reading generated data and validating...");
            var source = Read(options);

            source.Validate();
            return(0);
        }
예제 #3
0
파일: Program.cs 프로젝트: 0xced/nodatime
        /// <summary>
        /// Runs the compiler from the command line.
        /// </summary>
        /// <param name="arguments">The command line arguments. Each compiler defines its own.</param>
        /// <returns>0 for success, non-0 for error.</returns>
        private static async Task <int> Main(string[] arguments)
        {
            CompilerOptions    options = new CompilerOptions();
            ICommandLineParser parser  = new CommandLineParser(new CommandLineParserSettings(Console.Error)
            {
                MutuallyExclusive = true
            });

            if (!parser.ParseArguments(arguments, options))
            {
                return(1);
            }

            var tzdbCompiler = new TzdbZoneInfoCompiler();
            var tzdb         = await tzdbCompiler.CompileAsync(options.SourceDirectoryName !);

            tzdb.LogCounts();
            if (options.ZoneId != null)
            {
                tzdb.GenerateDateTimeZone(options.ZoneId);
                return(0);
            }
            var windowsZones = LoadWindowsZones(options, tzdb.Version);

            if (options.WindowsOverride != null)
            {
                var overrideFile = CldrWindowsZonesParser.Parse(options.WindowsOverride);
                windowsZones = MergeWindowsZones(windowsZones, overrideFile);
            }
            LogWindowsZonesSummary(windowsZones);
            var writer = new TzdbStreamWriter();

            using (var stream = CreateOutputStream(options))
            {
                writer.Write(tzdb, windowsZones, NameIdMappingSupport.StandardNameToIdMap, stream);
            }

            if (options.OutputFileName != null)
            {
                Console.WriteLine("Reading generated data and validating...");
                var source = Read(options);
                source.Validate();
            }

            if (options.XmlSchema is object)
            {
                Console.WriteLine($"Writing XML schema to {options.XmlSchema}");
                var source   = Read(options);
                var provider = new DateTimeZoneCache(source);
                XmlSerializationSettings.DateTimeZoneProvider = provider;
                var settings = new XmlWriterSettings {
                    Indent = true, NewLineChars = "\n", Encoding = new UTF8Encoding()
                };
                using var xmlWriter = XmlWriter.Create(options.XmlSchema, settings);
                XmlSchemaDefinition.NodaTimeXmlSchema.Write(xmlWriter);
            }
            return(0);
        }
예제 #4
0
        /// <summary>
        /// Runs the compiler from the command line.
        /// </summary>
        /// <param name="arguments">The command line arguments. Each compiler defines its own.</param>
        /// <returns>0 for success, non-0 for error.</returns>
        private static int Main(string[] arguments)
        {
            CompilerOptions    options = new CompilerOptions();
            ICommandLineParser parser  = new CommandLineParser(new CommandLineParserSettings(Console.Error)
            {
                MutuallyExclusive = true
            });

            if (!parser.ParseArguments(arguments, options))
            {
                return(1);
            }

            var tzdbCompiler = new TzdbZoneInfoCompiler();
            var tzdb         = tzdbCompiler.Compile(options.SourceDirectoryName !);

            tzdb.LogCounts();
            if (options.ZoneId != null)
            {
                tzdb.GenerateDateTimeZone(options.ZoneId);
                return(0);
            }
            var windowsZones = LoadWindowsZones(options, tzdb.Version);

            if (options.WindowsOverride != null)
            {
                var overrideFile = CldrWindowsZonesParser.Parse(options.WindowsOverride);
                windowsZones = MergeWindowsZones(windowsZones, overrideFile);
            }
            LogWindowsZonesSummary(windowsZones);
            var writer = new TzdbStreamWriter();

            using (var stream = CreateOutputStream(options))
            {
                writer.Write(tzdb, windowsZones, NameIdMappingSupport.StandardNameToIdMap, stream);
            }

            if (options.OutputFileName != null)
            {
                Console.WriteLine("Reading generated data and validating...");
                var source = Read(options);
                source.Validate();
            }
            return(0);
        }
예제 #5
0
 private static TzdbDateTimeZoneSource LoadSource(string source)
 {
     if (source == null)
     {
         return(TzdbDateTimeZoneSource.Default);
     }
     if (source.EndsWith(".nzd"))
     {
         var data = LoadFileOrUrl(source);
         return(TzdbDateTimeZoneSource.FromStream(new MemoryStream(data)));
     }
     else
     {
         var compiler = new TzdbZoneInfoCompiler(log: null);
         var database = compiler.Compile(source);
         return(database.ToTzdbDateTimeZoneSource());
     }
 }
예제 #6
0
파일: Program.cs 프로젝트: 0xced/nodatime
        private static async Task <TzdbDateTimeZoneSource> LoadSourceAsync(string?source)
        {
            if (source is null)
            {
                return(TzdbDateTimeZoneSource.Default);
            }
            if (source.EndsWith(".nzd"))
            {
                var data = await FileUtility.LoadFileOrUrlAsync(source);

                return(TzdbDateTimeZoneSource.FromStream(new MemoryStream(data)));
            }
            else
            {
                var compiler = new TzdbZoneInfoCompiler(log: null);
                var database = await compiler.CompileAsync(source);

                return(database.ToTzdbDateTimeZoneSource());
            }
        }
예제 #7
0
        /// <summary>
        /// Runs the compiler from the command line.
        /// </summary>
        /// <param name="arguments">The command line arguments. Each compiler defines its own.</param>
        /// <returns>0 for success, non-0 for error.</returns>
        private static int Main(string[] arguments)
        {
            CompilerOptions    options = new CompilerOptions();
            ICommandLineParser parser  = new CommandLineParser(new CommandLineParserSettings(Console.Error)
            {
                MutuallyExclusive = true
            });

            if (!parser.ParseArguments(arguments, options))
            {
                return(1);
            }

            var tzdbCompiler = new TzdbZoneInfoCompiler();
            var tzdb         = tzdbCompiler.Compile(options.SourceDirectoryName);

            tzdb.LogCounts();
            if (options.ZoneId != null)
            {
                tzdb.GenerateDateTimeZone(options.ZoneId);
                return(0);
            }
            var windowsZones = LoadWindowsZones(options, tzdb.Version);

            LogWindowsZonesSummary(windowsZones);
            var writer = CreateWriter(options);

            writer.Write(tzdb, windowsZones);

            if (options.OutputFileName != null)
            {
                Console.WriteLine("Reading generated data and validating...");
                var source = Read(options);
                source.Validate();
                if (options.TextDumpFile != null)
                {
                    CreateTextDump(source, options.TextDumpFile);
                }
            }
            return(0);
        }
예제 #8
0
        private static List <DateTimeZone> LoadSource(Options options)
        {
            var source = options.Source;

            if (source == null)
            {
                var provider = DateTimeZoneProviders.Tzdb;
                return(provider.Ids.Select(id => provider[id]).ToList());
            }
            if (source.EndsWith(".nzd"))
            {
                var data       = LoadFileOrUrl(source);
                var tzdbSource = TzdbDateTimeZoneSource.FromStream(new MemoryStream(data));
                return(tzdbSource.GetIds().Select(id => tzdbSource.ForId(id)).ToList());
            }
            else
            {
                var compiler = new TzdbZoneInfoCompiler(log: null);
                var database = compiler.Compile(source);
                return(database.GenerateDateTimeZones()
                       .Concat(database.Aliases.Keys.Select(database.GenerateDateTimeZone))
                       .ToList());
            }
        }