public override async Task <CommandResult> ExecuteAsync(ProjectOrSolution projectOrSolution, CancellationToken cancellationToken = default)
        {
            var codeMetricsOptions = new CodeMetricsOptions(includeGenerated: Options.IncludeGeneratedCode);

            if (projectOrSolution.IsProject)
            {
                Project project = projectOrSolution.AsProject();

                CodeMetricsCounter counter = CodeMetricsCounterFactory.GetLogicalLinesCounter(project.Language);

                if (counter != null)
                {
                    await CountLinesAsync(project, counter, codeMetricsOptions, cancellationToken);
                }
                else
                {
                    WriteLine($"Cannot count logical lines for language '{project.Language}'", ConsoleColor.Yellow, Verbosity.Minimal);
                }
            }
            else
            {
                CountLines(projectOrSolution.AsSolution(), codeMetricsOptions, cancellationToken);
            }

            return(CommandResult.Success);
        }
예제 #2
0
        public override async Task <CommandResult> ExecuteAsync(ProjectOrSolution projectOrSolution, CancellationToken cancellationToken = default)
        {
            var codeMetricsOptions = new CodeMetricsOptions(
                includeGenerated: Options.IncludeGeneratedCode,
                includeWhitespace: Options.IncludeWhitespace,
                includeComments: Options.IncludeComments,
                includePreprocessorDirectives: Options.IncludePreprocessorDirectives,
                ignoreBlockBoundary: Options.IgnoreBlockBoundary);

            if (projectOrSolution.IsProject)
            {
                Project project = projectOrSolution.AsProject();

                CodeMetricsCounter counter = CodeMetricsCounterFactory.GetPhysicalLinesCounter(project.Language);

                if (counter != null)
                {
                    await CountLinesAsync(project, counter, codeMetricsOptions, cancellationToken);
                }
                else
                {
                    WriteLine($"Cannot count lines for '{project.FilePath}', language '{project.Language}' is not supported", ConsoleColor.Yellow, Verbosity.Minimal);
                }
            }
            else
            {
                CountLines(projectOrSolution.AsSolution(), codeMetricsOptions, cancellationToken);
            }

            return(CommandResult.Success);
        }
        private static async Task CountLinesAsync(Project project, CodeMetricsCounter counter, CodeMetricsOptions options, CancellationToken cancellationToken)
        {
            WriteLine($"Count logical lines for '{project.Name}'", ConsoleColor.Cyan, Verbosity.Minimal);

            Stopwatch stopwatch = Stopwatch.StartNew();

            CodeMetricsInfo codeMetrics = await WorkspaceCodeMetrics.CountLinesAsync(project, counter, options, cancellationToken);

            stopwatch.Stop();

            WriteLine(Verbosity.Minimal);

            WriteMetrics(
                codeMetrics.CodeLineCount,
                codeMetrics.WhitespaceLineCount,
                codeMetrics.CommentLineCount,
                codeMetrics.PreprocessorDirectiveLineCount,
                codeMetrics.TotalLineCount);

            WriteLine(Verbosity.Minimal);
            WriteLine($"Done counting logical lines for '{project.FilePath}' in {stopwatch.Elapsed:mm\\:ss\\.ff}", Verbosity.Normal);
        }