Esempio n. 1
0
        private static string FormatTime(double elapsedMilliseconds, SolverConfiguration configuration, bool useColor = true)
        {
#pragma warning disable CS0618 // Type or member is obsolete - Needed to keep compatibility
            var customFormatSpecifier = configuration?.ElapsedTimeFormatSpecifier ?? ElapsedTimeFormatSpecifier;
#pragma warning restore CS0618 // Type or member is obsolete

            var message = customFormatSpecifier is null
                ? elapsedMilliseconds switch
            {
Esempio n. 2
0
        private static void RenderRow(Table table, string problemTitle, string part, string solution, double elapsedMilliseconds, SolverConfiguration configuration)
        {
            var formattedTime = FormatTime(elapsedMilliseconds, configuration);

            table.AddRow(problemTitle, part, solution, formattedTime);

            if (IsInteractiveEnvironment)
            {
                if (configuration?.ClearConsole == true)
                {
                    Console.Clear();
                }
                else
                {
                    AnsiConsole.Console.Clear(true);
                }
            }

            AnsiConsole.Render(table);
        }
Esempio n. 3
0
        private static ElapsedTime SolveProblem(BaseProblem problem, Table table, double constructorElapsedTime, SolverConfiguration configuration)
        {
            var problemIndex = problem.CalculateIndex();
            var problemTitle = problemIndex != default
                ? $"Day {problemIndex}"
                : $"{problem.GetType().Name}";

            if (configuration.ShowConstructorElapsedTime)
            {
                RenderRow(table, problemTitle, $"{problem.GetType().Name}()", "-----------", constructorElapsedTime, configuration);
            }

            (string solution1, double elapsedMillisecondsPart1) = SolvePart(isPart1: true, problem);
            RenderRow(table, problemTitle, "Part 1", solution1, elapsedMillisecondsPart1, configuration);

            (string solution2, double elapsedMillisecondsPart2) = SolvePart(isPart1: false, problem);
            RenderRow(table, problemTitle, "Part 2", solution2, elapsedMillisecondsPart2, configuration);

            if (configuration.ShowTotalElapsedTimePerDay)
            {
                RenderRow(table, problemTitle, "[bold]Total[/]", "-----------", constructorElapsedTime + elapsedMillisecondsPart1 + elapsedMillisecondsPart2, configuration);
            }

            table.AddEmptyRow();

            return(new ElapsedTime(constructorElapsedTime, elapsedMillisecondsPart1, elapsedMillisecondsPart2));
        }