Exemplo n.º 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);
        }
Exemplo n.º 2
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);
                }
            }
        }