fix: some fixes to file paths for the reworked websocket

This commit is contained in:
Nick Genovese
2024-11-05 13:16:46 -05:00
parent 1d20f6d1ed
commit 4f01ff1379
4 changed files with 22 additions and 17 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using Crestron.SimplSharp;
@@ -103,7 +104,7 @@ namespace PepperDash.Core
);
#if NET472
var certPath = IsRunningOnAppliance ? Path.Combine("/", "user", "selfCres.pfx") : Path.Combine("/", "User", "selfCres.pfx");
var certPath = IsRunningOnAppliance ? Path.Combine("/", "user") : Path.Combine("/", "User");
var websocket = new DebugNet472WebSocket(certPath);
WebsocketUrl = websocket.Url;
DefaultLoggerConfiguration.WriteTo.Sink(new DebugWebsocketSink(websocket, new JsonFormatter(renderMessage: true)), levelSwitch: WebsocketLoggingLevelSwitch);
@@ -190,16 +191,17 @@ namespace PepperDash.Core
return;
}
const string pattern = @"^(\d+)(?:\s+--devices\s+([\w,]+))?$";
var match = Regex.Match(levelString, pattern);
const string pattern = @"^(\d+)(?:\s+--devices\s+([\w\s,-]+))?$";
var match = Regex.Match(levelString, pattern);
if (match.Success)
{
var level = int.Parse(match.Groups[1].Value);
var devices = match.Groups[2].Success
? match.Groups[2].Value.Split(',')
.Select(device => device.Trim())
.ToArray()
: [];
if (LogLevels.TryGetValue(level, out var logEventLevel))
{
SetConsoleDebugLevel(logEventLevel, devices);
@@ -211,7 +213,7 @@ namespace PepperDash.Core
}
else
{
CrestronConsole.ConsoleCommandResponse($"Error: Unable to parse {levelString} to valid log level");
CrestronConsole.ConsoleCommandResponse($"Error: Unable to parse {levelString} to valid log level:does not match the pattern");
}
}
catch

View File

@@ -12,7 +12,7 @@ namespace PepperDash.Core.Logging
{
AppName = CrestronEnvironment.DevicePlatform switch
{
eDevicePlatform.Appliance => $"App {InitialParametersClass.ApplicationNumber}",
eDevicePlatform.Appliance => $"APP{InitialParametersClass.ApplicationNumber.ToString().PadLeft(2, '0')}",
eDevicePlatform.Server => $"{InitialParametersClass.RoomId}",
_ => string.Empty
};
@@ -22,7 +22,6 @@ namespace PepperDash.Core.Logging
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
var property = propertyFactory.CreateProperty("App", AppName);
logEvent.AddOrUpdateProperty(property);
}
}

View File

@@ -4,6 +4,7 @@ using System.Security.Cryptography.X509Certificates;
using Crestron.SimplSharp;
#if NET472
using System.IO;
using WebSocketSharp.Net;
using WebSocketSharp.Server;
@@ -11,10 +12,10 @@ namespace PepperDash.Core.Logging
{
internal class DebugNet472WebSocket : DebugWebSocket
{
private const string Path = "/debug/join/";
private const string WebsocketPath = "/debug/join/";
public string Url =>
$"wss://{CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0)}:{server.Port}{server.WebSocketServices[Path].Path}";
$"wss://{CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0)}:{server.Port}{server.WebSocketServices[WebsocketPath].Path}";
private readonly WebSocketServer server;
@@ -24,7 +25,8 @@ namespace PepperDash.Core.Logging
if (IsSecure)
{
server.SslConfiguration = new ServerSslConfiguration(new X509Certificate2(certPath, CertificatePassword))
var filename = Path.Combine(certPath, CertificateName + ".pfx");
server.SslConfiguration = new ServerSslConfiguration(new X509Certificate2(filename, CertificatePassword))
{
ClientCertificateRequired = false,
CheckCertificateRevocation = false,
@@ -38,7 +40,7 @@ namespace PepperDash.Core.Logging
};
}
server.AddWebSocketService<DebugClient>(Path);
server.AddWebSocketService<DebugClient>(WebsocketPath);
server.Start();
}

View File

@@ -1,10 +1,7 @@
using System;
using System.IO;
using Crestron.SimplSharp;
#if NET472
using Org.BouncyCastle.Asn1.X509;
#endif
namespace PepperDash.Core.Logging
{
@@ -22,8 +19,15 @@ namespace PepperDash.Core.Logging
return;
}
if (!File.Exists(certPath))
if (certPath == null)
{
return;
}
var filePath = Path.Combine(certPath, CertificateName + ".pfx");
if (!File.Exists(filePath))
{
Debug.LogInformation("Creating new cert at file path:{Path}", filePath);
CreateCert(certPath);
}
}
@@ -32,7 +36,6 @@ namespace PepperDash.Core.Logging
private static void CreateCert(string filePath)
{
#if NET472
try
{
var utility = new BouncyCertificate();
@@ -48,7 +51,6 @@ namespace PepperDash.Core.Logging
{
Debug.LogError(ex, "WSS failed to create cert");
}
#endif
}
public abstract bool IsListening { get; }