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.
74 lines
2.9 KiB
74 lines
2.9 KiB
|
4 months ago
|
using System;
|
||
|
|
using System.Net;
|
||
|
|
using System.Threading;
|
||
|
|
using System.Threading.Tasks;
|
||
|
|
using CoreAgent.Application.Commands.RanAPI;
|
||
|
|
using CoreAgent.Domain.Interfaces.Network;
|
||
|
|
using CoreAgent.Domain.Models.Common;
|
||
|
|
using MediatR;
|
||
|
|
using Microsoft.Extensions.Logging;
|
||
|
|
|
||
|
|
namespace CoreAgent.Application.Handlers.RanAPI;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 设置所有端口发送增益命令处理器
|
||
|
|
/// </summary>
|
||
|
|
public class SetAllTxGainCommandHandler : IRequestHandler<SetAllTxGainCommand, ApiActionResult<bool>>
|
||
|
|
{
|
||
|
|
private readonly IRanAPICommandHandlerFactory _ranAPICommandHandlerFactory;
|
||
|
|
private readonly ILogger<SetAllTxGainCommandHandler> _logger;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 构造函数
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="ranAPICommandHandlerFactory">RAN API命令处理器工厂</param>
|
||
|
|
/// <param name="logger">日志记录器</param>
|
||
|
|
public SetAllTxGainCommandHandler(
|
||
|
|
IRanAPICommandHandlerFactory ranAPICommandHandlerFactory,
|
||
|
|
ILogger<SetAllTxGainCommandHandler> logger)
|
||
|
|
{
|
||
|
|
_ranAPICommandHandlerFactory = ranAPICommandHandlerFactory ?? throw new ArgumentNullException(nameof(ranAPICommandHandlerFactory));
|
||
|
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 处理设置所有端口发送增益命令
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="request">设置所有端口发送增益命令</param>
|
||
|
|
/// <param name="cancellationToken">取消令牌</param>
|
||
|
|
/// <returns>设置所有端口发送增益结果</returns>
|
||
|
|
public async Task<ApiActionResult<bool>> Handle(SetAllTxGainCommand request, CancellationToken cancellationToken)
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
_logger.LogInformation("正在设置所有端口发送增益,端口数量: {PortCount}", request.GainValues?.Length);
|
||
|
|
|
||
|
|
// 通过工厂获取RAN增益控制处理器并执行操作
|
||
|
|
var ranGainControlHandler = _ranAPICommandHandlerFactory.CreateGainControlHandler();
|
||
|
|
var result = await ranGainControlHandler.SetAllTxGainAsync(request.GainValues);
|
||
|
|
|
||
|
|
if (result)
|
||
|
|
{
|
||
|
|
_logger.LogInformation("所有端口发送增益设置成功");
|
||
|
|
return ApiActionResult<bool>.Ok(true, "所有端口发送增益设置成功");
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
_logger.LogWarning("所有端口发送增益设置失败");
|
||
|
|
return ApiActionResult<bool>.Error(
|
||
|
|
"所有端口发送增益设置失败",
|
||
|
|
"ALL_TX_GAIN_SET_FAILED",
|
||
|
|
HttpStatusCode.BadRequest);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
_logger.LogError(ex, "设置所有端口发送增益失败");
|
||
|
|
return ApiActionResult<bool>.Error(
|
||
|
|
$"设置所有端口发送增益失败: {ex.Message}",
|
||
|
|
"INTERNAL_ERROR",
|
||
|
|
HttpStatusCode.InternalServerError);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|