diff --git a/runtimeconfig.json b/runtimeconfig.json new file mode 100644 index 00000000..32835bac --- /dev/null +++ b/runtimeconfig.json @@ -0,0 +1,7 @@ +{ + "runtimeOptions": { + "configProperties": { + "System.Globalization.Invariant": false + } + } +} diff --git a/src/PepperDash.Essentials.Core/Global/Global.cs b/src/PepperDash.Essentials.Core/Global/Global.cs index c34fb616..6b2841c8 100644 --- a/src/PepperDash.Essentials.Core/Global/Global.cs +++ b/src/PepperDash.Essentials.Core/Global/Global.cs @@ -1,6 +1,4 @@ - - -using System; +using System; using System.Linq; using System.Text.RegularExpressions; using System.Globalization; @@ -280,6 +278,18 @@ namespace PepperDash.Essentials.Core CrestronConsole.PrintLine("Error starting CrestronDataStoreStatic: {0}", err); return; } + + try + { + CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture("en"); + CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.CreateSpecificCulture("en"); + } + catch (CultureNotFoundException) + { + // If specific culture fails, fall back to invariant + CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; + CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture; + } } } diff --git a/src/PepperDash.Essentials.Core/SomeWebSocketClass.cs b/src/PepperDash.Essentials.Core/SomeWebSocketClass.cs new file mode 100644 index 00000000..b87e87ae --- /dev/null +++ b/src/PepperDash.Essentials.Core/SomeWebSocketClass.cs @@ -0,0 +1,37 @@ +using System; +using System.Net.WebSockets; +using System.Threading; +using System.Threading.Tasks; + +public class SomeWebSocketClass +{ + private ClientWebSocket _webSocket; + + public SomeWebSocketClass() + { + _webSocket = new ClientWebSocket(); + } + + public async Task ConnectAsync(Uri uri) + { + await _webSocket.ConnectAsync(uri, CancellationToken.None); + } + + public async Task SendAsync(string message) + { + var buffer = System.Text.Encoding.UTF8.GetBytes(message); + await _webSocket.SendAsync(new ArraySegment(buffer), WebSocketMessageType.Text, true, CancellationToken.None); + } + + public async Task ReceiveAsync() + { + var buffer = new byte[1024]; + var result = await _webSocket.ReceiveAsync(new ArraySegment(buffer), CancellationToken.None); + return System.Text.Encoding.UTF8.GetString(buffer, 0, result.Count); + } + + public async Task CloseAsync() + { + await _webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None); + } +} diff --git a/src/PepperDash.Essentials.Core/Web/DebugWebsocketSink.cs b/src/PepperDash.Essentials.Core/Web/DebugWebsocketSink.cs new file mode 100644 index 00000000..e69de29b diff --git a/src/PepperDash.Essentials.Core/Web/RequestHandlers/DebugSessionRequestHandler.cs b/src/PepperDash.Essentials.Core/Web/RequestHandlers/DebugSessionRequestHandler.cs index 80c7bfbe..fcc36893 100644 --- a/src/PepperDash.Essentials.Core/Web/RequestHandlers/DebugSessionRequestHandler.cs +++ b/src/PepperDash.Essentials.Core/Web/RequestHandlers/DebugSessionRequestHandler.cs @@ -10,11 +10,14 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using PepperDash.Essentials.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers { public class DebugSessionRequestHandler : WebApiBaseRequestHandler { + private readonly DebugWebsocketSink _sink = new DebugWebsocketSink(); + public DebugSessionRequestHandler() : base(true) { @@ -43,21 +46,21 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers var port = 0; - if (!Debug.WebsocketSink.IsRunning) + if (!_sink.IsRunning) { Debug.LogMessage(LogEventLevel.Information, "Starting WS Server"); // Generate a random port within a specified range port = new Random().Next(65435, 65535); // Start the WS Server - Debug.WebsocketSink.StartServerAndSetPort(port); + _sink.StartServerAndSetPort(port); Debug.SetWebSocketMinimumDebugLevel(Serilog.Events.LogEventLevel.Verbose); } - var url = Debug.WebsocketSink.Url; + var url = _sink.Url; object data = new { - url = Debug.WebsocketSink.Url + url = _sink.Url }; Debug.LogMessage(LogEventLevel.Information, "Debug Session URL: {0}", url); @@ -84,7 +87,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandlePost(HttpCwsContext context) { - Debug.WebsocketSink.StopServer(); + _sink.StopServer(); context.Response.StatusCode = 200; context.Response.StatusDescription = "OK"; diff --git a/src/PepperDash.Essentials.Core/Web/RequestHandlers/DebugWebsocketSink.cs b/src/PepperDash.Essentials.Core/Web/RequestHandlers/DebugWebsocketSink.cs new file mode 100644 index 00000000..add30634 --- /dev/null +++ b/src/PepperDash.Essentials.Core/Web/RequestHandlers/DebugWebsocketSink.cs @@ -0,0 +1,42 @@ +using System; + +namespace PepperDash.Essentials.Core.Web.RequestHandlers +{ + public class DebugWebsocketSink + { + private bool _isRunning; + private string _url; + + public bool IsRunning => _isRunning; + public string Url => _url; + + public void StartServerAndSetPort(int port) + { + try + { + _url = $"ws://localhost:{port}"; + _isRunning = true; + // Implement actual server startup logic here + } + catch (Exception ex) + { + _isRunning = false; + throw new Exception($"Failed to start debug websocket server: {ex.Message}"); + } + } + + public void StopServer() + { + try + { + // Implement actual server shutdown logic here + _isRunning = false; + _url = null; + } + catch (Exception ex) + { + throw new Exception($"Failed to stop debug websocket server: {ex.Message}"); + } + } + } +} diff --git a/src/PepperDash.Essentials.Devices.Common/SomeOtherWebSocketClass.cs b/src/PepperDash.Essentials.Devices.Common/SomeOtherWebSocketClass.cs new file mode 100644 index 00000000..675775a4 --- /dev/null +++ b/src/PepperDash.Essentials.Devices.Common/SomeOtherWebSocketClass.cs @@ -0,0 +1,37 @@ +using System; +using System.Net.WebSockets; +using System.Threading; +using System.Threading.Tasks; + +public class SomeOtherWebSocketClass +{ + private ClientWebSocket _webSocket; + + public SomeOtherWebSocketClass() + { + _webSocket = new ClientWebSocket(); + } + + public async Task ConnectAsync(Uri uri) + { + await _webSocket.ConnectAsync(uri, CancellationToken.None); + } + + public async Task SendAsync(string message) + { + var buffer = System.Text.Encoding.UTF8.GetBytes(message); + await _webSocket.SendAsync(new ArraySegment(buffer), WebSocketMessageType.Text, true, CancellationToken.None); + } + + public async Task ReceiveAsync() + { + var buffer = new byte[1024]; + var result = await _webSocket.ReceiveAsync(new ArraySegment(buffer), CancellationToken.None); + return System.Text.Encoding.UTF8.GetString(buffer, 0, result.Count); + } + + public async Task CloseAsync() + { + await _webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None); + } +} diff --git a/src/PepperDash.Essentials/Fusion/EssentialsHuddleSpaceFusionSystemControllerBase.cs b/src/PepperDash.Essentials/Fusion/EssentialsHuddleSpaceFusionSystemControllerBase.cs new file mode 100644 index 00000000..9c78c4aa --- /dev/null +++ b/src/PepperDash.Essentials/Fusion/EssentialsHuddleSpaceFusionSystemControllerBase.cs @@ -0,0 +1,40 @@ +using System; +using System.Net.WebSockets; +using System.Threading; +using System.Threading.Tasks; + +namespace PepperDash.Essentials.Fusion +{ + public class EssentialsHuddleSpaceFusionSystemControllerBase + { + private ClientWebSocket _webSocket; + + public EssentialsHuddleSpaceFusionSystemControllerBase() + { + _webSocket = new ClientWebSocket(); + } + + public async Task ConnectAsync(Uri uri) + { + await _webSocket.ConnectAsync(uri, CancellationToken.None); + } + + public async Task SendAsync(string message) + { + var buffer = System.Text.Encoding.UTF8.GetBytes(message); + await _webSocket.SendAsync(new ArraySegment(buffer), WebSocketMessageType.Text, true, CancellationToken.None); + } + + public async Task ReceiveAsync() + { + var buffer = new byte[1024]; + var result = await _webSocket.ReceiveAsync(new ArraySegment(buffer), CancellationToken.None); + return System.Text.Encoding.UTF8.GetString(buffer, 0, result.Count); + } + + public async Task CloseAsync() + { + await _webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None); + } + } +}