using System; using System.Net.Http; using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Client; using Domain; using Domain.Dto; using MessagePack; if (args.Length < 2) { System.Console.WriteLine("Pass two args: http/tcp and json/bin"); return -1; } var protocol = args[0]; var serialization = args[1]; IClient? client = protocol == "http" ? new HttpClientWrapper(serialization == "json" ? ConvertJsonResponse : ConvertMessagePackResponse) : null; client?.Start(); System.Console.WriteLine("Client started:"); System.Console.WriteLine(client); // Обработка выхода по Ctrl+C Console.CancelKeyPress += (sender, e) => { e.Cancel = true; // Prevent immediate termination Console.WriteLine("Shutdown signal received. Stopping client..."); client?.Stop(); Console.WriteLine("Goodbye!"); Environment.Exit(0); }; // Бесконечный цикл ожидания while (true) { Thread.Sleep(1000); } static async Task ConvertJsonResponse(HttpResponseMessage response) { var json = await response.Content.ReadAsStringAsync(); var jsonData = JsonSerializer.Deserialize(json); return jsonData?.ToData(); } static async Task ConvertMessagePackResponse(HttpResponseMessage response) { var bytes = await response.Content.ReadAsByteArrayAsync(); var msgPackData = MessagePackSerializer.Deserialize(bytes); return msgPackData?.ToData(); }