Пример #1
0
        public void Launch()
        {
            if (ShowHeader)
            {
                Cli.WriteHeader(Name, HeaderStyle);
                Cli.WriteLine();
            }

            if (Environment.GetCommandLineArgs().Length == 1)
            {
                CliArgWriter.WriteArguments <TArgs>();
                Environment.Exit(1);
            }

            var args = Environment.GetCommandLineArgs().Skip(1).ToArray();

            try
            {
                Arguments = new CliArgReader(args).Read <TArgs>();
            }
            catch (ArgumentException e)
            {
                WriteFatalError(0x1, e.Message);
            }

            Main(Arguments);
        }
Пример #2
0
 public static void WriteSubheader(string text, string style = "")
 {
     Cli.WriteLine(
         "{0}  {1}{2}{3}",
         style,
         Cli.Escape(text),
         new string(' ', Console.BufferWidth - text.Length - 3),
         "~R~");
 }
Пример #3
0
        public void WriteFatalError(int errorCode, string format, params object[] arg)
        {
            if (IsProcessing)
            {
                Cli.WriteLine("\r\n");
            }

            Cli.WriteSubheader(_fatalError, ErrorHeaderStyle);
            Cli.WriteLine();
            Cli.WriteLine(format, arg);
            Environment.Exit(errorCode);
        }
Пример #4
0
        public virtual void Launch()
        {
            var n = Name;

            if (Debugger.IsAttached)
            {
                n += " (under debugger)";
            }

            Console.Title = n;

            if (ShowHeader)
            {
                Cli.WriteHeader(n, HeaderStyle);
                Cli.WriteLine();
            }

            var props = CliArgProperty.GetAll <TArgs>();

            if (Environment.GetCommandLineArgs().Length == 1 && props.Any())
            {
                CliArgWriter.WriteArguments <TArgs>();
                Environment.Exit(1);
            }

            Arguments = ParseArguments();

            if (Debugger.IsAttached)
            {
                Main(Arguments);
            }
            else
            {
                try
                {
                    AppDomain.CurrentDomain.UnhandledException += (o, e) =>
                                                                  HandleUnexpectedException(e.ExceptionObject as Exception);

                    Main(Arguments);
                }
                catch (OutOfMemoryException e)
                {
                    HandleUnexpectedException(e);
                }
                catch (Exception e)
                {
                    HandleUnexpectedException(e);
                }
            }
        }
Пример #5
0
        public void Process <TElement>(IEnumerable <TElement> collection, Action <TElement> action)
        {
            IsProcessing = true;
            var progress = new CliProgressBar(collection.Count());

            progress.Write();

            foreach (var element in collection)
            {
                action(element);
                progress.IncrementAndWrite();
            }

            Cli.WriteLine();
            IsProcessing = false;
        }
Пример #6
0
        protected virtual TArgs ParseArguments()
        {
            var args = Environment.GetCommandLineArgs().Skip(1).ToArray();

            try
            {
                return(new CliArgReader(args).Read <TArgs>());
            }
            catch (ArgumentException e)
            {
                Cli.WriteLine();
                WriteFatalError(0x1, e.Message);

                return(default(TArgs));
            }
        }
Пример #7
0
 public void WriteMessage(ConsoleColor tokenColor, char token, string format, params object[] arg)
 {
     Cli.WriteLine(
         string.Format(_messageFormat, tokenColor, token, format),
         arg);
 }