trying to fix that some messages are not send after specific events

This commit is contained in:
Tim G. | SnapixLP
2025-06-06 03:14:11 +02:00
parent 536de50e4c
commit c2608f4bf6
4 changed files with 45 additions and 22 deletions

View File

@@ -12,12 +12,18 @@ public class Server
private StreamReader reader;
private StreamWriter writer;
private Action<string> onMessageReceived;
private Action<string> onCommandReceived;
public Action<string> OnMessageReceived
{
get => onMessageReceived;
set => onMessageReceived = value ?? throw new ArgumentNullException(nameof(value), "onMessageReceived cannot be null.");
}
public Action<string> OnCommandReceived
{
get => onCommandReceived;
set => onCommandReceived = value ?? throw new ArgumentNullException(nameof(value), "onMessageReceived cannot be null.");
}
private ConcurrentDictionary<string, TaskCompletionSource<string>> pendingRequests = new();
@@ -49,6 +55,7 @@ public class Server
{
if (message.StartsWith("{") && message.EndsWith("}"))
{
onCommandReceived?.Invoke(message);
Console.WriteLine("Received: " + message);
// Parse the JSON response
var response = JsonSerializer.Deserialize<JsonResponse>(message);