You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
171 lines
4.7 KiB
171 lines
4.7 KiB
using System.Diagnostics;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using LTEMvcApp.Models;
|
|
using LTEMvcApp.Services;
|
|
|
|
namespace LTEMvcApp.Controllers;
|
|
|
|
public class HomeController : Controller
|
|
{
|
|
private readonly ILogger<HomeController> _logger;
|
|
private readonly WebSocketManagerService _webSocketManager;
|
|
|
|
public HomeController(ILogger<HomeController> logger, WebSocketManagerService webSocketManager)
|
|
{
|
|
_logger = logger;
|
|
_webSocketManager = webSocketManager;
|
|
}
|
|
|
|
public IActionResult Index()
|
|
{
|
|
_logger.LogInformation("访问首页");
|
|
// 获取连接统计信息
|
|
var stats = _webSocketManager.GetConnectionStatistics();
|
|
ViewBag.ConnectionStats = stats;
|
|
|
|
// 获取所有客户端配置
|
|
var configs = _webSocketManager.GetAllClientConfigs();
|
|
ViewBag.ClientConfigs = configs;
|
|
|
|
// 获取测试客户端配置
|
|
var testConfig = _webSocketManager.GetTestClientConfig();
|
|
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 }
|
|
};
|
|
|
|
return View();
|
|
}
|
|
|
|
public IActionResult Privacy()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
public IActionResult Error()
|
|
{
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
}
|
|
|
|
/// <summary>
|
|
/// WebSocket测试页面
|
|
/// </summary>
|
|
public IActionResult WebSocketTest()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加测试客户端配置
|
|
/// </summary>
|
|
[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<string, LogLayerConfig>
|
|
{
|
|
["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));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 启动测试客户端
|
|
/// </summary>
|
|
[HttpPost]
|
|
public IActionResult StartTestClient()
|
|
{
|
|
_logger.LogInformation("启动测试客户端");
|
|
var success = _webSocketManager.StartClient("测试客户端");
|
|
if (success)
|
|
{
|
|
TempData["Message"] = "测试客户端已启动";
|
|
}
|
|
else
|
|
{
|
|
TempData["Error"] = "启动测试客户端失败";
|
|
}
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 停止测试客户端
|
|
/// </summary>
|
|
[HttpPost]
|
|
public IActionResult StopTestClient()
|
|
{
|
|
_logger.LogInformation("停止测试客户端");
|
|
var success = _webSocketManager.StopClient("测试客户端");
|
|
if (success)
|
|
{
|
|
TempData["Message"] = "测试客户端已停止";
|
|
}
|
|
else
|
|
{
|
|
TempData["Error"] = "停止测试客户端失败";
|
|
}
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 测试客户端配置页面
|
|
/// </summary>
|
|
public IActionResult TestClientConfig()
|
|
{
|
|
var testConfig = _webSocketManager.GetTestClientConfig();
|
|
ViewBag.TestConfig = testConfig;
|
|
return View();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 客户端消息队列页面
|
|
/// </summary>
|
|
public IActionResult ClientMessages(string clientName = "TestClient")
|
|
{
|
|
ViewBag.ClientName = clientName;
|
|
return View();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 返回 Logs.cshtml 视图
|
|
/// </summary>
|
|
public IActionResult Logs()
|
|
{
|
|
return View();
|
|
}
|
|
}
|
|
|