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.
86 lines
3.0 KiB
86 lines
3.0 KiB
|
4 months ago
|
using CoreAgent.Domain.Interfaces.System.Command;
|
||
|
|
using CoreAgent.Domain.Models.Network;
|
||
|
|
using CoreAgent.Domain.Models.System;
|
||
|
|
|
||
|
|
namespace CoreAgent.Domain.Interfaces.Network;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// RAN API 命令处理器基础接口
|
||
|
|
/// 负责处理各种RAN相关的API操作命令
|
||
|
|
/// </summary>
|
||
|
|
public interface IRanAPICommandHandler
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// 设置 RAN 日志配置
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="ranEndPoint">RAN 端点信息</param>
|
||
|
|
/// <param name="enableBcch">是否启用BCCH日志</param>
|
||
|
|
/// <returns>是否成功设置配置</returns>
|
||
|
|
Task<bool> SetRanLogsConfigAsync(RanIPEndPoint ranEndPoint, bool enableBcch);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// RAN API 命令处理器抽象基类
|
||
|
|
/// 提供通用的命令执行逻辑
|
||
|
|
/// </summary>
|
||
|
|
public abstract class RanAPICommandHandlerBase : IRanAPICommandHandler
|
||
|
|
{
|
||
|
|
protected readonly ISystemCommandExecutor _commandExecutor;
|
||
|
|
protected readonly AppSettings _appSettings;
|
||
|
|
|
||
|
|
protected RanAPICommandHandlerBase(ISystemCommandExecutor commandExecutor, AppSettings appSettings)
|
||
|
|
{
|
||
|
|
_commandExecutor = commandExecutor ?? throw new ArgumentNullException(nameof(commandExecutor));
|
||
|
|
_appSettings = appSettings ?? throw new ArgumentNullException(nameof(appSettings));
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 执行命令的通用方法
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="command">要执行的命令</param>
|
||
|
|
/// <param name="operationName">操作名称,用于日志记录</param>
|
||
|
|
/// <param name="parameters">操作参数,用于日志记录</param>
|
||
|
|
/// <returns>命令执行结果</returns>
|
||
|
|
protected async Task<CommandExecutionResult> ExecuteCommandAsync(string command, string operationName, object parameters = null)
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
var result = await _commandExecutor.ExecuteCommandAsync(command, new CancellationTokenSource());
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
// 这里可以添加通用的异常处理逻辑
|
||
|
|
throw new InvalidOperationException($"执行{operationName}命令时发生异常: {ex.Message}", ex);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 构建命令前缀
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="ranEndPoint">RAN 端点信息</param>
|
||
|
|
/// <returns>命令前缀</returns>
|
||
|
|
protected string BuildCommandPrefix(RanIPEndPoint ranEndPoint)
|
||
|
|
{
|
||
|
|
return $"{_appSettings.WebSocketJsPath} {ranEndPoint.ComAddr}";
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 验证RAN端点
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="ranEndPoint">RAN 端点信息</param>
|
||
|
|
/// <returns>是否有效</returns>
|
||
|
|
protected bool ValidateRanEndPoint(RanIPEndPoint ranEndPoint)
|
||
|
|
{
|
||
|
|
return ranEndPoint != null;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 设置 RAN 日志配置
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="ranEndPoint">RAN 端点信息</param>
|
||
|
|
/// <param name="enableBcch">是否启用BCCH日志</param>
|
||
|
|
/// <returns>是否成功设置配置</returns>
|
||
|
|
public abstract Task<bool> SetRanLogsConfigAsync(RanIPEndPoint ranEndPoint, bool enableBcch);
|
||
|
|
}
|