예제 #1
0
        public IHttpContext KeyboardStart(IHttpContext ctx)
        {
            Program.KeyboardMapperInstance.Start();

            RestServer.SetCORSHeaders(ctx);
            RestServer.CloseResponse(ctx);

            return(ctx);
        }
예제 #2
0
        public IHttpContext ControllerStart(IHttpContext ctx)
        {
            Program.ControllerManagerInstance.Start();

            RestServer.SetCORSHeaders(ctx);
            RestServer.CloseResponse(ctx);

            return(ctx);
        }
예제 #3
0
        public IHttpContext KeyboardGetMapping(IHttpContext ctx)
        {
            RestServer.SetCORSHeaders(ctx);
            RestServer.SendJsonResponse(ctx, new Dictionary <string, object> {
                { "currentMapping", Program.KeyboardMapperInstance.CurrentMappingName },
                { "mappings", Program.KeyboardMapperInstance.GetAllMappings() },
            });

            return(ctx);
        }
예제 #4
0
        public IHttpContext Status(IHttpContext ctx)
        {
            RestServer.SetCORSHeaders(ctx);
            RestServer.SendJsonResponse(ctx, new Dictionary <string, object> {
                { "isControllerRunning", Program.ControllerManagerInstance.IsRunning },
                { "isKeyboardRunning", Program.KeyboardMapperInstance.IsRunning },
                { "hostname", System.Net.Dns.GetHostName() },
            });

            return(ctx);
        }
예제 #5
0
        public IHttpContext Index(IHttpContext ctx)
        {
            string prefix = ctx.Server.PublicFolder.Prefix;

            if (string.IsNullOrEmpty(prefix))
            {
                prefix = "/";
            }
            ctx.Response.Redirect($"{prefix}{ctx.Server.PublicFolder.IndexFileName}");
            RestServer.CloseResponse(ctx);
            return(ctx);
        }
예제 #6
0
        public IHttpContext KeyboardMappingOptions(IHttpContext ctx)
        {
            var validMethods = new HttpMethod[] {
                HttpMethod.GET,
                HttpMethod.POST,
                HttpMethod.DELETE,
                HttpMethod.OPTIONS,
            };

            ctx.Response.Headers["Access-Control-Allow-Methods"] = string.Join(", ", validMethods.Select(x => x.ToString()));
            RestServer.SetCORSHeaders(ctx);
            RestServer.CloseResponse(ctx);
            return(ctx);
        }
예제 #7
0
        public IHttpContext KeyboardSetCurrentName(IHttpContext ctx)
        {
            try {
                Program.KeyboardMapperInstance.SetCurrentMappingName(ctx.Request.Payload);
                RestServer.SetCORSHeaders(ctx);
                RestServer.CloseResponse(ctx);
            } catch (System.Exception e) {
                ctx.Response.StatusCode = HttpStatusCode.InternalServerError;
                RestServer.SendJsonResponse(ctx, new Dictionary <string, object> {
                    { "error", e.Message },
                });
            }

            return(ctx);
        }
예제 #8
0
        public IHttpContext KeyboardRenameMapping(IHttpContext ctx)
        {
            try {
                var json = RestServer.ParseJson(ctx.Request.Payload);
                Program.KeyboardMapperInstance.RenameMapping((string)json["name"], (string)json["newName"]);
                RestServer.SetCORSHeaders(ctx);
                RestServer.CloseResponse(ctx);
            } catch (System.Exception e) {
                ctx.Response.StatusCode = HttpStatusCode.InternalServerError;
                RestServer.SendJsonResponse(ctx, new Dictionary <string, object> {
                    { "error", e.Message },
                });
            }

            return(ctx);
        }