feat: more debug testing

This commit is contained in:
Neil Dorin
2023-11-23 23:11:36 -07:00
parent 3eaa86905f
commit d2877f2cec
13 changed files with 192 additions and 18 deletions

View File

@@ -375,8 +375,7 @@ namespace PepperDash.Essentials.Core.Bridges
{
try
{
if (Debug.Level >= 1)
Debug.Console(1, this, "EiscApiAdvanced change: {0} {1}={2}", args.Sig.Type, args.Sig.Number, args.Sig.StringValue);
Debug.Console(2, this, "EiscApiAdvanced change: {0} {1}={2}", args.Sig.Type, args.Sig.Number, args.Sig.StringValue);
var uo = args.Sig.UserObject;
if (uo == null) return;

View File

@@ -189,7 +189,7 @@ namespace PepperDash.Essentials.Core
CrestronConsole.ConsoleCommandResponse(
@"Type: '{0}'
CType: '{1}'
Description: {2}", type.Key, cType, description);
Description: {2}{3}", type.Key, cType, description, CrestronEnvironment.NewLine);
}
}

View File

@@ -26,7 +26,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.2">
<Aliases>Full</Aliases>
</PackageReference>
<PackageReference Include="PepperDashCore" Version="2.0.0-alpha-366" />
<PackageReference Include="PepperDashCore" Version="2.0.0-alpha-373" />
</ItemGroup>
<ItemGroup>
<None Include="Crestron\CrestronGenericBaseDevice.cs.orig" />

View File

@@ -154,8 +154,7 @@ namespace PepperDash.Essentials.Core.UI
private void Panel_SigChange(object currentDevice, Crestron.SimplSharpPro.SigEventArgs args)
{
if (Debug.Level == 2)
Debug.Console(2, this, "Sig change: {0} {1}={2}", args.Sig.Type, args.Sig.Number, args.Sig.StringValue);
Debug.Console(2, this, "Sig change: {0} {1}={2}", args.Sig.Type, args.Sig.Number, args.Sig.StringValue);
var uo = args.Sig.UserObject;
if (uo is Action<bool>)
(uo as Action<bool>)(args.Sig.BoolValue);

View File

@@ -149,7 +149,22 @@ namespace PepperDash.Essentials.Core.Web
{
Name = "DebugSession",
RouteHandler = new DebugSessionRequestHandler()
}
},
new HttpCwsRoute("doNotLoadConfigOnNextBoot")
{
Name = "DoNotLoadConfigOnNextBoot",
RouteHandler = new DoNotLoadConfigOnNextBootRequestHandler()
},
new HttpCwsRoute("restartProgram")
{
Name = "Restart Program",
RouteHandler = new RestartProgramRequestHandler()
},
new HttpCwsRoute("loadConfig")
{
Name = "Load Config",
RouteHandler = new RestartProgramRequestHandler()
}
};

View File

@@ -24,7 +24,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
/// <param name="context"></param>
protected override void HandleGet(HttpCwsContext context)
{
var appDebug = new AppDebug { Level = Debug.Level };
var appDebug = new AppDebug { MinimumLevel = Debug.WebsocketMinimumLogLevel };
var body = JsonConvert.SerializeObject(appDebug, Formatting.Indented);
@@ -62,9 +62,9 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
var appDebug = new AppDebug();
var requestBody = JsonConvert.DeserializeAnonymousType(data, appDebug);
Debug.SetDebugLevel(requestBody.Level);
Debug.SetWebSocketMinimumDebugLevel(requestBody.MinimumLevel);
appDebug.Level = Debug.Level;
appDebug.MinimumLevel = Debug.WebsocketMinimumLogLevel;
var responseBody = JsonConvert.SerializeObject(appDebug, Formatting.Indented);
context.Response.StatusCode = 200;
@@ -76,7 +76,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
public class AppDebug
{
[JsonProperty("level", NullValueHandling = NullValueHandling.Ignore)]
public int Level { get; set; }
[JsonProperty("minimumLevel", NullValueHandling = NullValueHandling.Ignore)]
public Serilog.Events.LogEventLevel MinimumLevel { get; set; }
}
}

View File

@@ -49,6 +49,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
port = new Random().Next(65435, 65535);
// Start the WS Server
Debug.WebsocketSink.StartServerAndSetPort(port);
Debug.SetWebSocketMinimumDebugLevel(Serilog.Events.LogEventLevel.Verbose);
}
var url = Debug.WebsocketSink.Url;
@@ -84,10 +85,11 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
{
Debug.WebsocketSink.StopServer();
context.Response.StatusDescription = "Ending Debug Session";
context.Response.StatusCode = 200;
context.Response.StatusDescription = "OK";
context.Response.End();
Debug.Console(0, "Websocket Debug Session Stopped");
}
}

View File

@@ -0,0 +1,84 @@
using Crestron.SimplSharp.WebScripting;
using Newtonsoft.Json;
using PepperDash.Core;
using PepperDash.Core.Web.RequestHandlers;
namespace PepperDash.Essentials.Core.Web.RequestHandlers
{
public class DoNotLoadConfigOnNextBootRequestHandler : WebApiBaseRequestHandler
{
/// <summary>
/// Constructor
/// </summary>
/// <remarks>
/// base(true) enables CORS support by default
/// </remarks>
public DoNotLoadConfigOnNextBootRequestHandler()
: base(true)
{
}
/// <summary>
/// Handles GET method requests
/// </summary>
/// <param name="context"></param>
protected override void HandleGet(HttpCwsContext context)
{
var data = new Data
{
DoNotLoadConfigOnNextBoot = Debug.DoNotLoadConfigOnNextBoot
};
var body = JsonConvert.SerializeObject(data, Formatting.Indented);
context.Response.StatusCode = 200;
context.Response.StatusDescription = "OK";
context.Response.Write(body, false);
context.Response.End();
}
/// <summary>
/// Handles POST method requests
/// </summary>
/// <param name="context"></param>
protected override void HandlePost(HttpCwsContext context)
{
if (context.Request.ContentLength < 0)
{
context.Response.StatusCode = 400;
context.Response.StatusDescription = "Bad Request";
context.Response.End();
return;
}
var data = EssentialsWebApiHelpers.GetRequestBody(context.Request);
if (string.IsNullOrEmpty(data))
{
context.Response.StatusCode = 400;
context.Response.StatusDescription = "Bad Request";
context.Response.End();
return;
}
var d = new Data();
var requestBody = JsonConvert.DeserializeAnonymousType(data, d);
Debug.SetDoNotLoadConfigOnNextBoot(requestBody.DoNotLoadConfigOnNextBoot);
var responseBody = JsonConvert.SerializeObject(d, Formatting.Indented);
context.Response.StatusCode = 200;
context.Response.StatusDescription = "OK";
context.Response.Write(responseBody, false);
context.Response.End();
}
}
public class Data
{
[JsonProperty("doNotLoadConfigOnNextBoot", NullValueHandling = NullValueHandling.Ignore)]
public bool DoNotLoadConfigOnNextBoot { get; set; }
}
}

View File

@@ -0,0 +1,37 @@
using Crestron.SimplSharp;
using Crestron.SimplSharp.WebScripting;
using Newtonsoft.Json;
using PepperDash.Core;
using PepperDash.Core.Web.RequestHandlers;
namespace PepperDash.Essentials.Core.Web.RequestHandlers
{
public class LoadConfigRequestHandler : WebApiBaseRequestHandler
{
/// <summary>
/// Constructor
/// </summary>
/// <remarks>
/// base(true) enables CORS support by default
/// </remarks>
public LoadConfigRequestHandler()
: base(true)
{
}
/// <summary>
/// Handles POST method requests
/// </summary>
/// <param name="context"></param>
protected override void HandlePost(HttpCwsContext context)
{
var message = "";
//Global.ControlSystem.GoWithLoad();
context.Response.StatusCode = 200;
context.Response.StatusDescription = "OK";
context.Response.Write(message, false);
context.Response.End();
}
}
}

View File

@@ -0,0 +1,38 @@
using Crestron.SimplSharp;
using Crestron.SimplSharp.WebScripting;
using Newtonsoft.Json;
using PepperDash.Core;
using PepperDash.Core.Web.RequestHandlers;
namespace PepperDash.Essentials.Core.Web.RequestHandlers
{
public class RestartProgramRequestHandler : WebApiBaseRequestHandler
{
/// <summary>
/// Constructor
/// </summary>
/// <remarks>
/// base(true) enables CORS support by default
/// </remarks>
public RestartProgramRequestHandler()
: base(true)
{
}
/// <summary>
/// Handles POST method requests
/// </summary>
/// <param name="context"></param>
protected override void HandlePost(HttpCwsContext context)
{
var message = "";
if(CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance)
CrestronConsole.SendControlSystemCommand($"progres -p:{InitialParametersClass.ApplicationNumber}", ref message);
context.Response.StatusCode = 200;
context.Response.StatusDescription = "OK";
context.Response.Write(message, false);
context.Response.End();
}
}
}