mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-15 20:54:55 +00:00
feat: remove context file for storing values
This commit is contained in:
@@ -18,15 +18,16 @@ using System.Text.RegularExpressions;
|
|||||||
|
|
||||||
namespace PepperDash.Core;
|
namespace PepperDash.Core;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains debug commands for use in various situations
|
/// Contains debug commands for use in various situations
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class Debug
|
public static class Debug
|
||||||
{
|
{
|
||||||
private static readonly string LevelStoreKey = "ConsoleDebugLevel";
|
private static readonly string LevelStoreKey = "ConsoleDebugLevel";
|
||||||
private static readonly string WebSocketLevelStoreKey = "WebsocketDebugLevel";
|
private static readonly string WebSocketLevelStoreKey = "WebsocketDebugLevel";
|
||||||
private static readonly string ErrorLogLevelStoreKey = "ErrorLogDebugLevel";
|
private static readonly string ErrorLogLevelStoreKey = "ErrorLogDebugLevel";
|
||||||
private static readonly string FileLevelStoreKey = "FileDebugLevel";
|
private static readonly string FileLevelStoreKey = "FileDebugLevel";
|
||||||
|
private static readonly string DoNotLoadOnNextBootKey = "DoNotLoadOnNextBoot";
|
||||||
|
|
||||||
private static readonly Dictionary<uint, LogEventLevel> _logLevels = new Dictionary<uint, LogEventLevel>()
|
private static readonly Dictionary<uint, LogEventLevel> _logLevels = new Dictionary<uint, LogEventLevel>()
|
||||||
{
|
{
|
||||||
@@ -117,6 +118,8 @@ namespace PepperDash.Core;
|
|||||||
public static LoggerConfiguration LoggerConfiguration => _loggerConfiguration;
|
public static LoggerConfiguration LoggerConfiguration => _loggerConfiguration;
|
||||||
|
|
||||||
static Debug()
|
static Debug()
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
CrestronDataStoreStatic.InitCrestronDataStore();
|
CrestronDataStoreStatic.InitCrestronDataStore();
|
||||||
|
|
||||||
@@ -162,21 +165,6 @@ namespace PepperDash.Core;
|
|||||||
levelSwitch: _fileLevelSwitch
|
levelSwitch: _fileLevelSwitch
|
||||||
);
|
);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (InitialParametersClass.NumberOfRemovableDrives > 0)
|
|
||||||
{
|
|
||||||
CrestronConsole.PrintLine("{0} RM Drive(s) Present. Initializing CrestronLogger", InitialParametersClass.NumberOfRemovableDrives);
|
|
||||||
_defaultLoggerConfiguration.WriteTo.Sink(new DebugCrestronLoggerSink());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
CrestronConsole.PrintLine("No RM Drive(s) Present. Not using Crestron Logger");
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
CrestronConsole.PrintLine("Initializing of CrestronLogger failed: {0}", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Instantiate the root logger
|
// Instantiate the root logger
|
||||||
_loggerConfiguration = _defaultLoggerConfiguration;
|
_loggerConfiguration = _defaultLoggerConfiguration;
|
||||||
|
|
||||||
@@ -193,7 +181,7 @@ namespace PepperDash.Core;
|
|||||||
|
|
||||||
CrestronConsole.PrintLine(msg);
|
CrestronConsole.PrintLine(msg);
|
||||||
|
|
||||||
LogMessage(LogEventLevel.Information,msg);
|
LogMessage(LogEventLevel.Information, msg);
|
||||||
|
|
||||||
IncludedExcludedKeys = new Dictionary<string, object>();
|
IncludedExcludedKeys = new Dictionary<string, object>();
|
||||||
|
|
||||||
@@ -218,13 +206,9 @@ namespace PepperDash.Core;
|
|||||||
|
|
||||||
CrestronEnvironment.ProgramStatusEventHandler += CrestronEnvironment_ProgramStatusEventHandler;
|
CrestronEnvironment.ProgramStatusEventHandler += CrestronEnvironment_ProgramStatusEventHandler;
|
||||||
|
|
||||||
LoadMemory();
|
DoNotLoadConfigOnNextBoot = GetDoNotLoadOnNextBoot();
|
||||||
|
|
||||||
var context = _contexts.GetOrCreateItem("DEFAULT");
|
if (DoNotLoadConfigOnNextBoot)
|
||||||
Level = context.Level;
|
|
||||||
DoNotLoadConfigOnNextBoot = context.DoNotLoadOnNextBoot;
|
|
||||||
|
|
||||||
if(DoNotLoadConfigOnNextBoot)
|
|
||||||
CrestronConsole.PrintLine(string.Format("Program {0} will not load config after next boot. Use console command go:{0} to load the config manually", InitialParametersClass.ApplicationNumber));
|
CrestronConsole.PrintLine(string.Format("Program {0} will not load config after next boot. Use console command go:{0} to load the config manually", InitialParametersClass.ApplicationNumber));
|
||||||
|
|
||||||
_consoleLoggingLevelSwitch.MinimumLevelChanged += (sender, args) =>
|
_consoleLoggingLevelSwitch.MinimumLevelChanged += (sender, args) =>
|
||||||
@@ -232,6 +216,24 @@ namespace PepperDash.Core;
|
|||||||
LogMessage(LogEventLevel.Information, "Console debug level set to {minimumLevel}", _consoleLoggingLevelSwitch.MinimumLevel);
|
LogMessage(LogEventLevel.Information, "Console debug level set to {minimumLevel}", _consoleLoggingLevelSwitch.MinimumLevel);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LogError(ex, "Exception in Debug static constructor: {message}", ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool GetDoNotLoadOnNextBoot()
|
||||||
|
{
|
||||||
|
var err = CrestronDataStoreStatic.GetLocalBoolValue(DoNotLoadOnNextBootKey, out var doNotLoad);
|
||||||
|
|
||||||
|
if (err != CrestronDataStore.CDS_ERROR.CDS_SUCCESS)
|
||||||
|
{
|
||||||
|
LogError("Error retrieving DoNotLoadOnNextBoot value: {err}", err);
|
||||||
|
doNotLoad = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return doNotLoad;
|
||||||
|
}
|
||||||
|
|
||||||
public static void UpdateLoggerConfiguration(LoggerConfiguration config)
|
public static void UpdateLoggerConfiguration(LoggerConfiguration config)
|
||||||
{
|
{
|
||||||
@@ -571,11 +573,13 @@ namespace PepperDash.Core;
|
|||||||
public static void SetDoNotLoadConfigOnNextBoot(bool state)
|
public static void SetDoNotLoadConfigOnNextBoot(bool state)
|
||||||
{
|
{
|
||||||
DoNotLoadConfigOnNextBoot = state;
|
DoNotLoadConfigOnNextBoot = state;
|
||||||
_contexts.GetOrCreateItem("DEFAULT").DoNotLoadOnNextBoot = state;
|
|
||||||
SaveMemoryOnTimeout();
|
|
||||||
|
|
||||||
CrestronConsole.ConsoleCommandResponse("[Application {0}], Do Not Load Config on Next Boot set to {1}",
|
var err = CrestronDataStoreStatic.SetLocalBoolValue(DoNotLoadOnNextBootKey, state);
|
||||||
InitialParametersClass.ApplicationNumber, DoNotLoadConfigOnNextBoot);
|
|
||||||
|
if (err != CrestronDataStore.CDS_ERROR.CDS_SUCCESS)
|
||||||
|
LogError("Error saving console debug level setting: {err}", err);
|
||||||
|
|
||||||
|
LogInformation("Do Not Load Config on Next Boot set to {state}", DoNotLoadConfigOnNextBoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -15,15 +15,15 @@ using X509Certificate2 = System.Security.Cryptography.X509Certificates.X509Certi
|
|||||||
|
|
||||||
namespace PepperDash.Core;
|
namespace PepperDash.Core;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides a WebSocket-based logging sink for debugging purposes, allowing log events to be broadcast to connected
|
/// Provides a WebSocket-based logging sink for debugging purposes, allowing log events to be broadcast to connected
|
||||||
/// WebSocket clients.
|
/// WebSocket clients.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>This class implements the <see cref="ILogEventSink"/> interface and is designed to send
|
/// <remarks>This class implements the <see cref="ILogEventSink"/> interface and is designed to send
|
||||||
/// formatted log events to WebSocket clients connected to a secure WebSocket server. The server is hosted locally
|
/// formatted log events to WebSocket clients connected to a secure WebSocket server. The server is hosted locally
|
||||||
/// and uses a self-signed certificate for SSL/TLS encryption.</remarks>
|
/// and uses a self-signed certificate for SSL/TLS encryption.</remarks>
|
||||||
public class DebugWebsocketSink : ILogEventSink, IKeyed
|
public class DebugWebsocketSink : ILogEventSink, IKeyed
|
||||||
{
|
{
|
||||||
private HttpServer _httpsServer;
|
private HttpServer _httpsServer;
|
||||||
|
|
||||||
private readonly string _path = "/debug/join/";
|
private readonly string _path = "/debug/join/";
|
||||||
@@ -107,8 +107,10 @@ namespace PepperDash.Core;
|
|||||||
|
|
||||||
//Crestron fails to let us do this...perhaps it should be done through their Dll's but haven't tested
|
//Crestron fails to let us do this...perhaps it should be done through their Dll's but haven't tested
|
||||||
|
|
||||||
|
var separator = Path.DirectorySeparatorChar;
|
||||||
|
|
||||||
utility.CertificatePassword = _certificatePassword;
|
utility.CertificatePassword = _certificatePassword;
|
||||||
utility.WriteCertificate(certificate, @"\user\", _certificateName);
|
utility.WriteCertificate(certificate, @$"{separator}user{separator}", _certificateName);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -228,15 +230,15 @@ namespace PepperDash.Core;
|
|||||||
|
|
||||||
_httpsServer = null;
|
_httpsServer = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Configures the logger to write log events to a debug WebSocket sink.
|
/// Configures the logger to write log events to a debug WebSocket sink.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>This extension method allows you to direct log events to a WebSocket sink for debugging
|
/// <remarks>This extension method allows you to direct log events to a WebSocket sink for debugging
|
||||||
/// purposes.</remarks>
|
/// purposes.</remarks>
|
||||||
public static class DebugWebsocketSinkExtensions
|
public static class DebugWebsocketSinkExtensions
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Configures a logger to write log events to a debug WebSocket sink.
|
/// Configures a logger to write log events to a debug WebSocket sink.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -251,17 +253,17 @@ namespace PepperDash.Core;
|
|||||||
{
|
{
|
||||||
return loggerConfiguration.Sink(new DebugWebsocketSink(formatProvider));
|
return loggerConfiguration.Sink(new DebugWebsocketSink(formatProvider));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a WebSocket client for debugging purposes, providing connection lifecycle management and message
|
/// Represents a WebSocket client for debugging purposes, providing connection lifecycle management and message
|
||||||
/// handling functionality.
|
/// handling functionality.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>The <see cref="DebugClient"/> class extends <see cref="WebSocketBehavior"/> to handle
|
/// <remarks>The <see cref="DebugClient"/> class extends <see cref="WebSocketBehavior"/> to handle
|
||||||
/// WebSocket connections, including events for opening, closing, receiving messages, and errors. It tracks the
|
/// WebSocket connections, including events for opening, closing, receiving messages, and errors. It tracks the
|
||||||
/// duration of the connection and logs relevant events for debugging.</remarks>
|
/// duration of the connection and logs relevant events for debugging.</remarks>
|
||||||
public class DebugClient : WebSocketBehavior
|
public class DebugClient : WebSocketBehavior
|
||||||
{
|
{
|
||||||
private DateTime _connectionTime;
|
private DateTime _connectionTime;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user