mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-04-20 07:56:50 +00:00
feat: implement WebSocket classes and update culture settings; bump PepperDashCore version
This commit is contained in:
parent
8be5481ac9
commit
bdd398e2e6
8 changed files with 185 additions and 8 deletions
0
src/PepperDash.Essentials.Core/Web/DebugWebsocketSink.cs
Normal file
0
src/PepperDash.Essentials.Core/Web/DebugWebsocketSink.cs
Normal file
|
|
@ -10,6 +10,7 @@ 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
|
||||
{
|
||||
|
|
@ -18,6 +19,9 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
|||
/// </summary>
|
||||
public class DebugSessionRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
|
||||
private readonly DebugWebsocketSink _sink = new DebugWebsocketSink();
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
|
|
@ -49,21 +53,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);
|
||||
|
|
@ -90,7 +94,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
|||
/// <param name="context"></param>
|
||||
protected override void HandlePost(HttpCwsContext context)
|
||||
{
|
||||
Debug.WebsocketSink.StopServer();
|
||||
_sink.StopServer();
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
|
|
|
|||
|
|
@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue