Esempio n. 1
0
        public static void WriteError(
            Exception exception,
            string message,
            ConsoleColor color  = ConsoleColor.Red,
            Verbosity verbosity = Verbosity.Quiet)
        {
            var colors = new ConsoleColors(color);

            WriteLine(exception.Message, colors, verbosity);

            if (exception is AggregateException aggregateException)
            {
                WriteInnerExceptions(aggregateException, "");
            }
#if DEBUG
            WriteLine(exception.ToString());
#endif
            void WriteInnerExceptions(AggregateException aggregateException, string indent)
            {
                indent += "  ";

                foreach (Exception innerException in aggregateException.InnerExceptions)
                {
                    WriteLine(indent + "Inner exception: " + innerException.Message, colors, verbosity);

                    if (innerException is AggregateException aggregateException2)
                    {
                        WriteInnerExceptions(aggregateException2, indent);
                    }
                }

                indent = indent.Substring(2);
            }
        }
Esempio n. 2
0
 public void WriteLineIf(bool condition, string value, ConsoleColors colors)
 {
     if (condition)
     {
         WriteLine(value, colors);
     }
 }
Esempio n. 3
0
        public static void WriteUsedFixers(
            ImmutableArray <CodeFixProvider> fixers,
            CodeAnalysisOptions options,
            ConsoleColors colors,
            Verbosity verbosity)
        {
            if (!ShouldWrite(verbosity))
            {
                return;
            }

            foreach (IGrouping <string, string> grouping in fixers
                     .SelectMany(f => f.FixableDiagnosticIds)
                     .Distinct()
                     .Where(f => options.IsSupportedDiagnosticId(f))
                     .GroupBy(f => f, DiagnosticIdComparer.Prefix)
                     .OrderBy(f => f.Key, DiagnosticIdComparer.Prefix))
            {
                int    count  = grouping.Count();
                string prefix = DiagnosticIdPrefix.GetPrefix(grouping.Key);

                Write($"  {count} fixable {((count == 1) ? "diagnostic" : "diagnostics")} with ", colors, verbosity);
                Write((string.IsNullOrEmpty(prefix)) ? "no prefix" : $"prefix '{prefix}'", colors, verbosity);

                using (IEnumerator <string> en = grouping
                                                 .OrderBy(f => f)
                                                 .GetEnumerator())
                {
                    if (en.MoveNext())
                    {
                        Write(" (", colors, verbosity);

                        while (true)
                        {
                            Write(en.Current, colors, verbosity);

                            if (en.MoveNext())
                            {
                                Write(", ", colors, verbosity);
                            }
                            else
                            {
                                break;
                            }
                        }

                        Write(")", colors, verbosity);
                    }
                }

                WriteLine("", colors, verbosity);
            }
        }
Esempio n. 4
0
 public void Write(string value, ConsoleColors colors)
 {
     if (!colors.IsDefault)
     {
         ConsoleColors tmp = Colors;
         Colors = colors;
         Write(value);
         Colors = tmp;
     }
     else
     {
         Write(value);
     }
 }
Esempio n. 5
0
        public static void WriteUsedAnalyzers(
            ImmutableArray <DiagnosticAnalyzer> analyzers,
            Func <DiagnosticDescriptor, bool> predicate,
            CodeAnalysisOptions options,
            ConsoleColors colors,
            Verbosity verbosity)
        {
            if (!analyzers.Any())
            {
                return;
            }

            if (!ShouldWrite(verbosity))
            {
                return;
            }

            IEnumerable <DiagnosticDescriptor> descriptors = analyzers
                                                             .SelectMany(f => f.SupportedDiagnostics)
                                                             .Distinct(DiagnosticDescriptorComparer.Id)
                                                             .Where(f => options.IsSupportedDiagnosticId(f.Id));

            if (predicate != null)
            {
                descriptors = descriptors.Where(predicate);
            }

            foreach (IGrouping <DiagnosticDescriptor, DiagnosticDescriptor> grouping in descriptors
                     .GroupBy(f => f, DiagnosticDescriptorComparer.IdPrefix)
                     .OrderBy(f => f.Key, DiagnosticDescriptorComparer.IdPrefix))
            {
                int    count  = grouping.Count();
                string prefix = DiagnosticIdPrefix.GetPrefix(grouping.Key.Id);

                Write($"  {count} supported {((count == 1) ? "diagnostic" : "diagnostics")} with ", colors, verbosity);
                Write((string.IsNullOrEmpty(prefix)) ? "no prefix" : $"prefix '{prefix}'", colors, verbosity);

                using (IEnumerator <DiagnosticDescriptor> en = grouping
                                                               .OrderBy(f => f.Id)
                                                               .GetEnumerator())
                {
                    if (en.MoveNext())
                    {
                        Write(" (", colors, verbosity);

                        while (true)
                        {
                            Write(en.Current.Id, colors, verbosity);

                            if (en.MoveNext())
                            {
                                Write(", ", colors, verbosity);
                            }
                            else
                            {
                                break;
                            }
                        }

                        Write(")", colors, verbosity);
                    }
                }

                WriteLine("", colors, verbosity);
            }
        }
Esempio n. 6
0
 public void WriteLine(string value, ConsoleColors colors, Verbosity verbosity)
 {
     WriteLineIf(ShouldWrite(verbosity), value, colors);
 }
Esempio n. 7
0
 public static void WriteLineIf(bool condition, string value, ConsoleColors colors)
 {
     ConsoleOut.WriteLineIf(condition, value, colors);
     Out?.WriteLineIf(condition, value);
 }
Esempio n. 8
0
 public static void WriteLine(string value, ConsoleColors colors, Verbosity verbosity)
 {
     ConsoleOut.WriteLine(value, colors, verbosity: verbosity);
     Out?.WriteLine(value, verbosity: verbosity);
 }
Esempio n. 9
0
 public static void WriteLine(string value, ConsoleColors colors)
 {
     ConsoleOut.WriteLine(value, colors);
     Out?.WriteLine(value);
 }