using CoreAgent.Domain.Interfaces.System.Command; using CoreAgent.Domain.Models.Network; using CoreAgent.Domain.Models.System; namespace CoreAgent.Domain.Interfaces.Network; /// /// RAN API 命令处理器基础接口 /// 负责处理各种RAN相关的API操作命令 /// public interface IRanAPICommandHandler { /// /// 设置 RAN 日志配置 /// /// RAN 端点信息 /// 是否启用BCCH日志 /// 是否成功设置配置 Task SetRanLogsConfigAsync(RanIPEndPoint ranEndPoint, bool enableBcch); } /// /// RAN API 命令处理器抽象基类 /// 提供通用的命令执行逻辑 /// 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)); } /// /// 执行命令的通用方法 /// /// 要执行的命令 /// 操作名称,用于日志记录 /// 操作参数,用于日志记录 /// 命令执行结果 protected async Task 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); } } /// /// 构建命令前缀 /// /// RAN 端点信息 /// 命令前缀 protected string BuildCommandPrefix(RanIPEndPoint ranEndPoint) { return $"{_appSettings.WebSocketJsPath} {ranEndPoint.ComAddr}"; } /// /// 验证RAN端点 /// /// RAN 端点信息 /// 是否有效 protected bool ValidateRanEndPoint(RanIPEndPoint ranEndPoint) { return ranEndPoint != null; } /// /// 设置 RAN 日志配置 /// /// RAN 端点信息 /// 是否启用BCCH日志 /// 是否成功设置配置 public abstract Task SetRanLogsConfigAsync(RanIPEndPoint ranEndPoint, bool enableBcch); }