This commit is contained in:
2026-01-21 22:13:31 +01:00
parent 3dce3cc56b
commit abc50d0c11
5 changed files with 314 additions and 299 deletions

View File

@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EonaCat.Connections.Client
{
// Root myDeserializedClass = JsonConvert.DeserializeObject<List<Root>>(myJsonResponse);
public class Contact
{
public string email { get; set; }
public string phone { get; set; }
}
public class Department
{
public string id { get; set; }
public string name { get; set; }
public Manager manager { get; set; }
}
public class Details
{
public int hoursSpent { get; set; }
public List<string> technologiesUsed { get; set; }
public string completionDate { get; set; }
public string expectedCompletion { get; set; }
}
public class Employee
{
public string id { get; set; }
public string name { get; set; }
public string position { get; set; }
public Department department { get; set; }
public List<Project> projects { get; set; }
}
public class Manager
{
public string id { get; set; }
public string name { get; set; }
public Contact contact { get; set; }
}
public class Project
{
public string projectId { get; set; }
public string projectName { get; set; }
public string startDate { get; set; }
public List<Task> tasks { get; set; }
}
public class Root
{
public Employee employee { get; set; }
}
public class Task
{
public string taskId { get; set; }
public string title { get; set; }
public string status { get; set; }
public Details details { get; set; }
}
}

View File

@@ -20,7 +20,7 @@ namespace EonaCat.Connections.Client.Example
//public static string SERVER_IP = "10.40.11.22";
public static string SERVER_IP = "127.0.0.1";
private static Dictionary<NetworkClient, JsonDataProcessor<dynamic>> _clientsProcessors = new Dictionary<NetworkClient, JsonDataProcessor<dynamic>>();
private static Dictionary<NetworkClient, JsonDataProcessor<List<Root>>> _clientsProcessors = new Dictionary<NetworkClient, JsonDataProcessor<List<Root>>>();
private static bool testDataProcessor;
public static bool WaitForMessage { get; private set; }
@@ -28,9 +28,9 @@ namespace EonaCat.Connections.Client.Example
public static bool ToConsoleOnly { get; private set; } = true;
public static bool UseJson { get; private set; } = true;
public static bool TESTBYTES { get; private set; }
public static bool UseJsonProcessorTest { get; private set; } = false;
public static bool UseJsonProcessorTest { get; private set; } = true;
public static async Task Main(string[] args)
public static async System.Threading.Tasks.Task Main(string[] args)
{
for (long i = 0; i < clientCount; i++)
{
@@ -40,7 +40,7 @@ namespace EonaCat.Connections.Client.Example
if (testDataProcessor)
{
_clientsProcessors[client] = new JsonDataProcessor<dynamic>();
_clientsProcessors[client] = new JsonDataProcessor<List<Root>>();
}
else
{
@@ -67,7 +67,7 @@ namespace EonaCat.Connections.Client.Example
break;
}
var jsonUrl = "https://samples.json-format.com/employees/json/employees_500KB.json";
var jsonUrl = "https://sample.json-format.com/api/download?url=https%3A%2F%2Ffiles.jsons.live%2Femployees%2F5-level%2F20-MB%2Fformatted.json&name=20%20MB%205%20Level%20Formatted.json";
try
{
@@ -98,14 +98,16 @@ namespace EonaCat.Connections.Client.Example
{
WriteToLog($"Processed JSON message from {e.ClientName} ({e.ClientEndpoint}): {e.RawData}");
};
processor.MaxAllowedBufferSize = 10 * 1024 * 1024; // 10 MB
processor.MaxAllowedBufferSize = 50 * 1024 * 1024; // 10 MB
processor.MaxMessagesPerBatch = 5;
var json = _jsonContent;
while (true)
{
json = "TEST1" + _jsonContent + "TEST2";
processor.Process(json, "TestClient");
await Task.Delay(100).ConfigureAwait(false);
await System.Threading.Tasks.Task.Delay(100).ConfigureAwait(false);
}
}
}
@@ -131,11 +133,11 @@ namespace EonaCat.Connections.Client.Example
}
}
await Task.Delay(1000).ConfigureAwait(false);
await System.Threading.Tasks.Task.Delay(1000).ConfigureAwait(false);
}
}
private static async Task StartClientAsync(string clientName, NetworkClient client)
private static async System.Threading.Tasks.Task StartClientAsync(string clientName, NetworkClient client)
{
await client.ConnectAsync().ConfigureAwait(false);
@@ -157,7 +159,7 @@ namespace EonaCat.Connections.Client.Example
UseAesEncryption = false,
EnableHeartbeat = IsHeartBeatEnabled,
AesPassword = "EonaCat.Connections.Password",
Certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2("client.pfx", "p@ss"),
//Certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2("client.pfx", "p@ss"),
};
var client = new NetworkClient(config);
@@ -172,8 +174,8 @@ namespace EonaCat.Connections.Client.Example
if (UseProcessor)
{
_clientsProcessors[client] = new JsonDataProcessor<object>();
_clientsProcessors[client].OnError += (sender, e) =>
_clientsProcessors[client] = new JsonDataProcessor<List<Root>>();
_clientsProcessors[client].OnMessageError += (sender, e) =>
{
Console.WriteLine($"Processor error: {e.Message}");
};
@@ -198,7 +200,7 @@ namespace EonaCat.Connections.Client.Example
{
if (UseProcessor)
{
_clientsProcessors[client].Process(e, currentClientName: e.Nickname);
_clientsProcessors[client].Process(e.StringData, clientName: e.Nickname);
return;
}
else