Example #1
0
        public void Run()
        {
            HorseMvc mvc = new HorseMvc();

            HomeController cont = new HomeController();

            Assert.NotNull(cont);

            mvc.Init();
            Assembly asm = Assembly.GetExecutingAssembly();

            mvc.CreateRoutes(asm);
            mvc.Use();

            HorseServer server = new HorseServer(ServerOptions.CreateDefault());

            server.UseMvc(mvc, HttpOptions.CreateDefault());
            server.Start(47442);
            System.Threading.Thread.Sleep(1000);

            HttpClient          client   = new HttpClient();
            HttpResponseMessage response = client.GetAsync("http://127.0.0.1:47442/home/get").Result;

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
Example #2
0
 /// <summary>
 /// Uses WebSocket Protocol and accepts HTTP connections which comes with "Upgrade: websocket" header data
 /// </summary>
 public static ITwinoServer UseWebSockets(this ITwinoServer server,
                                          WebSocketReadyHandler readyAction,
                                          WebSocketMessageRecievedHandler messageAction)
 {
     return(UseWebSockets(server,
                          new MethodWebSocketConnectionHandler(null, readyAction, messageAction),
                          HttpOptions.CreateDefault()));
 }
Example #3
0
 /// <summary>
 /// Uses WebSocket Protocol and accepts HTTP connections which comes with "Upgrade: websocket" header data
 /// </summary>
 public static IHorseServer UseWebSockets(this IHorseServer server,
                                          WebSocketConnectedHandler connectedAction,
                                          WebSocketMessageRecievedHandler messageAction)
 {
     return(UseWebSockets(server,
                          new MethodWebSocketConnectionHandler(connectedAction, null, messageAction),
                          HttpOptions.CreateDefault()));
 }
Example #4
0
        static void Main(string[] args)
        {
            HorseMvc mvc = new HorseMvc();
            HorseServer
                server = new HorseServer();

            mvc.Init();
            server.UseMvc(mvc, HttpOptions.CreateDefault());
            server.Run();
        }
Example #5
0
        static void Main(string[] args)
        {
            TwinoMvc    mvc    = new TwinoMvc();
            TwinoServer server = new TwinoServer();

            mvc.Init();
            server.UseMvc(mvc, HttpOptions.CreateDefault());
            server.Start();
            server.BlockWhileRunning();
        }
Example #6
0
        static void Main(string[] args)
        {
            HorseMvc mvc = new HorseMvc();

            mvc.IsDevelopment = false;
            mvc.Init(services =>
            {
                services.AddScoped <IScopedService, ScopedService>();
                services.AddTransient <IFirstService, FirstService>();
                services.AddTransient <ISecondService, SecondService>();

                services.AddJwt(mvc, options =>
                {
                    options.Key              = "Very_very_secret_key";
                    options.Issuer           = "localhost";
                    options.Audience         = "localhost";
                    options.Lifetime         = TimeSpan.FromHours(1);
                    options.ValidateAudience = false;
                    options.ValidateIssuer   = false;
                    options.ValidateLifetime = true;
                });

                mvc.Policies.Add(Policy.RequireRole("Admin", "Admin"));
                mvc.Policies.Add(Policy.RequireClaims("IT", "Database", "Cloud", "Source"));
                mvc.Policies.Add(Policy.Custom("Custom", (d, c) => true));

                mvc.StatusCodeResults.Add(HttpStatusCode.Unauthorized, new JsonResult(new { Message = "Access denied" }));

                mvc.ErrorHandler = new MvcErrorHandler();
            });

            CorsMiddleware cors = new CorsMiddleware();

            cors.AllowAll();

            mvc.Use(app =>
            {
                app.UseActionRoute("/test-action", request => new StringResult("Hello, Test Action!"));

                app.UseMiddleware(cors);
                app.UseMiddleware <TMid>();
                app.UseFiles("/download", "/home/mehmet/files");
            });

            HorseServer server = new HorseServer();
            var         opt    = HttpOptions.CreateDefault();

            opt.HttpConnectionTimeMax = 0;
            server.UseMvc(mvc, opt);
            server.Run(4410);
        }
Example #7
0
        static void Main(string[] args)
        {
            using TwinoMvc mvc = new TwinoMvc();

            mvc.IsDevelopment = false;
            mvc.Init(twino =>
            {
                twino.Services.AddScoped <IScopedService, ScopedService>();
                twino.Services.AddTransient <IFirstService, FirstService>();
                twino.Services.AddTransient <ISecondService, SecondService>();

                twino.AddJwt(options =>
                {
                    options.Key              = "Very_very_secret_key";
                    options.Issuer           = "localhost";
                    options.Audience         = "localhost";
                    options.Lifetime         = TimeSpan.FromHours(1);
                    options.ValidateAudience = false;
                    options.ValidateIssuer   = false;
                    options.ValidateLifetime = true;
                });

                twino.Policies.Add(Policy.RequireRole("Admin", "Admin"));
                twino.Policies.Add(Policy.RequireClaims("IT", "Database", "Cloud", "Source"));
                twino.Policies.Add(Policy.Custom("Custom", (d, c) => true));
                twino.Services.AddHttpClient();

                twino.StatusCodeResults.Add(HttpStatusCode.Unauthorized, new JsonResult(new { Message = "Access denied" }));
            });

            CorsMiddleware cors = new CorsMiddleware();

            cors.AllowAll();

            mvc.Use(app =>
            {
                app.UseMiddleware(cors);
                app.UseMiddleware <TMid>();
                app.UseFiles("/download", "/home/mehmet/files");
            });

            TwinoServer server = new TwinoServer();
            var         opt    = HttpOptions.CreateDefault();

            opt.HttpConnectionTimeMax = 0;
            server.UseMvc(mvc, opt);
            server.Start(441);
            server.BlockWhileRunning();
        }
Example #8
0
        static void Main(string[] args)
        {
            HorseServer server = new HorseServer(ServerOptions.CreateDefault());

            server.UseHttp((request, response) =>
            {
                if (request.Path.Equals("/plaintext", StringComparison.InvariantCultureIgnoreCase))
                {
                    response.SetToText();
                    return(response.WriteAsync("Hello, World!"));
                }

                response.StatusCode = HttpStatusCode.NotFound;
                return(Task.CompletedTask);
            }, HttpOptions.CreateDefault());

            server.Run(5000);
        }
Example #9
0
        static void Main(string[] args)
        {
            HorseServer server = new HorseServer(ServerOptions.CreateDefault());

            server.UseHttp(async(request, response) =>
            {
                if (request.Path.Equals("/json", StringComparison.InvariantCultureIgnoreCase))
                {
                    response.SetToJson(new { message = "Hello, World!" });
                }
                else
                {
                    response.StatusCode = HttpStatusCode.NotFound;
                }

                await Task.CompletedTask;
            }, HttpOptions.CreateDefault());

            server.Run();
        }
Example #10
0
        static void Main(string[] args)
        {
            TwinoServer server = new TwinoServer(ServerOptions.CreateDefault());

            server.UseHttp(async(request, response) =>
            {
                if (request.Path.Equals("/plaintext", StringComparison.InvariantCultureIgnoreCase))
                {
                    response.SetToText();
                    response.Write("Hello, World!");
                }
                else
                {
                    response.StatusCode = HttpStatusCode.NotFound;
                }

                await Task.CompletedTask;
            }, HttpOptions.CreateDefault());

            server.Start(5000);
            server.BlockWhileRunning();
        }
Example #11
0
 /// <summary>
 /// Uses WebSocket Protocol and accepts HTTP connections which comes with "Upgrade: websocket" header data
 /// </summary>
 public static ITwinoServer UseWebSockets(this ITwinoServer server,
                                          IProtocolConnectionHandler <WsServerSocket,
                                                                      WebSocketMessage> handler)
 {
     return(UseWebSockets(server, handler, HttpOptions.CreateDefault()));
 }
 /// <summary>
 /// Uses websocket protocol
 /// </summary>
 public static IHorseServer AddWebSockets(this IHorseServer server, Action <WebSocketServerBuilder> cfg)
 {
     return(AddWebSockets(server, HttpOptions.CreateDefault(), cfg));
 }
Example #13
0
 /// <summary>
 /// Uses HTTP Protocol and accepts HTTP connections with Twino MVC Architecture
 /// </summary>
 public static ITwinoServer UseMvc(this ITwinoServer server, TwinoMvc mvc)
 {
     return(UseMvc(server, mvc, HttpOptions.CreateDefault()));
 }
Example #14
0
 /// <summary>
 /// Uses HTTP Protocol and accepts HTTP connections with Horse MVC Architecture
 /// </summary>
 public static IHorseServer UseMvc(this IHorseServer server, HorseMvc mvc)
 {
     return(UseMvc(server, mvc, HttpOptions.CreateDefault()));
 }