Beispiel #1
0
        static void Main(string[] args)
        {
            var configuration = new Configuration {
                ApiKey   = Environment.GetEnvironmentVariable("MAZE_API_KEY"),
                Endpoint = new Uri(Environment.GetEnvironmentVariable("MAZE_ENDPOINT"))
            };
            var bugsnag = new Bugsnag.Client(configuration);
            var app     = new Microsoft.Extensions.CommandLineUtils.CommandLineApplication();

            app.Command("handled", config => {
                bugsnag.Notify(new Exception("Handled Error for Maze Runner"));
            });
            app.Execute(args);
        }
Beispiel #2
0
        public static void Run(string[] args, bool pauseOnExit, Microsoft.Extensions.CommandLineUtils.CommandLineApplication app, List <ICommandDefinition> primaryCommands, IEnumerable <ICommandDefinition> loadedComponents)
        {
            // add default commmands
            if (!loadedComponents.Any(pc => pc.Name.Equals("version", StringComparison.InvariantCultureIgnoreCase)))
            {
                primaryCommands.Add(new VersionPrimaryCommand());
            }

            primaryCommands.AddRange(loadedComponents);

            primaryCommands.ToList().ForEach(pc =>
            {
                var command = app.Command(pc.Name, pc.Config);
                pc.SubCommandDefinitions.ToList().ForEach(sc => command.Command(sc.Name, sc.Config));
            });

            //give people help with --help

            app.HelpOption("-? | -h | --help");

            if (!args.Any())
            {
                args = new string[] { "--help" };
            }

            int result = 0;

            try
            {
                result = app.Execute(args);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                result = app.Execute(new string[] { "--help" });
            }

            if (pauseOnExit)
            {
                Console.WriteLine("Hit Return to exit.");
                Console.ReadLine();
            }

            Environment.Exit(result);
        }
Beispiel #3
0
        private static async Task MainAsync(string[] args)
        {
            var result = 0;

            Console.WriteLine("Message Sender Data Generator: usage: dotnet DataGenNetCore.dll sendmessages (slow|fast|faster|insane)");
            Console.WriteLine("Press ESC to stop");

            var app = new Microsoft.Extensions.CommandLineUtils.CommandLineApplication();

            var sendmessages = app.Command("sendmessages", config => {
                config.OnExecute(() => {
                    config.ShowHelp();                 //show help for catapult
                    return(1);                         //return error since we didn't do anything
                });
                config.HelpOption("-? | -h | --help"); //show help on --help
            });

            sendmessages.Command("help", config => {
                config.Description = "get help!";
                config.OnExecute(() => {
                    sendmessages.ShowHelp("sendmessages");
                    return(1);
                });
            });
            sendmessages.Command("slow", config => {
                config.Description = "run message sending with 1 second thread sleep (slow)";
                config.HelpOption("-? | -h | --help");
                config.OnExecute(async() => {
                    Console.WriteLine("using slow mode (1 message every five seconds using thread.sleep)");
                    await sendMessages("slow");
                    return(0);
                });
            });
            sendmessages.Command("fast", config => {
                config.Description = "run message sending with no thread sleep (fast)";
                config.HelpOption("-? | -h | --help");
                config.OnExecute(async() => {
                    Console.WriteLine("using fast mode (single thread, no delay)");
                    await sendMessages("fast");
                    return(0);
                });
            });
            sendmessages.Command("faster", config => {
                config.Description = "run parallel for loop message sending (fastest)";
                config.HelpOption("-? | -h | --help");
                config.OnExecute(async() => {
                    Console.WriteLine("using faster mode (10 threads via parallel.for, no delay)");
                    await sendMessages("faster");
                    return(0);
                });
            });
            sendmessages.Command("insane", config => {
                config.Description = "run parallel for loop message sending (insane)";
                config.HelpOption("-? | -h | --help");
                config.OnExecute(async() => {
                    Console.WriteLine("using insane mode (100 threads via parallel.for, no delay)");
                    await sendMessages("insane");
                    return(0);
                });
            });

            //give people help with --help
            app.HelpOption("-? | -h | --help");
            try
            {
                var connectionStringBuilder = new EventHubsConnectionStringBuilder(secrets.EventHubConnectionString())
                {
                    EntityPath = secrets.EventHubPath()
                };

                hubClient = EventHubClient.CreateFromConnectionString(connectionStringBuilder.ToString());
                app.Execute(args);
            }
            catch (Exception e)
            {
                app.HelpOption("-? | -h | --help");
                Console.WriteLine("Error occurred: {0}", e.Message);
            }
            Environment.Exit(result);
        }