From 2cf973abeabe1c5f2a8c40819375c1a7cd86863b Mon Sep 17 00:00:00 2001 From: root <295172551@qq.com> Date: Wed, 25 Jun 2025 23:44:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E8=8B=8F=E6=89=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LTEMvcApp/Controllers/HomeController.cs | 15 ++------ LTEMvcApp/Controllers/TestConfigController.cs | 11 ++++++ LTEMvcApp/Services/WebSocketManagerService.cs | 38 +++++++++++++++++++ 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/LTEMvcApp/Controllers/HomeController.cs b/LTEMvcApp/Controllers/HomeController.cs index 4847cd0..627a357 100644 --- a/LTEMvcApp/Controllers/HomeController.cs +++ b/LTEMvcApp/Controllers/HomeController.cs @@ -27,18 +27,9 @@ public class HomeController : Controller var configs = _webSocketManager.GetAllClientConfigs(); ViewBag.ClientConfigs = configs; - // 获取测试客户端配置 - var testConfig = _webSocketManager.GetDefaultTestClientConfig(); - var testClient = _webSocketManager.GetTestClient(); - var clientState = testClient?.State ?? LTEMvcApp.Models.ClientState.Stop; - - ViewBag.TestConfig = testConfig; - ViewBag.ClientState = clientState; - // 以后可以扩展为客户端列表 - ViewBag.Clients = new List - { - new { Config = testConfig, State = clientState } - }; + // 获取所有测试客户端配置和状态 + var allTestClients = _webSocketManager.GetAllTestClientsWithState(); + ViewBag.Clients = allTestClients; return View(); } diff --git a/LTEMvcApp/Controllers/TestConfigController.cs b/LTEMvcApp/Controllers/TestConfigController.cs index 83ffb9a..c0d58e7 100644 --- a/LTEMvcApp/Controllers/TestConfigController.cs +++ b/LTEMvcApp/Controllers/TestConfigController.cs @@ -61,6 +61,17 @@ namespace LTEMvcApp.Controllers return Ok(configs); } + /// + /// 获取所有测试客户端配置和状态 + /// + /// 测试客户端配置和状态列表 + [HttpGet("with-state")] + public ActionResult> GetAllTestClientsWithState() + { + var clientsWithState = _webSocketManager.GetAllTestClientsWithState(); + return Ok(clientsWithState); + } + /// /// 根据地址获取测试客户端配置 /// diff --git a/LTEMvcApp/Services/WebSocketManagerService.cs b/LTEMvcApp/Services/WebSocketManagerService.cs index 82b256d..da351a2 100644 --- a/LTEMvcApp/Services/WebSocketManagerService.cs +++ b/LTEMvcApp/Services/WebSocketManagerService.cs @@ -501,6 +501,44 @@ namespace LTEMvcApp.Services return GetClientInstance(defaultConfig.Name); } + /// + /// 获取所有测试客户端实例 + /// + /// 所有测试客户端的WebSocket实例列表 + public List GetAllTestClients() + { + var testClients = new List(); + + foreach (var config in _testClientConfigs) + { + if (_clients.TryGetValue(config.Name, out var client)) + { + testClients.Add(client); + } + } + + return testClients; + } + + /// + /// 获取所有测试客户端配置和状态 + /// + /// 测试客户端配置和状态列表 + public List GetAllTestClientsWithState() + { + var result = new List(); + + foreach (var config in _testClientConfigs) + { + var client = GetClientInstance(config.Name); + var state = client?.State ?? ClientState.Stop; + + result.Add(new { Config = config, State = state, Client = client }); + } + + return result; + } + /// /// 创建默认测试配置 ///