示例#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);
 }