feat: adds more api handlers to load config and get/set min log level

This commit is contained in:
Neil Dorin
2023-11-24 18:58:11 -07:00
parent d2877f2cec
commit a2c628145d
8 changed files with 27 additions and 10 deletions

View File

@@ -163,7 +163,7 @@ namespace PepperDash.Essentials.Core.Web
new HttpCwsRoute("loadConfig")
{
Name = "Load Config",
RouteHandler = new RestartProgramRequestHandler()
RouteHandler = new LoadConfigRequestHandler()
}
};

View File

@@ -2,6 +2,8 @@
using Newtonsoft.Json;
using PepperDash.Core;
using PepperDash.Core.Web.RequestHandlers;
using System;
using Serilog.Events;
namespace PepperDash.Essentials.Core.Web.RequestHandlers
{
@@ -26,7 +28,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
{
var appDebug = new AppDebug { MinimumLevel = Debug.WebsocketMinimumLogLevel };
var body = JsonConvert.SerializeObject(appDebug, Formatting.Indented);
var body = JsonConvert.SerializeObject((appDebug, Formatting.Indented, new JsonSerializerSettings( ));
context.Response.StatusCode = 200;
context.Response.StatusDescription = "OK";
@@ -60,7 +62,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
}
var appDebug = new AppDebug();
var requestBody = JsonConvert.DeserializeAnonymousType(data, appDebug);
var requestBody = JsonConvert.DeserializeObject<AppDebug>(data);
Debug.SetWebSocketMinimumDebugLevel(requestBody.MinimumLevel);
@@ -77,6 +79,6 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
public class AppDebug
{
[JsonProperty("minimumLevel", NullValueHandling = NullValueHandling.Ignore)]
public Serilog.Events.LogEventLevel MinimumLevel { get; set; }
public LogEventLevel MinimumLevel { get; set; }
}
}

View File

@@ -26,8 +26,10 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
protected override void HandlePost(HttpCwsContext context)
{
var message = "";
//Global.ControlSystem.GoWithLoad();
var cs = Global.ControlSystem as ILoadConfig;
if(cs != null)
cs.GoWithLoad();
context.Response.StatusCode = 200;
context.Response.StatusDescription = "OK";
context.Response.Write(message, false);