예제 #1
0
파일: Program.cs 프로젝트: 0xced/nodatime
        private static async Task <int> Main(string[] args)
        {
            Options            options = new Options();
            ICommandLineParser parser  = new CommandLineParser(new CommandLineParserSettings(Console.Error));

            if (!parser.ParseArguments(args, options))
            {
                return(1);
            }
            // Not null after we've parsed the arguments.
            TzdbDateTimeZoneSource source = await LoadSourceAsync(options.Source);

            var dumper = new ZoneDumper(source, options);

            try
            {
                using (var writer = options.OutputFile is null ? Console.Out : File.CreateText(options.OutputFile))
                {
                    dumper.Dump(writer);
                }
            }
            catch (UserErrorException e)
            {
                Console.Error.WriteLine($"Error: {e.Message}");
                return(1);
            }

            return(0);
        }
예제 #2
0
        private static int Main(string[] args)
        {
            Options options = new Options();
            ICommandLineParser parser = new CommandLineParser(new CommandLineParserSettings(Console.Error) { MutuallyExclusive = true });
            if (!parser.ParseArguments(args, options))
            {
                return 1;
            }
            TzdbDateTimeZoneSource source = LoadSource(options.Source);
            var dumper = new ZoneDumper(source, options);
            try
            {
                using (var writer = options.OutputFile == null ? Console.Out : File.CreateText(options.OutputFile))
                {
                    dumper.Dump(writer);
                }
            }
            catch (UserErrorException e)
            {
                Console.Error.WriteLine($"Error: {e.Message}");
                return 1;
            }

            return 0;
        }        
예제 #3
0
        private static int Main(string[] args)
        {
            Options            options = new Options();
            ICommandLineParser parser  = new CommandLineParser(new CommandLineParserSettings(Console.Error)
            {
                MutuallyExclusive = true
            });

            if (!parser.ParseArguments(args, options))
            {
                return(1);
            }
            TzdbDateTimeZoneSource source = LoadSource(options.Source);
            var dumper = new ZoneDumper(source, options);

            try
            {
                using (var writer = options.OutputFile == null ? Console.Out : File.CreateText(options.OutputFile))
                {
                    dumper.Dump(writer);
                }
            }
            catch (UserErrorException e)
            {
                Console.Error.WriteLine($"Error: {e.Message}");
                return(1);
            }

            return(0);
        }
예제 #4
0
        // This will do something soon :)
        public IActionResult Generate(int startYear = 1, int endYear = 2035)
        {
            var source = TzdbDateTimeZoneSource.Default;
            var writer = new StringWriter();
            var options = new Options { FromYear = startYear, ToYear = endYear };
            var dumper = new ZoneDumper(source, options);
            dumper.Dump(writer);

            return new ContentResult
            {
                Content = writer.ToString(),
                ContentType = "text/plain",
                StatusCode = (int) HttpStatusCode.OK
            };
        }