Browse Source

bcch log update

feature/protocol-log-Perfect
root 4 months ago
parent
commit
64f62c15a0
  1. 55
      CoreAgent.Application/Handlers/CellularNetwork/StartCellularNetworkCommandHandler.cs
  2. 55
      CoreAgent.Infrastructure/Services/Network/GeneralCellularNetworkService.cs

55
CoreAgent.Application/Handlers/CellularNetwork/StartCellularNetworkCommandHandler.cs

@ -15,13 +15,15 @@ public class StartCellularNetworkCommandHandler : IRequestHandler<StartCellularN
{
private readonly ICellularNetworkService _cellularNetworkService;
private readonly ILogger<StartCellularNetworkCommandHandler> _logger;
private readonly IRanAPICommandHandlerFactory _ranAPICommandHandlerFactory;
public StartCellularNetworkCommandHandler(
ICellularNetworkService cellularNetworkService,
ILogger<StartCellularNetworkCommandHandler> logger)
ILogger<StartCellularNetworkCommandHandler> logger,
IRanAPICommandHandlerFactory ranAPICommandHandlerFactory)
{
_cellularNetworkService = cellularNetworkService;
_logger = logger;
_ranAPICommandHandlerFactory = ranAPICommandHandlerFactory ?? throw new ArgumentNullException(nameof(ranAPICommandHandlerFactory));
}
public async Task<ApiActionResult<NetworkStatus>> Handle(StartCellularNetworkCommand request, CancellationToken cancellationToken)
@ -32,7 +34,7 @@ public class StartCellularNetworkCommandHandler : IRequestHandler<StartCellularN
// 启动网络
var result = await _cellularNetworkService.StartAsync(request.Key);
_=Task.Run(() => SetBcchLogStatusAsync(), cancellationToken);
if (result.IsSuccess)
{
_logger.LogInformation("蜂窝网络配置 {ConfigKey} 启动成功", request.Key);
@ -56,4 +58,51 @@ public class StartCellularNetworkCommandHandler : IRequestHandler<StartCellularN
HttpStatusCode.InternalServerError);
}
}
/// <summary>
/// 设置BCCH日志状态
/// </summary>
/// <returns>任务</returns>
private async Task SetBcchLogStatusAsync()
{
try
{
// 使用工厂创建处理器实例
var ranApiCommandHandler = _ranAPICommandHandlerFactory.CreateHandler();
// 设置BCCH日志状态为true
_logger.LogInformation("开始设置BCCH日志状态为true");
var setTrueResult = await ranApiCommandHandler.SetBcchLogStatusAsync(true);
if (setTrueResult)
{
_logger.LogInformation("BCCH日志状态设置为true成功");
// 等待200秒
_logger.LogInformation("等待200秒后设置BCCH日志状态为false");
await Task.Delay(TimeSpan.FromSeconds(200));
// 设置BCCH日志状态为false
_logger.LogInformation("200秒后开始设置BCCH日志状态为false");
var setFalseResult = await ranApiCommandHandler.SetBcchLogStatusAsync(false);
if (setFalseResult)
{
_logger.LogInformation("BCCH日志状态设置为false成功");
}
else
{
_logger.LogWarning("BCCH日志状态设置为false失败");
}
}
else
{
_logger.LogWarning("BCCH日志状态设置为true失败");
}
}
catch (Exception ex)
{
_logger.LogError(ex, "设置BCCH日志状态时发生异常");
}
}
}

55
CoreAgent.Infrastructure/Services/Network/GeneralCellularNetworkService.cs

@ -31,7 +31,6 @@ namespace CoreAgent.Infrastructure.Services.Network
private readonly IWebSocketTransport _webSocketTransport;
private readonly IProtocolWsClientManager _protocolWsClientManager;
private readonly IServiceScopeManager _serviceScopeManager;
private readonly IRanAPICommandHandlerFactory _ranAPICommandHandlerFactory;
private static readonly SemaphoreSlim _startLock = new(1, 1);
private const int LockTimeoutSeconds = 60;
@ -48,8 +47,7 @@ namespace CoreAgent.Infrastructure.Services.Network
IWebSocketTransport webSocketTransport,
IProtocolLogObserver protocolLogObserver,
IProtocolWsClientManager protocolWsClientManager,
IServiceScopeManager serviceScopeManager,
IRanAPICommandHandlerFactory ranAPICommandHandlerFactory)
IServiceScopeManager serviceScopeManager)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
@ -60,7 +58,6 @@ namespace CoreAgent.Infrastructure.Services.Network
_webSocketTransport = webSocketTransport ?? throw new ArgumentNullException(nameof(webSocketTransport));
_protocolWsClientManager = protocolWsClientManager ?? throw new ArgumentNullException(nameof(protocolWsClientManager));
_serviceScopeManager = serviceScopeManager ?? throw new ArgumentNullException(nameof(serviceScopeManager));
_ranAPICommandHandlerFactory = ranAPICommandHandlerFactory ?? throw new ArgumentNullException(nameof(ranAPICommandHandlerFactory));
}
/// <summary>
@ -388,9 +385,6 @@ namespace CoreAgent.Infrastructure.Services.Network
var step12Duration = (DateTime.UtcNow - step12Start).TotalMilliseconds;
_logger.LogDebug("步骤12完成:启动所有协议客户端,耗时: {Duration}ms", step12Duration.ToString("F2"));
await SetBcchLogStatusAsync();
_logger.LogInformation("BCCH日志状态设置完成");
var endTime = DateTime.UtcNow;
var duration = endTime - startTime;
_logger.LogInformation("蜂窝网络配置 {ConfigKey} 启动成功,当前状态: {Status},总耗时: {Duration}ms",
@ -519,52 +513,5 @@ namespace CoreAgent.Infrastructure.Services.Network
return CellularNetworkOperationResult.Failure($"启动协议客户端失败: {ex.Message}");
}
}
/// <summary>
/// 设置BCCH日志状态
/// </summary>
/// <returns>任务</returns>
private async Task SetBcchLogStatusAsync()
{
try
{
// 使用工厂创建处理器实例
var ranApiCommandHandler = _ranAPICommandHandlerFactory.CreateHandler();
// 设置BCCH日志状态为true
_logger.LogInformation("开始设置BCCH日志状态为true");
var setTrueResult = await ranApiCommandHandler.SetBcchLogStatusAsync(true);
if (setTrueResult)
{
_logger.LogInformation("BCCH日志状态设置为true成功");
// 等待200秒
_logger.LogInformation("等待200秒后设置BCCH日志状态为false");
await Task.Delay(TimeSpan.FromSeconds(200));
// 设置BCCH日志状态为false
_logger.LogInformation("200秒后开始设置BCCH日志状态为false");
var setFalseResult = await ranApiCommandHandler.SetBcchLogStatusAsync(false);
if (setFalseResult)
{
_logger.LogInformation("BCCH日志状态设置为false成功");
}
else
{
_logger.LogWarning("BCCH日志状态设置为false失败");
}
}
else
{
_logger.LogWarning("BCCH日志状态设置为true失败");
}
}
catch (Exception ex)
{
_logger.LogError(ex, "设置BCCH日志状态时发生异常");
}
}
}
}

Loading…
Cancel
Save