From b07806ad37d345ca568ade823449c5730e501b3c Mon Sep 17 00:00:00 2001
From: root <295172551@qq.com>
Date: Sat, 28 Jun 2025 20:23:47 +0800
Subject: [PATCH] dsad
---
LTEMvcApp/Controllers/HomeController.cs | 40 ---------------
LTEMvcApp/Services/WebSocketManagerService.cs | 49 ++-----------------
2 files changed, 4 insertions(+), 85 deletions(-)
diff --git a/LTEMvcApp/Controllers/HomeController.cs b/LTEMvcApp/Controllers/HomeController.cs
index 824cc02..d62bf40 100644
--- a/LTEMvcApp/Controllers/HomeController.cs
+++ b/LTEMvcApp/Controllers/HomeController.cs
@@ -170,46 +170,6 @@ public class HomeController : Controller
return View();
}
- ///
- /// 添加测试客户端配置
- ///
- [HttpPost]
- public IActionResult AddTestClient()
- {
- _logger.LogInformation("添加测试客户端配置");
- var config = new ClientConfig
- {
- Name = "测试客户端",
- Address = "192.168.13.12:9001",
- Ssl = false,
- Enabled = true,
- ReconnectDelay = 5000,
- Password = "test123",
- Logs = new ClientLogsConfig
- {
- Layers = new Dictionary
- {
- ["PHY"] = new LogLayerConfig { Level = "debug", Filter = "debug", MaxSize = 1000, Payload = false },
- ["RRC"] = new LogLayerConfig { Level = "debug", Filter = "debug", MaxSize = 1000, Payload = false }
- },
- Signal = true,
- Cch = true
- }
- };
-
- var success = _webSocketManager.AddClientConfig(config);
- if (success)
- {
- TempData["Message"] = "测试客户端配置已添加";
- }
- else
- {
- TempData["Error"] = "添加测试客户端配置失败";
- }
-
- return RedirectToAction(nameof(Index));
- }
-
///
/// 启动测试客户端
///
diff --git a/LTEMvcApp/Services/WebSocketManagerService.cs b/LTEMvcApp/Services/WebSocketManagerService.cs
index aae083d..30858c9 100644
--- a/LTEMvcApp/Services/WebSocketManagerService.cs
+++ b/LTEMvcApp/Services/WebSocketManagerService.cs
@@ -20,7 +20,6 @@ namespace LTEMvcApp.Services
#region 私有字段
private readonly ConcurrentDictionary _clients;
- private readonly ConcurrentDictionary _configs;
private readonly ILogger _logger;
private readonly IServiceProvider _serviceProvider;
private List _testClientConfigs; // 只保留多个测试配置
@@ -70,7 +69,6 @@ namespace LTEMvcApp.Services
public WebSocketManagerService(ILogger logger, IServiceProvider serviceProvider)
{
_clients = new ConcurrentDictionary();
- _configs = new ConcurrentDictionary();
_logger = logger;
_serviceProvider = serviceProvider;
_testClientConfigs = new List(); // 初始化测试配置列表
@@ -180,44 +178,6 @@ namespace LTEMvcApp.Services
#region 公共方法
- ///
- /// 添加客户端配置
- ///
- /// 客户端配置
- /// 是否成功添加
- public bool AddClientConfig(ClientConfig config)
- {
- if (string.IsNullOrEmpty(config.Name))
- {
- _logger.LogWarning("尝试添加空名称客户端配置");
- return false;
- }
- _logger.LogInformation($"添加客户端配置: {config.Name}");
- _configs[config.Name] = config;
- return true;
- }
-
- ///
- /// 移除客户端配置
- ///
- /// 客户端名称
- /// 是否成功移除
- public bool RemoveClientConfig(string clientName)
- {
- _logger.LogInformation($"移除客户端配置: {clientName}");
- if (_configs.TryRemove(clientName, out _))
- {
- // 如果客户端正在运行,停止它
- if (_clients.TryGetValue(clientName, out var client))
- {
- client.Stop();
- _clients.TryRemove(clientName, out _);
- }
- return true;
- }
- return false;
- }
-
///
/// 启动客户端
///
@@ -234,7 +194,7 @@ namespace LTEMvcApp.Services
config = testConfig;
_logger.LogInformation($"使用测试客户端配置: {config.Address}");
}
- else if (!_configs.TryGetValue(address, out config))
+ else
{
_logger.LogWarning($"客户端配置不存在: {address}");
return false;
@@ -308,8 +268,7 @@ namespace LTEMvcApp.Services
/// 客户端配置
public ClientConfig? GetClientConfig(string clientName)
{
- _configs.TryGetValue(clientName, out var config);
- return config;
+ return _testClientConfigs.FirstOrDefault(c => c.Name == clientName);
}
///
@@ -318,7 +277,7 @@ namespace LTEMvcApp.Services
/// 客户端配置列表
public List GetAllClientConfigs()
{
- return _configs.Values.ToList();
+ return _testClientConfigs.ToList();
}
///
@@ -432,7 +391,7 @@ namespace LTEMvcApp.Services
///
public void StartAllConfiguredClients()
{
- foreach (var config in _configs.Values)
+ foreach (var config in _testClientConfigs)
{
if (config.Enabled)
{