Example #1
0
        /// <summary>
        /// Handles HTTP request.
        /// </summary>
        protected override async Task HandleRequest(SimpleHttpContext context)
        {
            string json;

            switch (context.Command)
            {
            case "read":
                json = Read(context);
                await context.WriteJson(json);

                break;

            case "write":
                json = Write(context);
                await context.WriteJson(json);

                break;

            case "readwrite":
                json = ReadWrite(context);
                await context.WriteJson(json);

                break;

            default:
                string message = "Command not found";
                await context.WriteError(message, 404);

                throw new Exception(message);
            }
        }
Example #2
0
        /// <summary>
        /// Handles HTTP request.
        /// </summary>
        protected override async Task HandleRequest(SimpleHttpContext context)
        {
            string json, html, text;

            switch (context.Command)
            {
            case "ping":
                json = Ping(context);
                await context.WriteJson(json);

                break;

            case "getstats":
                json = GetStats(context);
                await context.WriteJson(json);

                break;

            case "getstatshtml":
                json = GetStats(context);
                html = StatsToHtml.GetStatsHtml(json);
                await context.WriteHtml(html);

                break;

            case "getlogs":
                text = GetLogs(context);
                await context.WriteText(text);

                break;

            case "pstree":
                text = PsTree(context);
                context.Response.ContentType = "text/plain";
                await context.Response.WriteAsync(text);

                break;

            case "ps":
                text = Ps(context);
                context.Response.ContentType = "text/plain";
                await context.Response.WriteAsync(text);

                break;

            default:
                string message = "Command not found";
                await context.WriteError(message, 404);

                throw new Exception(message);
            }
        }