Ejemplo n.º 1
0
        static int Main(string[] args)
        {
            var rootCommand = new RootCommand
                              (
                "Sends HTTP `HEAD` requests to the specified URL."
                              )
            {
                Name = "./RequestsGalore",
            };

            rootCommand.AddOption(UrlOption);
            rootCommand.AddOption(RequestsOption);
            rootCommand.AddOption(ConcurrencyLevelOption);

            rootCommand.Handler = CommandHandler.Create <string, int?, int?>((url, numberOfRequests, numberOfConcurrentRequestsPerRequest) =>
            {
                // TODO: The following is a hack to make validation work as the
                // CommandLine API is not fully fleshed out yet.
                OptionValidation.ValidateOptions(url, numberOfRequests, numberOfConcurrentRequestsPerRequest);

                var urlRequestService = new UrlRequestService(Client);
                var urlController     = new UrlController(urlRequestService);

                var urlRequestResponses = urlController.GetUrlRequestResponses(url, numberOfRequests.Value, numberOfConcurrentRequestsPerRequest.Value);

                for (int i = 0; i < urlRequestResponses.Count; i++)
                {
                    var response = urlRequestResponses[i];
                    Console.WriteLine($"Request {i} -> [{response.StatusCode}]");
                }
            });

            return(rootCommand.InvokeAsync(args).Result);
        }