コード例 #1
0
 /// <summary>
 /// Displays an error message to the console.
 /// </summary>
 /// <param name="message">The error message.</param>
 protected virtual void ShowErrorMessage(string message)
 {
     console.ForegroundColor = ConsoleColor.Red;
     console.WriteLine(String.Format("Error: {0}", message));
     console.ResetColor();
     console.WriteLine();
 }
コード例 #2
0
        private void ShowTaskBeginningBanner()
        {
            // Just print the task name once.
            if (!bannerPrinted)
            {
                width = console.Width;

                console.ForegroundColor = ConsoleColor.White;
                console.WriteLine(StringUtils.TruncateWithEllipsis(ProgressMonitor.TaskName, width - 1));
                console.ResetColor();

                bannerPrinted = true;
            }
        }
コード例 #3
0
        /// <inheritdoc />
        protected override void LogImpl(LogSeverity severity, string message, ExceptionData exceptionData)
        {
            lock (console.SyncRoot)
            {
                bool oldFooterVisible = console.FooterVisible;
                try
                {
                    console.FooterVisible = false;

                    if (!console.IsRedirected)
                    {
                        switch (severity)
                        {
                        case LogSeverity.Error:
                            console.ForegroundColor = ConsoleColor.Red;
                            break;

                        case LogSeverity.Warning:
                            console.ForegroundColor = ConsoleColor.Yellow;
                            break;

                        case LogSeverity.Important:
                            console.ForegroundColor = ConsoleColor.White;
                            break;

                        case LogSeverity.Info:
                            console.ForegroundColor = ConsoleColor.Gray;
                            break;

                        case LogSeverity.Debug:
                            console.ForegroundColor = ConsoleColor.DarkGray;
                            break;
                        }
                    }

                    console.WriteLine(message);

                    if (exceptionData != null)
                    {
                        console.WriteLine(Indent(exceptionData.ToString()));
                    }

                    if (!console.IsRedirected)
                    {
                        console.ResetColor();
                    }
                }
                finally
                {
                    console.FooterVisible = oldFooterVisible;
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Runs the program.
        /// </summary>
        /// <param name="console">The console.</param>
        /// <param name="args">The command-line arguments.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="console"/>
        /// or <paramref name="args"/> is null.</exception>
        /// <exception cref="InvalidOperationException">Thrown if the program has already started running.</exception>
        public int Run(IRichConsole console, string[] args)
        {
            if (console == null)
            {
                throw new ArgumentNullException("console");
            }
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }
            if (this.console != null)
            {
                throw new InvalidOperationException("The program has already started running.");
            }

            this.console      = console;
            commandLineOutput = new CommandLineOutput(console);

            try
            {
                if (!console.IsRedirected)
                {
                    console.Title = ApplicationTitle;
                }

                return(RunImpl(args));
            }
            catch (Exception ex)
            {
                return(HandleFatalException(ex));
            }
            finally
            {
                console.ResetColor();
            }
        }