fix: use correct line endings for verbatim strings

This commit is contained in:
Andrew Welker 2025-08-06 08:55:08 -05:00 committed by Neil Dorin
parent 5d90fafbd7
commit 3feab2593d
4 changed files with 142 additions and 150 deletions

View file

@ -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;
@ -111,6 +110,8 @@ public static class Debug
/// </summary> /// </summary>
private static bool _excludeAllMode; private static bool _excludeAllMode;
//static bool ExcludeNoKeyMessages;
private static readonly Dictionary<string, object> IncludedExcludedKeys; private static readonly Dictionary<string, object> IncludedExcludedKeys;
private static readonly LoggerConfiguration _defaultLoggerConfiguration; private static readonly LoggerConfiguration _defaultLoggerConfiguration;
@ -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,18 +348,18 @@ 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;
@ -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}");
@ -410,7 +412,7 @@ public static class Debug
{ {
_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);
@ -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);
} }
@ -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>

View file

@ -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" />

View file

@ -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;
} }

View file

@ -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.
@ -42,7 +37,7 @@ public class 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
{ {
@ -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;
@ -124,7 +119,7 @@ public class DeviceFactory
/// 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>
@ -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;
@ -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);
@ -253,9 +248,9 @@ 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);
} }
} }