Browse Source

大苏打

feature/MultiClientLog
root 1 month ago
parent
commit
2cf973abea
  1. 15
      LTEMvcApp/Controllers/HomeController.cs
  2. 11
      LTEMvcApp/Controllers/TestConfigController.cs
  3. 38
      LTEMvcApp/Services/WebSocketManagerService.cs

15
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<dynamic>
{
new { Config = testConfig, State = clientState }
};
// 获取所有测试客户端配置和状态
var allTestClients = _webSocketManager.GetAllTestClientsWithState();
ViewBag.Clients = allTestClients;
return View();
}

11
LTEMvcApp/Controllers/TestConfigController.cs

@ -61,6 +61,17 @@ namespace LTEMvcApp.Controllers
return Ok(configs);
}
/// <summary>
/// 获取所有测试客户端配置和状态
/// </summary>
/// <returns>测试客户端配置和状态列表</returns>
[HttpGet("with-state")]
public ActionResult<List<dynamic>> GetAllTestClientsWithState()
{
var clientsWithState = _webSocketManager.GetAllTestClientsWithState();
return Ok(clientsWithState);
}
/// <summary>
/// 根据地址获取测试客户端配置
/// </summary>

38
LTEMvcApp/Services/WebSocketManagerService.cs

@ -501,6 +501,44 @@ namespace LTEMvcApp.Services
return GetClientInstance(defaultConfig.Name);
}
/// <summary>
/// 获取所有测试客户端实例
/// </summary>
/// <returns>所有测试客户端的WebSocket实例列表</returns>
public List<LTEClientWebSocket> GetAllTestClients()
{
var testClients = new List<LTEClientWebSocket>();
foreach (var config in _testClientConfigs)
{
if (_clients.TryGetValue(config.Name, out var client))
{
testClients.Add(client);
}
}
return testClients;
}
/// <summary>
/// 获取所有测试客户端配置和状态
/// </summary>
/// <returns>测试客户端配置和状态列表</returns>
public List<dynamic> GetAllTestClientsWithState()
{
var result = new List<dynamic>();
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;
}
/// <summary>
/// 创建默认测试配置
/// </summary>

Loading…
Cancel
Save