Exemplo n.º 1
0
        static void Main(string[] args)
        {
            ICowsay cowsay = new Cowsay();

            if (args.Length == 0)
            {
                //Console.WriteLine("Print the error message.");
                Console.WriteLine(cowsay.GetVersion());
            }

            if (args.Length == 1)
            {
                var option = args.First();
                if (option == "--version" || option == "-v")
                {
                    Console.WriteLine(cowsay.GetVersion());
                }

                if (option == "--help" || option == "-h")
                {
                    Console.WriteLine("Print the help.");
                }
            }

            //Console.WriteLine(cowsay.SayMessage("Hi"));
            Console.ReadKey();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            ICowsay cowsay = new Cowsay();

            CommandLineApplication commandLineApplication =
                new CommandLineApplication(throwOnUnexpectedArg: false);
            CommandArgument text = null;

            commandLineApplication.Command("say",
                                           (target) =>
                                           text = target.Argument(
                                               "say",
                                               "Prints the given text to the console as if a cow had said it."));
            commandLineApplication.VersionOption("-v | --version", () => cowsay.GetVersion());
            commandLineApplication.HelpOption("-? | -h | --help");
            commandLineApplication.OnExecute(() =>
            {
                return(0);
            });
            commandLineApplication.Execute(args);
        }
Exemplo n.º 3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseForwardedHeaders(new ForwardedHeadersOptions
            {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            });

            var defaultRoute = new RouteHandler(context => {
                return(context.Response.WriteAsync("Hello..."));
            });

            var routeBuilder = new RouteBuilder(app, defaultRoute);

            routeBuilder.MapGet("cowsay/{message}", context => {
                var message = (string)context.GetRouteValue("message");
                var dead    = context.Request.Query["dead"] == "1";
                var output  = new Cowsay().Speak(message, dead);
                return(context.Response.WriteAsync(string.Format(@"
                <!DOCTYPE html>
                    <html>
                        <head>
                            <title>Cowsay Dotnet</title>
                        </head>
                        <body style='background-color:azure'>
                            <pre>{0}</pre>
                        </body>
                    </html>", output)));
            });

            app.UseRouter(routeBuilder.Build());
        }