コード例 #1
0
        public Program(string[] args)
        {
            try
            {
                Day.UseLogs = true;

                // parse command args
                Args = ParseCommandLineArgs(args);

                if (Args.HasArg(CommandLineArgs.SupportedArgument.Help))
                {
                    Args.PrintHelp(LogLine);
                    return;
                }

                // get the number of records to keep for perf tests
                if (Args.HasArgValue(CommandLineArgs.SupportedArgument.PerfRecordCount))
                {
                    m_recordCount = long.Parse(Args.Args[CommandLineArgs.SupportedArgument.PerfRecordCount]);
                }

                // get the timeout runs should adhere to
                if (Args.HasArgValue(CommandLineArgs.SupportedArgument.PerfTimeout))
                {
                    m_maxPerfTimeoutMs = long.Parse(Args.Args[CommandLineArgs.SupportedArgument.PerfTimeout]);
                }

                // TODO: programatically find the latest year to use
                // get the namespace to use
                string baseNamespace = nameof(AoC._2021);
                if (Args.HasArgValue(CommandLineArgs.SupportedArgument.Namespace))
                {
                    baseNamespace = Args.Args[CommandLineArgs.SupportedArgument.Namespace];
                }

                // run the day specified or the latest day
                if (Args.HasArg(CommandLineArgs.SupportedArgument.Day))
                {
                    Day day = RunDay(baseNamespace, Args.Args[CommandLineArgs.SupportedArgument.Day]);
                    if (day == null)
                    {
                        LogLine($"Unable to find {baseNamespace}.{Args.Args[CommandLineArgs.SupportedArgument.Day]}");
                    }
                    else
                    {
                        LogLine("");
                    }
                }
                else if (!Args.HasArg(CommandLineArgs.SupportedArgument.SkipLatest))
                {
                    Day latestDay = RunLatestDay(baseNamespace);
                    if (latestDay == null)
                    {
                        LogLine($"Unable to find any solutions for namespace {baseNamespace}");
                    }
                    else
                    {
                        LogLine("");
                    }
                }

                // show performance
                if (Args.HasArg(CommandLineArgs.SupportedArgument.ShowPerf))
                {
                    ShowPerformance(baseNamespace);
                }
                // run performance tests
                else if (Args.HasArg(CommandLineArgs.SupportedArgument.RunPerf))
                {
                    RunPerformance(baseNamespace);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }