mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-04-13 12:37:07 +00:00
fix: use correct line endings for verbatim strings
This commit is contained in:
parent
5d90fafbd7
commit
3feab2593d
4 changed files with 142 additions and 150 deletions
|
|
@ -1,8 +1,7 @@
|
||||||
extern alias NewtonsoftJson;
|
extern alias NewtonsoftJson;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
|
|
@ -101,17 +100,19 @@ public static class Debug
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Version for the currently loaded PepperDashCore dll
|
/// Version for the currently loaded PepperDashCore dll
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string PepperDashCoreVersion { get; private set; }
|
public static string PepperDashCoreVersion { get; private set; }
|
||||||
|
|
||||||
private static CTimer _saveTimer;
|
private static CTimer _saveTimer;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// When true, the IncludedExcludedKeys dict will contain keys to include.
|
/// When true, the IncludedExcludedKeys dict will contain keys to include.
|
||||||
/// When false (default), IncludedExcludedKeys will contain keys to exclude.
|
/// When false (default), IncludedExcludedKeys will contain keys to exclude.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static bool _excludeAllMode;
|
private static bool _excludeAllMode;
|
||||||
|
|
||||||
private static readonly Dictionary<string, object> IncludedExcludedKeys;
|
//static bool ExcludeNoKeyMessages;
|
||||||
|
|
||||||
|
private static readonly Dictionary<string, object> IncludedExcludedKeys;
|
||||||
|
|
||||||
private static readonly LoggerConfiguration _defaultLoggerConfiguration;
|
private static readonly LoggerConfiguration _defaultLoggerConfiguration;
|
||||||
|
|
||||||
|
|
@ -255,7 +256,7 @@ public static class Debug
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result = CrestronDataStoreStatic.GetLocalIntValue(levelStoreKey, out int logLevel);
|
var result = CrestronDataStoreStatic.GetLocalIntValue(levelStoreKey, out int logLevel);
|
||||||
|
|
||||||
if (result != CrestronDataStore.CDS_ERROR.CDS_SUCCESS)
|
if (result != CrestronDataStore.CDS_ERROR.CDS_SUCCESS)
|
||||||
{
|
{
|
||||||
|
|
@ -263,14 +264,15 @@ public static class Debug
|
||||||
return LogEventLevel.Information;
|
return LogEventLevel.Information;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(logLevel < 0 || logLevel > 5)
|
if (logLevel < 0 || logLevel > 5)
|
||||||
{
|
{
|
||||||
CrestronConsole.PrintLine($"Stored Log level not valid for {levelStoreKey}: {logLevel}. Setting level to {LogEventLevel.Information}");
|
CrestronConsole.PrintLine($"Stored Log level not valid for {levelStoreKey}: {logLevel}. Setting level to {LogEventLevel.Information}");
|
||||||
return LogEventLevel.Information;
|
return LogEventLevel.Information;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (LogEventLevel)logLevel;
|
return (LogEventLevel)logLevel;
|
||||||
} catch (Exception ex)
|
}
|
||||||
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
CrestronConsole.PrintLine($"Exception retrieving log level for {levelStoreKey}: {ex.Message}");
|
CrestronConsole.PrintLine($"Exception retrieving log level for {levelStoreKey}: {ex.Message}");
|
||||||
return LogEventLevel.Information;
|
return LogEventLevel.Information;
|
||||||
|
|
@ -282,7 +284,7 @@ public static class Debug
|
||||||
var assembly = Assembly.GetExecutingAssembly();
|
var assembly = Assembly.GetExecutingAssembly();
|
||||||
var ver =
|
var ver =
|
||||||
assembly
|
assembly
|
||||||
.GetCustomAttributes(typeof (AssemblyInformationalVersionAttribute), false);
|
.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false);
|
||||||
|
|
||||||
if (ver != null && ver.Length > 0)
|
if (ver != null && ver.Length > 0)
|
||||||
{
|
{
|
||||||
|
|
@ -330,13 +332,13 @@ public static class Debug
|
||||||
if (levelString.Trim() == "?")
|
if (levelString.Trim() == "?")
|
||||||
{
|
{
|
||||||
CrestronConsole.ConsoleCommandResponse(
|
CrestronConsole.ConsoleCommandResponse(
|
||||||
$@"Used to set the minimum level of debug messages to be printed to the console:
|
"Used to set the minimum level of debug messages to be printed to the console:\r\n" +
|
||||||
{_logLevels[0]} = 0
|
$"{_logLevels[0]} = 0\r\n" +
|
||||||
{_logLevels[1]} = 1
|
$"{_logLevels[1]} = 1\r\n" +
|
||||||
{_logLevels[2]} = 2
|
$"{_logLevels[2]} = 2\r\n" +
|
||||||
{_logLevels[3]} = 3
|
$"{_logLevels[3]} = 3\r\n" +
|
||||||
{_logLevels[4]} = 4
|
$"{_logLevels[4]} = 4\r\n" +
|
||||||
{_logLevels[5]} = 5");
|
$"{_logLevels[5]} = 5");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -346,25 +348,25 @@ public static class Debug
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(int.TryParse(levelString, out var levelInt))
|
if (int.TryParse(levelString, out var levelInt))
|
||||||
{
|
{
|
||||||
if(levelInt < 0 || levelInt > 5)
|
if (levelInt < 0 || levelInt > 5)
|
||||||
{
|
{
|
||||||
CrestronConsole.ConsoleCommandResponse($"Error: Unable to parse {levelString} to valid log level. If using a number, value must be between 0-5");
|
CrestronConsole.ConsoleCommandResponse($"Error: Unable to parse {levelString} to valid log level. If using a number, value must be between 0-5");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SetDebugLevel((uint) levelInt);
|
SetDebugLevel((uint)levelInt);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Enum.TryParse<LogEventLevel>(levelString, out var levelEnum))
|
if (Enum.TryParse<LogEventLevel>(levelString, out var levelEnum))
|
||||||
{
|
{
|
||||||
SetDebugLevel(levelEnum);
|
SetDebugLevel(levelEnum);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CrestronConsole.ConsoleCommandResponse($"Error: Unable to parse {levelString} to valid log level");
|
CrestronConsole.ConsoleCommandResponse($"Error: Unable to parse {levelString} to valid log level");
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
CrestronConsole.ConsoleCommandResponse("Usage: appdebug:P [0-5]");
|
CrestronConsole.ConsoleCommandResponse("Usage: appdebug:P [0-5]");
|
||||||
|
|
@ -377,7 +379,7 @@ public static class Debug
|
||||||
/// <param name="level"> Valid values 0-5</param>
|
/// <param name="level"> Valid values 0-5</param>
|
||||||
public static void SetDebugLevel(uint level)
|
public static void SetDebugLevel(uint level)
|
||||||
{
|
{
|
||||||
if(!_logLevels.TryGetValue(level, out var logLevel))
|
if (!_logLevels.TryGetValue(level, out var logLevel))
|
||||||
{
|
{
|
||||||
logLevel = LogEventLevel.Information;
|
logLevel = LogEventLevel.Information;
|
||||||
|
|
||||||
|
|
@ -396,9 +398,9 @@ public static class Debug
|
||||||
CrestronConsole.ConsoleCommandResponse("[Application {0}], Debug level set to {1}\r\n",
|
CrestronConsole.ConsoleCommandResponse("[Application {0}], Debug level set to {1}\r\n",
|
||||||
InitialParametersClass.ApplicationNumber, _consoleLoggingLevelSwitch.MinimumLevel);
|
InitialParametersClass.ApplicationNumber, _consoleLoggingLevelSwitch.MinimumLevel);
|
||||||
|
|
||||||
CrestronConsole.ConsoleCommandResponse($"Storing level {level}:{(int) level}");
|
CrestronConsole.ConsoleCommandResponse($"Storing level {level}:{(int)level}");
|
||||||
|
|
||||||
var err = CrestronDataStoreStatic.SetLocalIntValue(LevelStoreKey, (int) level);
|
var err = CrestronDataStoreStatic.SetLocalIntValue(LevelStoreKey, (int)level);
|
||||||
|
|
||||||
CrestronConsole.ConsoleCommandResponse($"Store result: {err}:{(int)level}");
|
CrestronConsole.ConsoleCommandResponse($"Store result: {err}:{(int)level}");
|
||||||
|
|
||||||
|
|
@ -408,9 +410,9 @@ public static class Debug
|
||||||
|
|
||||||
public static void SetWebSocketMinimumDebugLevel(LogEventLevel level)
|
public static void SetWebSocketMinimumDebugLevel(LogEventLevel level)
|
||||||
{
|
{
|
||||||
_websocketLoggingLevelSwitch.MinimumLevel = level;
|
_websocketLoggingLevelSwitch.MinimumLevel = level;
|
||||||
|
|
||||||
var err = CrestronDataStoreStatic.SetLocalUintValue(WebSocketLevelStoreKey, (uint) level);
|
var err = CrestronDataStoreStatic.SetLocalUintValue(WebSocketLevelStoreKey, (uint)level);
|
||||||
|
|
||||||
if (err != CrestronDataStore.CDS_ERROR.CDS_SUCCESS)
|
if (err != CrestronDataStore.CDS_ERROR.CDS_SUCCESS)
|
||||||
LogMessage(LogEventLevel.Information, "Error saving websocket debug level setting: {erro}", err);
|
LogMessage(LogEventLevel.Information, "Error saving websocket debug level setting: {erro}", err);
|
||||||
|
|
@ -468,80 +470,80 @@ public static class Debug
|
||||||
/// Callback for console command
|
/// Callback for console command
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="items"></param>
|
/// <param name="items"></param>
|
||||||
public static void SetDebugFilterFromConsole(string items)
|
public static void SetDebugFilterFromConsole(string items)
|
||||||
{
|
{
|
||||||
var str = items.Trim();
|
var str = items.Trim();
|
||||||
if (str == "?")
|
if (str == "?")
|
||||||
{
|
{
|
||||||
CrestronConsole.ConsoleCommandResponse("Usage:\r APPDEBUGFILTER key1 key2 key3....\r " +
|
CrestronConsole.ConsoleCommandResponse("Usage:\r APPDEBUGFILTER key1 key2 key3....\r " +
|
||||||
"+all: at beginning puts filter into 'default include' mode\r" +
|
"+all: at beginning puts filter into 'default include' mode\r" +
|
||||||
" All keys that follow will be excluded from output.\r" +
|
" All keys that follow will be excluded from output.\r" +
|
||||||
"-all: at beginning puts filter into 'default exclude all' mode.\r" +
|
"-all: at beginning puts filter into 'default exclude all' mode.\r" +
|
||||||
" All keys that follow will be the only keys that are shown\r" +
|
" All keys that follow will be the only keys that are shown\r" +
|
||||||
"+nokey: Enables messages with no key (default)\r" +
|
"+nokey: Enables messages with no key (default)\r" +
|
||||||
"-nokey: Disables messages with no key.\r" +
|
"-nokey: Disables messages with no key.\r" +
|
||||||
"(nokey settings are independent of all other settings)");
|
"(nokey settings are independent of all other settings)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var keys = Regex.Split(str, @"\s*");
|
var keys = Regex.Split(str, @"\s*");
|
||||||
foreach (var keyToken in keys)
|
foreach (var keyToken in keys)
|
||||||
{
|
{
|
||||||
var lkey = keyToken.ToLower();
|
var lkey = keyToken.ToLower();
|
||||||
if (lkey == "+all")
|
if (lkey == "+all")
|
||||||
{
|
{
|
||||||
IncludedExcludedKeys.Clear();
|
IncludedExcludedKeys.Clear();
|
||||||
_excludeAllMode = false;
|
_excludeAllMode = false;
|
||||||
}
|
}
|
||||||
else if (lkey == "-all")
|
else if (lkey == "-all")
|
||||||
{
|
{
|
||||||
IncludedExcludedKeys.Clear();
|
IncludedExcludedKeys.Clear();
|
||||||
_excludeAllMode = true;
|
_excludeAllMode = true;
|
||||||
}
|
}
|
||||||
//else if (lkey == "+nokey")
|
//else if (lkey == "+nokey")
|
||||||
//{
|
//{
|
||||||
// ExcludeNoKeyMessages = false;
|
// ExcludeNoKeyMessages = false;
|
||||||
//}
|
//}
|
||||||
//else if (lkey == "-nokey")
|
//else if (lkey == "-nokey")
|
||||||
//{
|
//{
|
||||||
// ExcludeNoKeyMessages = true;
|
// ExcludeNoKeyMessages = true;
|
||||||
//}
|
//}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string key;
|
string key;
|
||||||
if (lkey.StartsWith("-"))
|
if (lkey.StartsWith("-"))
|
||||||
{
|
{
|
||||||
key = lkey.Substring(1);
|
key = lkey.Substring(1);
|
||||||
// if in exclude all mode, we need to remove this from the inclusions
|
// if in exclude all mode, we need to remove this from the inclusions
|
||||||
if (_excludeAllMode)
|
if (_excludeAllMode)
|
||||||
{
|
{
|
||||||
if (IncludedExcludedKeys.ContainsKey(key))
|
if (IncludedExcludedKeys.ContainsKey(key))
|
||||||
IncludedExcludedKeys.Remove(key);
|
IncludedExcludedKeys.Remove(key);
|
||||||
}
|
}
|
||||||
// otherwise include all mode, add to the exclusions
|
// otherwise include all mode, add to the exclusions
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
IncludedExcludedKeys[key] = new object();
|
IncludedExcludedKeys[key] = new object();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (lkey.StartsWith("+"))
|
else if (lkey.StartsWith("+"))
|
||||||
{
|
{
|
||||||
key = lkey.Substring(1);
|
key = lkey.Substring(1);
|
||||||
// if in exclude all mode, we need to add this as inclusion
|
// if in exclude all mode, we need to add this as inclusion
|
||||||
if (_excludeAllMode)
|
if (_excludeAllMode)
|
||||||
{
|
{
|
||||||
|
|
||||||
IncludedExcludedKeys[key] = new object();
|
IncludedExcludedKeys[key] = new object();
|
||||||
}
|
}
|
||||||
// otherwise include all mode, remove this from exclusions
|
// otherwise include all mode, remove this from exclusions
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (IncludedExcludedKeys.ContainsKey(key))
|
if (IncludedExcludedKeys.ContainsKey(key))
|
||||||
IncludedExcludedKeys.Remove(key);
|
IncludedExcludedKeys.Remove(key);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -566,7 +568,7 @@ public static class Debug
|
||||||
public static object GetDeviceDebugSettingsForKey(string deviceKey)
|
public static object GetDeviceDebugSettingsForKey(string deviceKey)
|
||||||
{
|
{
|
||||||
return _contexts.GetDebugSettingsForKey(deviceKey);
|
return _contexts.GetDebugSettingsForKey(deviceKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the flag to prevent application starting on next boot
|
/// Sets the flag to prevent application starting on next boot
|
||||||
|
|
@ -626,7 +628,7 @@ public static class Debug
|
||||||
|
|
||||||
public static void LogMessage(LogEventLevel level, string message, params object[] args)
|
public static void LogMessage(LogEventLevel level, string message, params object[] args)
|
||||||
{
|
{
|
||||||
_logger.Write(level, message, args);
|
_logger.Write(level, message, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LogMessage(LogEventLevel level, Exception ex, string message, params object[] args)
|
public static void LogMessage(LogEventLevel level, Exception ex, string message, params object[] args)
|
||||||
|
|
@ -650,7 +652,7 @@ public static class Debug
|
||||||
#region Explicit methods for logging levels
|
#region Explicit methods for logging levels
|
||||||
public static void LogVerbose(IKeyed keyed, string message, params object[] args)
|
public static void LogVerbose(IKeyed keyed, string message, params object[] args)
|
||||||
{
|
{
|
||||||
using(LogContext.PushProperty("Key", keyed?.Key))
|
using (LogContext.PushProperty("Key", keyed?.Key))
|
||||||
{
|
{
|
||||||
_logger.Write(LogEventLevel.Verbose, message, args);
|
_logger.Write(LogEventLevel.Verbose, message, args);
|
||||||
}
|
}
|
||||||
|
|
@ -658,7 +660,7 @@ public static class Debug
|
||||||
|
|
||||||
public static void LogVerbose(Exception ex, IKeyed keyed, string message, params object[] args)
|
public static void LogVerbose(Exception ex, IKeyed keyed, string message, params object[] args)
|
||||||
{
|
{
|
||||||
using(LogContext.PushProperty("Key", keyed?.Key))
|
using (LogContext.PushProperty("Key", keyed?.Key))
|
||||||
{
|
{
|
||||||
_logger.Write(LogEventLevel.Verbose, ex, message, args);
|
_logger.Write(LogEventLevel.Verbose, ex, message, args);
|
||||||
}
|
}
|
||||||
|
|
@ -812,7 +814,7 @@ public static class Debug
|
||||||
if (!_logLevels.ContainsKey(level)) return;
|
if (!_logLevels.ContainsKey(level)) return;
|
||||||
|
|
||||||
var logLevel = _logLevels[level];
|
var logLevel = _logLevels[level];
|
||||||
|
|
||||||
LogMessage(logLevel, format, items);
|
LogMessage(logLevel, format, items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -849,7 +851,7 @@ public static class Debug
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Logs to Console when at-level, and all messages to error log, including device key
|
/// Logs to Console when at-level, and all messages to error log, including device key
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Obsolete("Use LogMessage methods, Will be removed in 2.2.0 and later versions")]
|
[Obsolete("Use LogMessage methods, Will be removed in 2.2.0 and later versions")]
|
||||||
public static void Console(uint level, IKeyed dev, string format, params object[] items)
|
public static void Console(uint level, IKeyed dev, string format, params object[] items)
|
||||||
|
|
@ -867,7 +869,7 @@ public static class Debug
|
||||||
[Obsolete("Use LogMessage methods, Will be removed in 2.2.0 and later versions")]
|
[Obsolete("Use LogMessage methods, Will be removed in 2.2.0 and later versions")]
|
||||||
public static void Console(uint level, IKeyed dev, ErrorLogLevel errorLogLevel,
|
public static void Console(uint level, IKeyed dev, ErrorLogLevel errorLogLevel,
|
||||||
string format, params object[] items)
|
string format, params object[] items)
|
||||||
{
|
{
|
||||||
LogMessage(level, dev, format, items);
|
LogMessage(level, dev, format, items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1005,7 +1007,7 @@ public static class Debug
|
||||||
return string.Format(@"\user\debugSettings\program{0}", InitialParametersClass.ApplicationNumber);
|
return string.Format(@"\user\debugSettings\program{0}", InitialParametersClass.ApplicationNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
return string.Format("{0}{1}user{1}debugSettings{1}{2}.json",Directory.GetApplicationRootDirectory(), Path.DirectorySeparatorChar, InitialParametersClass.RoomId);
|
return string.Format("{0}{1}user{1}debugSettings{1}{2}.json", Directory.GetApplicationRootDirectory(), Path.DirectorySeparatorChar, InitialParametersClass.RoomId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1016,15 +1018,15 @@ public static class Debug
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Error
|
/// Error
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Error,
|
Error,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Warning
|
/// Warning
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Warning,
|
Warning,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Notice
|
/// Notice
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Notice,
|
Notice,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// None
|
/// None
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -55,11 +55,6 @@
|
||||||
<PackageReference Include="SSH.NET" Version="2025.0.0" />
|
<PackageReference Include="SSH.NET" Version="2025.0.0" />
|
||||||
<PackageReference Include="WebSocketSharp-netstandard" Version="1.0.1" />
|
<PackageReference Include="WebSocketSharp-netstandard" Version="1.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup Condition="'$(TargetFramework)' == 'net6'">
|
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3">
|
|
||||||
<Aliases>global,NewtonsoftJson</Aliases>
|
|
||||||
</PackageReference>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Remove="Comm\._GenericSshClient.cs" />
|
<Compile Remove="Comm\._GenericSshClient.cs" />
|
||||||
<Compile Remove="Comm\._GenericTcpIpClient.cs" />
|
<Compile Remove="Comm\._GenericTcpIpClient.cs" />
|
||||||
|
|
|
||||||
|
|
@ -461,9 +461,9 @@ public static class DeviceManager
|
||||||
if (String.IsNullOrEmpty(s) || s.Contains("?"))
|
if (String.IsNullOrEmpty(s) || s.Contains("?"))
|
||||||
{
|
{
|
||||||
CrestronConsole.ConsoleCommandResponse(
|
CrestronConsole.ConsoleCommandResponse(
|
||||||
@"SETDEVICESTREAMDEBUG [{deviceKey}] [OFF |TX | RX | BOTH] [timeOutInMinutes]
|
"SETDEVICESTREAMDEBUG [{deviceKey}] [OFF |TX | RX | BOTH] [timeOutInMinutes]\r\n" +
|
||||||
{deviceKey} [OFF | TX | RX | BOTH] - Device to set stream debugging on, and which setting to use
|
" {deviceKey} [OFF | TX | RX | BOTH] - Device to set stream debugging on, and which setting to use\r\n" +
|
||||||
timeOutInMinutes - Set timeout for stream debugging. Default is 30 minutes");
|
" timeOutInMinutes - Set timeout for stream debugging. Default is 30 minutes");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
@ -10,15 +11,9 @@ using Newtonsoft.Json.Linq;
|
||||||
using PepperDash.Core;
|
using PepperDash.Core;
|
||||||
using PepperDash.Essentials.Core.Config;
|
using PepperDash.Essentials.Core.Config;
|
||||||
using Serilog.Events;
|
using Serilog.Events;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace PepperDash.Essentials.Core;
|
namespace PepperDash.Essentials.Core;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides functionality for managing and registering device factories, including loading plugin-based factories and
|
/// Provides functionality for managing and registering device factories, including loading plugin-based factories and
|
||||||
/// retrieving devices based on their configuration.
|
/// retrieving devices based on their configuration.
|
||||||
|
|
@ -39,14 +34,14 @@ public class DeviceFactory
|
||||||
/// instantiated, an informational log message is generated, and the process continues with the remaining
|
/// instantiated, an informational log message is generated, and the process continues with the remaining
|
||||||
/// types.</remarks>
|
/// types.</remarks>
|
||||||
public DeviceFactory()
|
public DeviceFactory()
|
||||||
{
|
{
|
||||||
var programAssemblies = Directory.GetFiles(InitialParametersClass.ProgramDirectory.ToString(), "*.dll");
|
var programAssemblies = Directory.GetFiles(InitialParametersClass.ProgramDirectory.ToString(), "*.dll");
|
||||||
|
|
||||||
foreach(var assembly in programAssemblies)
|
foreach (var assembly in programAssemblies)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Assembly.LoadFrom(assembly);
|
Assembly.LoadFrom(assembly);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
@ -54,7 +49,7 @@ public class DeviceFactory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
|
var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||||
|
|
||||||
// Loop through all loaded assemblies that contain at least 1 type that implements IDeviceFactory
|
// Loop through all loaded assemblies that contain at least 1 type that implements IDeviceFactory
|
||||||
foreach (var assembly in loadedAssemblies)
|
foreach (var assembly in loadedAssemblies)
|
||||||
|
|
@ -65,7 +60,7 @@ public class DeviceFactory
|
||||||
|
|
||||||
var types = assembly.GetTypes().Where(ct => typeof(IDeviceFactory).IsAssignableFrom(ct) && !ct.IsInterface && !ct.IsAbstract);
|
var types = assembly.GetTypes().Where(ct => typeof(IDeviceFactory).IsAssignableFrom(ct) && !ct.IsInterface && !ct.IsAbstract);
|
||||||
|
|
||||||
if(types == null || !types.Any())
|
if (types == null || !types.Any())
|
||||||
{
|
{
|
||||||
Debug.LogDebug("No DeviceFactory types found in assembly: {assemblyName}", assembly.GetName().Name);
|
Debug.LogDebug("No DeviceFactory types found in assembly: {assemblyName}", assembly.GetName().Name);
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -83,8 +78,8 @@ public class DeviceFactory
|
||||||
Debug.LogError("Unable to load type: '{message}' DeviceFactory: {type}", e.Message, type.Name);
|
Debug.LogError("Unable to load type: '{message}' DeviceFactory: {type}", e.Message, type.Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -113,7 +108,7 @@ public class DeviceFactory
|
||||||
private static readonly Dictionary<string, DeviceFactoryWrapper> FactoryMethods =
|
private static readonly Dictionary<string, DeviceFactoryWrapper> FactoryMethods =
|
||||||
new(StringComparer.OrdinalIgnoreCase);
|
new(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Registers a factory method for creating instances of a specific type.
|
/// Registers a factory method for creating instances of a specific type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>This method associates a type name with a factory method, allowing instances of the type to
|
/// <remarks>This method associates a type name with a factory method, allowing instances of the type to
|
||||||
|
|
@ -122,10 +117,10 @@ public class DeviceFactory
|
||||||
/// <param name="typeName">The name of the type for which the factory method is being registered. This value cannot be null or empty.</param>
|
/// <param name="typeName">The name of the type for which the factory method is being registered. This value cannot be null or empty.</param>
|
||||||
/// <param name="method">A delegate that defines the factory method. The delegate takes a <see cref="DeviceConfig"/> parameter and
|
/// <param name="method">A delegate that defines the factory method. The delegate takes a <see cref="DeviceConfig"/> parameter and
|
||||||
/// returns an instance of <see cref="IKeyed"/>.</param>
|
/// returns an instance of <see cref="IKeyed"/>.</param>
|
||||||
public static void AddFactoryForType(string typeName, Func<DeviceConfig, IKeyed> method)
|
public static void AddFactoryForType(string typeName, Func<DeviceConfig, IKeyed> method)
|
||||||
{
|
{
|
||||||
FactoryMethods.Add(typeName, new DeviceFactoryWrapper() { FactoryMethod = method});
|
FactoryMethods.Add(typeName, new DeviceFactoryWrapper() { FactoryMethod = method });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Registers a factory method for creating instances of a specific device type.
|
/// Registers a factory method for creating instances of a specific device type.
|
||||||
|
|
@ -139,7 +134,7 @@ public class DeviceFactory
|
||||||
/// cref="IKeyed"/>.</param>
|
/// cref="IKeyed"/>.</param>
|
||||||
public static void AddFactoryForType(string typeName, string description, Type Type, Func<DeviceConfig, IKeyed> method)
|
public static void AddFactoryForType(string typeName, string description, Type Type, Func<DeviceConfig, IKeyed> method)
|
||||||
{
|
{
|
||||||
if(FactoryMethods.ContainsKey(typeName))
|
if (FactoryMethods.ContainsKey(typeName))
|
||||||
{
|
{
|
||||||
Debug.LogInformation("Unable to add type: '{typeName}'. Already exists in DeviceFactory", typeName);
|
Debug.LogInformation("Unable to add type: '{typeName}'. Already exists in DeviceFactory", typeName);
|
||||||
return;
|
return;
|
||||||
|
|
@ -157,7 +152,7 @@ public class DeviceFactory
|
||||||
if (prop.Name.Equals("secret", StringComparison.CurrentCultureIgnoreCase))
|
if (prop.Name.Equals("secret", StringComparison.CurrentCultureIgnoreCase))
|
||||||
{
|
{
|
||||||
var secret = GetSecret(prop.Children().First().ToObject<SecretsPropertiesConfig>());
|
var secret = GetSecret(prop.Children().First().ToObject<SecretsPropertiesConfig>());
|
||||||
|
|
||||||
prop.Parent.Replace(secret);
|
prop.Parent.Replace(secret);
|
||||||
}
|
}
|
||||||
if (prop.Value is not JObject recurseProp) return;
|
if (prop.Value is not JObject recurseProp) return;
|
||||||
|
|
@ -170,7 +165,7 @@ public class DeviceFactory
|
||||||
var secretProvider = SecretsManager.GetSecretProviderByKey(data.Provider);
|
var secretProvider = SecretsManager.GetSecretProviderByKey(data.Provider);
|
||||||
if (secretProvider == null) return null;
|
if (secretProvider == null) return null;
|
||||||
var secret = secretProvider.GetSecret(data.Key);
|
var secret = secretProvider.GetSecret(data.Key);
|
||||||
if (secret != null) return (string) secret.Value;
|
if (secret != null) return (string)secret.Value;
|
||||||
Debug.LogMessage(LogEventLevel.Debug,
|
Debug.LogMessage(LogEventLevel.Debug,
|
||||||
"Unable to retrieve secret {0}{1} - Make sure you've added it to the secrets provider",
|
"Unable to retrieve secret {0}{1} - Make sure you've added it to the secrets provider",
|
||||||
data.Provider, data.Key);
|
data.Provider, data.Key);
|
||||||
|
|
@ -191,7 +186,7 @@ public class DeviceFactory
|
||||||
public static IKeyed GetDevice(DeviceConfig dc)
|
public static IKeyed GetDevice(DeviceConfig dc)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var localDc = new DeviceConfig(dc);
|
var localDc = new DeviceConfig(dc);
|
||||||
|
|
||||||
var key = localDc.Key;
|
var key = localDc.Key;
|
||||||
|
|
@ -253,23 +248,23 @@ public class DeviceFactory
|
||||||
}
|
}
|
||||||
|
|
||||||
CrestronConsole.ConsoleCommandResponse(
|
CrestronConsole.ConsoleCommandResponse(
|
||||||
@"Type: '{0}'
|
"Type: '{0}'\r\n" +
|
||||||
Type: '{1}'
|
" Type: '{1}'\r\n" +
|
||||||
Description: {2}{3}", type.Key, Type, description, CrestronEnvironment.NewLine);
|
" Description: {2}{3}", type.Key, Type, description, CrestronEnvironment.NewLine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves a dictionary of device factory wrappers, optionally filtered by a specified string.
|
/// Retrieves a dictionary of device factory wrappers, optionally filtered by a specified string.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filter">A string used to filter the dictionary keys. Only entries with keys containing the specified filter will be
|
/// <param name="filter">A string used to filter the dictionary keys. Only entries with keys containing the specified filter will be
|
||||||
/// included. If <see langword="null"/> or empty, all entries are returned.</param>
|
/// included. If <see langword="null"/> or empty, all entries are returned.</param>
|
||||||
/// <returns>A dictionary where the keys are strings representing device identifiers and the values are <see
|
/// <returns>A dictionary where the keys are strings representing device identifiers and the values are <see
|
||||||
/// cref="DeviceFactoryWrapper"/> instances. The dictionary may be empty if no entries match the filter.</returns>
|
/// cref="DeviceFactoryWrapper"/> instances. The dictionary may be empty if no entries match the filter.</returns>
|
||||||
public static Dictionary<string, DeviceFactoryWrapper> GetDeviceFactoryDictionary(string filter)
|
public static Dictionary<string, DeviceFactoryWrapper> GetDeviceFactoryDictionary(string filter)
|
||||||
{
|
{
|
||||||
return string.IsNullOrEmpty(filter)
|
return string.IsNullOrEmpty(filter)
|
||||||
? FactoryMethods
|
? FactoryMethods
|
||||||
: FactoryMethods.Where(k => k.Key.Contains(filter)).ToDictionary(k => k.Key, k => k.Value);
|
: FactoryMethods.Where(k => k.Key.Contains(filter)).ToDictionary(k => k.Key, k => k.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue