Esempio n. 1
0
 public override void Write(string value)
 {
     using (ConsoleColorScope.CreateFrom(m_ConsoleColors[DefaultColor]))
     {
         Console.WriteLine(value);
     }
 }
Esempio n. 2
0
 public override void WriteDebugLine(string message)
 {
     using (ConsoleColorScope.CreateFrom(m_ConsoleColors[DebugColor]))
     {
         Console.WriteLine($"[DEBUG] {message}");
     }
 }
Esempio n. 3
0
 public override void WriteVerboseLine(string message)
 {
     using (ConsoleColorScope.CreateFrom(m_ConsoleColors[VerboseColor]))
     {
         Console.WriteLine($"[VERBOSE] {message}");
     }
 }
Esempio n. 4
0
 public override void WriteWarningLine(string message)
 {
     using (ConsoleColorScope.CreateFrom(m_ConsoleColors[WarningColor]))
     {
         Console.WriteLine($"[WARNING] {message}");
     }
 }
Esempio n. 5
0
        private static void AddLangVersionElement(this XContainer document, XNamespace @namespace, string langVersion)
        {
            var propertyGroups = document
                                 .Descendants(@namespace + "PropertyGroup")
                                 .ToList();

            var langVersionElement = propertyGroups.Descendants(@namespace + "LangVersion").FirstOrDefault();

            if (langVersionElement != null)
            {
                // If we already have an element, just set the value.
                langVersionElement.SetValue(langVersion);
                return;
            }

            var emptyPropertyGroup = propertyGroups.FirstOrDefault(x => !x.HasAttributes);

            var globalPropertyGroup = emptyPropertyGroup ?? propertyGroups.FirstOrDefault();

            if (globalPropertyGroup == null)
            {
                using (ConsoleColorScope.Start(ConsoleColor.Yellow))
                {
                    Console.WriteLine("No PropertyGroup element found in file.");
                }
            }
            else
            {
                globalPropertyGroup.Add(new XElement(@namespace + "LangVersion")
                {
                    Value = langVersion
                });
            }
        }
Esempio n. 6
0
 public override void WriteErrorLine(string value)
 {
     using (ConsoleColorScope.CreateFrom(m_ConsoleColors[ErrorColor]))
     {
         Console.WriteLine($"[ERROR] {value}");
     }
 }
Esempio n. 7
0
        public static int Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Usage: LangVersionFixer <folder-with-csprojs> <lang-version-number> [<clean-document>]");
                return(-1);
            }

            var directoryPath = args[0];
            var langVersion   = args[1];

            var cleanDocument = true;

            if (args.Length > 2)
            {
                var parseOk = Boolean.TryParse(args[2], out cleanDocument);
                if (!parseOk)
                {
                    using (ConsoleColorScope.Start(ConsoleColor.Red))
                    {
                        Console.WriteLine($"Could not convert '{args[2].ToString()}' to boolean.");
                        return(-1);
                    }
                }
            }

            int parsedLangVersion;

            if (!int.TryParse(langVersion, out parsedLangVersion))
            {
                if (!langVersion.Equals("default", StringComparison.OrdinalIgnoreCase))
                {
                    using (ConsoleColorScope.Start(ConsoleColor.Red))
                    {
                        Console.WriteLine($"'{langVersion}' is not a valid LangVersion parameter.");
                        return(-1);
                    }
                }
            }

            var directory = new DirectoryInfo(directoryPath);

            if (!directory.Exists)
            {
                using (ConsoleColorScope.Start(ConsoleColor.Red))
                {
                    Console.WriteLine($"Folder '{directoryPath}' does not exist.");
                    return(-1);
                }
            }

            directory.FixLangVersion(langVersion, cleanDocument);

            using (ConsoleColorScope.Start(ConsoleColor.Green))
            {
                Console.WriteLine($"Successfully set LangVersion to {langVersion} in all projects.");
                return(0);
            }
        }
Esempio n. 8
0
        public void Error(string message)
        {
            message.ThrowIfNull(nameof(message));

            using var colorScope = new ConsoleColorScope(ConsoleColor.Red);

            Console.Error.WriteLine($"Error: {_prefix} {message}");
        }
Esempio n. 9
0
        public void Warning(string message)
        {
            message.ThrowIfNull(nameof(message));

            using var colorScope = new ConsoleColorScope(ConsoleColor.Yellow);

            Console.Out.WriteLine($"Warning: {_prefix} {message}");
        }
Esempio n. 10
0
        public void Message(string message)
        {
            message.ThrowIfNull(nameof(message));

            using var colorScope = new ConsoleColorScope(ConsoleColor.Green);

            Console.Out.WriteLine($"Message: {_prefix} {message}");
        }
Esempio n. 11
0
        public void Debug(string message)
        {
            message.ThrowIfNull(nameof(message));

            using var colorScope = new ConsoleColorScope(ConsoleColor.Cyan);

            Console.Out.WriteLine($"Debug: {_prefix} {message}");
        }
Esempio n. 12
0
            public static IDisposable Start(ConsoleColor foregroundColor)
            {
                var scope = new ConsoleColorScope(Console.ForegroundColor);

                Console.ForegroundColor = foregroundColor;

                return(scope);
            }
Esempio n. 13
0
        public void Exception(Exception ex, string?message = null)
        {
            using var colorScope = new ConsoleColorScope(ConsoleColor.Red);

            if (message != null)
            {
                Console.Error.WriteLine($"Exception: {_prefix} {message}");
            }

            Console.Error.WriteLine($"Exception: {_prefix} {ex}");
        }
Esempio n. 14
0
 protected void PrintList()
 {
     if (Config.Paths.Count == 0)
     {
         using var scope = new ConsoleColorScope(Console, ConsoleColor.Yellow);
         Console.WriteLine("There are currently no aliases registered. You can register a new alias by using the 'add' verb.");
         Console.WriteLine("Execute 'cdx add --help' for more information.");
     }
     else
     {
         Console.WriteLine("The following aliases are available:");
         Console.WriteLine();
         new TableControl(Console)
         {
             Margin            = new(3, 0, 0, 0),
             ShowColumnHeaders = false,
             Columns           =
             {
                 new() { WidthMode = ColumnWidthMode.Auto, MaxWidth = Console.BufferSize.Width / 3 },
                 new() { WidthMode = ColumnWidthMode.Star },
             },
Esempio n. 15
0
            public static IDisposable Start(ConsoleColor foregroundColor)
            {
                var scope = new ConsoleColorScope(Console.ForegroundColor);

                Console.ForegroundColor = foregroundColor;

                return scope;
            }