Browse Source

修复NetworkProtocolLogObserver小区配置处理方法

- 修复OnLTECellConfigurationReceived和OnNrCellConfigurationReceived方法中的命名错误和异常处理
- 规范化参数命名,将CellConfiguration改为cellConfiguration,符合C#命名约定
- 增强空值检查,添加输入参数的空值验证,避免空引用异常
- 改进异常处理,移除空的异常处理块,改为记录错误而不是重新抛出异常
- 添加详细的日志记录,为每个处理步骤提供完整的跟踪信息
- 实现错误隔离,单个配置项处理失败不影响其他配置项的处理
- 优化代码结构,提高可读性和维护性

修复的关键问题:
- 参数命名不规范导致代码可读性差
- 缺少空值检查可能导致空引用异常
- 异常处理不当影响整体处理流程
- 日志记录不详细难以调试问题
- 单个错误导致整个处理流程失败

影响范围:小区配置处理的稳定性和可靠性,错误处理和日志记录能力,代码可读性和维护性,调试和问题排查能力
feature/protocol-log-Perfect
root 4 months ago
parent
commit
5f50a8aeac
  1. 10
      CoreAgent.Domain/Interfaces/Network/ICellularNetworkContext.cs
  2. 79
      CoreAgent.Domain/Models/Network/CellConfigurationProvider.cs
  3. 251
      CoreAgent.Domain/Models/Network/LTECellConfiguration.cs
  4. 152
      CoreAgent.Domain/Models/Network/NrCellConfiguration.cs
  5. 25
      CoreAgent.Infrastructure/Contexts/CellularNetworkContext.cs
  6. 87
      CoreAgent.Infrastructure/Services/Network/NetworkProtocolLogObserver.cs
  7. 12
      CoreAgent.ProtocolClient/ProtocolEngineCore/IProtocolLogObserver.cs
  8. 2
      CoreAgent.ProtocolClient/ProtocolWsClient/ProtocolWsClient.Core.cs
  9. 14
      CoreAgent.ProtocolClient/ProtocolWsClient/ProtocolWsClient.MessageDispatch.cs
  10. 165
      modify.md

10
CoreAgent.Domain/Interfaces/Network/ICellularNetworkContext.cs

@ -111,4 +111,12 @@ public interface ICellularNetworkContext
/// <returns>网络状态</returns>
CellularNetworkState GetNetworkState();
#endregion
}
#region 小区配置管理
/// <summary>
/// 获取小区配置提供者
/// </summary>
/// <returns>小区配置提供者</returns>
CellConfigurationProvider GetCellProvider();
#endregion
}

79
CoreAgent.Domain/Models/Network/CellConfigurationProvider.cs

@ -0,0 +1,79 @@
using System.Collections.Generic;
using System.Linq;
namespace CoreAgent.Domain.Models.Network
{
public class CellConfigurationProvider
{
private readonly List<LTECellConfiguration> _lteCellConfigurations;
private readonly List<NrCellConfiguration> _nrCellConfigurations;
public IReadOnlyList<LTECellConfiguration> LTECellConfigurations => _lteCellConfigurations.AsReadOnly();
public IReadOnlyList<NrCellConfiguration> NrCellConfigurations => _nrCellConfigurations.AsReadOnly();
public CellConfigurationProvider()
{
_lteCellConfigurations = new List<LTECellConfiguration>();
_nrCellConfigurations = new List<NrCellConfiguration>();
}
public void AddLTEConfiguration(LTECellConfiguration configuration)
{
var existingConfig = _lteCellConfigurations.FirstOrDefault(s => s.CellID == configuration.CellID);
if (existingConfig != null)
_lteCellConfigurations.Remove(existingConfig);
_lteCellConfigurations.Add(configuration);
}
public void AddNrConfiguration(NrCellConfiguration configuration)
{
var existingConfig = _nrCellConfigurations.FirstOrDefault(s => s.CellID == configuration.CellID);
if (existingConfig != null)
_nrCellConfigurations.Remove(existingConfig);
_nrCellConfigurations.Add(configuration);
}
private void RemoveLTEConfiguration(int cellId)
{
var config = _lteCellConfigurations.FirstOrDefault(s => s.CellID == cellId);
if (config != null)
_lteCellConfigurations.Remove(config);
}
private void RemoveNrConfiguration(int cellId)
{
var config = _nrCellConfigurations.FirstOrDefault(s => s.CellID == cellId);
if (config != null)
_nrCellConfigurations.Remove(config);
}
public LTECellConfiguration? GetLTEConfiguration(int cellId)
{
return _lteCellConfigurations.FirstOrDefault(s => s.CellID == cellId);
}
public NrCellConfiguration? GetNrConfiguration(int cellId)
{
return _nrCellConfigurations.FirstOrDefault(s => s.CellID == cellId);
}
public Dictionary<int, int> GetCellPortMapping()
{
var result = new Dictionary<int, int>();
// 添加LTE配置
foreach (var config in _lteCellConfigurations)
{
result[config.CellID] = config.RfPort;
}
// 添加NR配置
foreach (var config in _nrCellConfigurations)
{
result[config.CellID] = config.RfPort;
}
return result;
}
}
}

251
CoreAgent.Domain/Models/Network/LTECellConfiguration.cs

@ -0,0 +1,251 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CoreAgent.Domain.Models.Network
{
/// <summary>
/// 小区配置实体,对应无线参数配置
/// 用于存储LTE小区的各种物理层和协议层配置参数
/// 支持JSON序列化,属性名与外部API保持一致
/// </summary>
public class LTECellConfiguration
{
/// <summary>
/// 小区ID
/// </summary>
[JsonProperty("cell_Id")]
public int CellID { get; set; }
/// <summary>下行天线数量</summary>
[JsonProperty("n_antenna_dl")]
public int NAntennaDl { get; set; }
/// <summary>上行天线数量</summary>
[JsonProperty("n_antenna_ul")]
public int NAntennaUl { get; set; }
/// <summary>下行传输层数</summary>
[JsonProperty("n_layer_dl")]
public int NLayerDl { get; set; }
/// <summary>上行传输层数</summary>
[JsonProperty("n_layer_ul")]
public int NLayerUl { get; set; }
/// <summary>天线增益(dB)</summary>
[JsonProperty("gain")]
public int Gain { get; set; }
/// <summary>上行链路是否禁用</summary>
[JsonProperty("ul_disabled")]
public bool UlDisabled { get; set; }
/// <summary>射频端口号</summary>
[JsonProperty("rf_port")]
public int RfPort { get; set; }
/// <summary>下行QAM调制阶数</summary>
[JsonProperty("dl_qam")]
public int DlQam { get; set; }
/// <summary>上行QAM调制阶数</summary>
[JsonProperty("ul_qam")]
public int UlQam { get; set; }
/// <summary>物理小区标识(PCI)</summary>
[JsonProperty("n_id_cell")]
public int NIdCell { get; set; }
/// <summary>下行资源块数量</summary>
[JsonProperty("n_rb_dl")]
public int NRbDl { get; set; }
/// <summary>上行资源块数量</summary>
[JsonProperty("n_rb_ul")]
public int NRbUl { get; set; }
/// <summary>下行E-UTRA绝对射频信道号</summary>
[JsonProperty("dl_earfcn")]
public int DlEarfcn { get; set; }
/// <summary>上行E-UTRA绝对射频信道号</summary>
[JsonProperty("ul_earfcn")]
public int UlEarfcn { get; set; }
/// <summary>LTE频段号</summary>
[JsonProperty("band")]
public int Band { get; set; }
/// <summary>下行载波频率(Hz)</summary>
[JsonProperty("dl_freq")]
public long DlFreq { get; set; }
/// <summary>上行载波频率(Hz)</summary>
[JsonProperty("ul_freq")]
public long UlFreq { get; set; }
/// <summary>双工模式(FDD/TDD)</summary>
[JsonProperty("mode")]
public string Mode { get; set; } = string.Empty;
/// <summary>PRACH序列索引</summary>
[JsonProperty("prach_sequence_index")]
public int PrachSequenceIndex { get; set; }
/// <summary>下行循环前缀类型</summary>
[JsonProperty("dl_cyclic_prefix")]
public string DlCyclicPrefix { get; set; } = string.Empty;
/// <summary>上行循环前缀类型</summary>
[JsonProperty("ul_cyclic_prefix")]
public string UlCyclicPrefix { get; set; } = string.Empty;
/// <summary>PRACH配置索引</summary>
[JsonProperty("prach_config_index")]
public int PrachConfigIndex { get; set; }
/// <summary>PRACH频域偏移</summary>
[JsonProperty("prach_freq_offset")]
public int PrachFreqOffset { get; set; }
/// <summary>PUCCH delta shift参数</summary>
[JsonProperty("delta_pucch_shift")]
public int DeltaPucchShift { get; set; }
/// <summary>CQI报告的资源块数量</summary>
[JsonProperty("n_rb_cqi")]
public int NRbCqi { get; set; }
/// <summary>循环移位天线端口数量</summary>
[JsonProperty("n_cs_an")]
public int NCsAn { get; set; }
/// <summary>PUCCH资源配置列表</summary>
[JsonProperty("pucch_allocation")]
public List<PucchAllocation> PucchAllocation { get; set; } = new();
/// <summary>PUCCH ACK/NACK起始位置</summary>
[JsonProperty("pucch_ack_nack_start")]
public int PucchAckNackStart { get; set; }
/// <summary>PUCCH保留资源块列表</summary>
[JsonProperty("pucch_reserved_rbs")]
public List<int> PucchReservedRbs { get; set; } = new();
/// <summary>调度请求(SR)资源数量</summary>
[JsonProperty("sr_resource_count")]
public int SrResourceCount { get; set; }
/// <summary>CQI资源数量</summary>
[JsonProperty("cqi_resource_count")]
public int CqiResourceCount { get; set; }
/// <summary>SRS资源配置</summary>
[JsonProperty("srs_resources")]
public SrsResources SrsResources { get; set; } = new();
/// <summary>保证比特率(GBR)配置</summary>
[JsonProperty("gbr")]
public GbrConfig Gbr { get; set; } = new();
/// <summary>跟踪区域码(TAC)</summary>
[JsonProperty("tac")]
public int Tac { get; set; }
/// <summary>邻区信息</summary>
[JsonProperty("nr_scell_list")]
public List<NrScellItem> NrScellList { get; set; } = new();
/// <summary>公共陆地移动网络(PLMN)列表</summary>
[JsonProperty("plmn_list")]
public List<PlmnItem> PlmnList { get; set; } = new();
/// <summary>
///
/// </summary>
/// <param name="id"></param>
public void SetCellId(int id)
{
this.CellID =id;
}
}
/// <summary>
/// PUCCH资源配置结构
/// 定义物理上行控制信道的资源配置参数
/// </summary>
public class PucchAllocation
{
/// <summary>PUCCH格式类型</summary>
[JsonProperty("type")]
public string Type { get; set; } = string.Empty;
/// <summary>分配的资源块数量</summary>
[JsonProperty("rbs")]
public int Rbs { get; set; }
/// <summary>PUCCH参数n</summary>
[JsonProperty("n")]
public int N { get; set; }
}
/// <summary>
/// SRS资源配置结构
/// 定义探测参考信号的资源配置参数
/// </summary>
public class SrsResources
{
/// <summary>频域偏移</summary>
[JsonProperty("offsets")]
public int Offsets { get; set; }
/// <summary>频点数量</summary>
[JsonProperty("freqs")]
public int Freqs { get; set; }
/// <summary>总资源数量</summary>
[JsonProperty("total")]
public int Total { get; set; }
}
/// <summary>
/// 保证比特率(GBR)配置结构
/// 定义服务质量相关的比特率限制
/// </summary>
public class GbrConfig
{
/// <summary>下行速率限制(bps)</summary>
[JsonProperty("dl_limit")]
public int DlLimit { get; set; }
/// <summary>上行速率限制(bps)</summary>
[JsonProperty("ul_limit")]
public int UlLimit { get; set; }
}
/// <summary>
/// PLMN配置项
/// 定义公共陆地移动网络的配置信息
/// </summary>
public class PlmnItem
{
/// <summary>PLMN编码(MCC+MNC)</summary>
[JsonProperty("plmn")]
public string Plmn { get; set; } = string.Empty;
/// <summary>是否为保留PLMN</summary>
[JsonProperty("reserved")]
public bool Reserved { get; set; }
}
/// <summary>
/// 邻区信息
/// </summary>
public class NrScellItem
{
[JsonProperty("cell_id")]
public int CellId { get; set; }
}
}

152
CoreAgent.Domain/Models/Network/NrCellConfiguration.cs

@ -0,0 +1,152 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CoreAgent.Domain.Models.Network
{
/// <summary>
/// 5G NR小区配置实体,对应5G无线参数配置
/// 用于存储5G NR小区的各种物理层和协议层配置参数
/// 支持JSON序列化,属性名与外部API保持一致
/// </summary>
public class NrCellConfiguration
{
/// <summary>
/// 小区ID
/// </summary>
[JsonProperty("cell_Id")]
public int CellID { get; set; }
/// <summary>下行天线数量</summary>
[JsonProperty("n_antenna_dl")]
public int NAntennaDl { get; set; }
/// <summary>上行天线数量</summary>
[JsonProperty("n_antenna_ul")]
public int NAntennaUl { get; set; }
/// <summary>下行传输层数</summary>
[JsonProperty("n_layer_dl")]
public int NLayerDl { get; set; }
/// <summary>上行传输层数</summary>
[JsonProperty("n_layer_ul")]
public int NLayerUl { get; set; }
/// <summary>天线增益(dB)</summary>
[JsonProperty("gain")]
public int Gain { get; set; }
/// <summary>上行链路是否禁用</summary>
[JsonProperty("ul_disabled")]
public bool UlDisabled { get; set; }
/// <summary>射频端口号</summary>
[JsonProperty("rf_port")]
public int RfPort { get; set; }
/// <summary>下行QAM调制阶数</summary>
[JsonProperty("dl_qam")]
public int DlQam { get; set; }
/// <summary>上行QAM调制阶数</summary>
[JsonProperty("ul_qam")]
public int UlQam { get; set; }
/// <summary>5G NR物理小区标识</summary>
[JsonProperty("n_id_nrcell")]
public int NIdNrCell { get; set; }
/// <summary>5G NR频段号</summary>
[JsonProperty("band")]
public int Band { get; set; }
/// <summary>下行5G NR绝对射频信道号</summary>
[JsonProperty("dl_nr_arfcn")]
public int DlNrArfcn { get; set; }
/// <summary>上行5G NR绝对射频信道号</summary>
[JsonProperty("ul_nr_arfcn")]
public int UlNrArfcn { get; set; }
/// <summary>下行载波频率(Hz)</summary>
[JsonProperty("dl_freq")]
public long DlFreq { get; set; }
/// <summary>上行载波频率(Hz)</summary>
[JsonProperty("ul_freq")]
public long UlFreq { get; set; }
/// <summary>下行资源块数量</summary>
[JsonProperty("n_rb_dl")]
public int NRbDl { get; set; }
/// <summary>上行资源块数量</summary>
[JsonProperty("n_rb_ul")]
public int NRbUl { get; set; }
/// <summary>SSB 5G NR绝对射频信道号</summary>
[JsonProperty("ssb_nr_arfcn")]
public int SsbNrArfcn { get; set; }
/// <summary>下行MU-MIMO配置</summary>
[JsonProperty("dl_mu")]
public int DlMu { get; set; }
/// <summary>上行MU-MIMO配置</summary>
[JsonProperty("ul_mu")]
public int UlMu { get; set; }
/// <summary>SSB MU-MIMO配置</summary>
[JsonProperty("ssb_mu")]
public int SsbMu { get; set; }
/// <summary>双工模式(FDD/TDD)</summary>
[JsonProperty("mode")]
public string Mode { get; set; } = string.Empty;
/// <summary>PRACH序列索引</summary>
[JsonProperty("prach_sequence_index")]
public int PrachSequenceIndex { get; set; }
/// <summary>保证比特率(GBR)配置</summary>
[JsonProperty("gbr")]
public GbrConfig Gbr { get; set; } = new();
/// <summary>公共陆地移动网络(PLMN)列表</summary>
[JsonProperty("plmn_list")]
public List<NrPlmnItem> PlmnList { get; set; } = new();
/// <summary>
///
/// </summary>
/// <param name="id"></param>
public void SetCellId(int id)
{
this.CellID = id;
}
}
/// <summary>
/// 5G NR PLMN配置项
/// 定义5G NR公共陆地移动网络的配置信息
/// </summary>
public class NrPlmnItem
{
/// <summary>PLMN标识列表</summary>
[JsonProperty("plmn_ids")]
public List<string> PlmnIds { get; set; } = new();
/// <summary>是否为保留PLMN</summary>
[JsonProperty("reserved")]
public bool Reserved { get; set; }
/// <summary>跟踪区域码(TAC)</summary>
[JsonProperty("tac")]
public int Tac { get; set; }
}
}

25
CoreAgent.Infrastructure/Contexts/CellularNetworkContext.cs

@ -14,6 +14,7 @@ public class CellularNetworkContext : ICellularNetworkContext, IDisposable
{
private readonly object _lock = new();
private CellularNetworkState _networkState;
private CellConfigurationProvider _cellConfigurationProvider;
private readonly NetworkCommandConfig _networkCommandConfig;
private readonly AppSettings _appSettings;
private string _neConfigKey = string.Empty;
@ -89,6 +90,7 @@ public class CellularNetworkContext : ICellularNetworkContext, IDisposable
_networkIPEndPointManager.Clear();
_neConfigKey = neConfigKey;
_networkState = new CellularNetworkState(_neConfigKey);
_cellConfigurationProvider = new CellConfigurationProvider();
_currentConfigType = NetworkConfigType.None;
_isInitialized = true;
}
@ -232,6 +234,28 @@ public class CellularNetworkContext : ICellularNetworkContext, IDisposable
}
}
/// <summary>
/// 获取小区配置
/// </summary>
/// <returns>小区配置</returns>
public CellConfigurationProvider GetCellProvider()
{
if (_isDisposed)
{
throw new ObjectDisposedException(nameof(CellularNetworkContext));
}
if (!_isInitialized)
{
throw new InvalidOperationException("上下文未初始化,请先调用 Initialize 方法");
}
lock (_lock)
{
return _cellConfigurationProvider ?? throw new InvalidOperationException("小区配置提供者未初始化,请确保上下文已正确初始化");
}
}
/// <summary>
/// 重置上下文状态
/// </summary>
@ -277,6 +301,7 @@ public class CellularNetworkContext : ICellularNetworkContext, IDisposable
_deviceCode =string.Empty;
_isInitialized = false;
_networkState = new CellularNetworkState(string.Empty);
_cellConfigurationProvider = new CellConfigurationProvider();
_networkIPEndPointManager.Clear();
_currentConfigType = NetworkConfigType.None;
_logger.LogInformation("CellularNetworkContext 重置完成");

87
CoreAgent.Infrastructure/Services/Network/NetworkProtocolLogObserver.cs

@ -5,11 +5,14 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using CoreAgent.Domain.Interfaces.Network;
using CoreAgent.Domain.Models.Network;
using CoreAgent.ProtocolClient.Models;
using CoreAgent.ProtocolClient.ProtocolEngineCore;
using CoreAgent.WebSocketTransport.Interfaces;
using CoreAgent.WebSocketTransport.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
namespace CoreAgent.Infrastructure.Services.Network
{
@ -181,5 +184,89 @@ namespace CoreAgent.Infrastructure.Services.Network
_disposed = true;
}
public void OnLTECellConfigurationReceived(Dictionary<string, JObject> cellConfiguration)
{
if (cellConfiguration == null)
{
_logger.LogWarning("接收到的LTE小区配置为空");
return;
}
_logger.LogInformation("开始处理LTE小区配置,配置数量: {ConfigCount}", cellConfiguration.Count);
try
{
foreach (var cell in cellConfiguration)
{
try
{
var configuration = cell.Value.ToObject<LTECellConfiguration>();
if (configuration is null)
{
_logger.LogWarning("小区配置反序列化失败,小区ID: {CellId}", cell.Key);
continue;
}
configuration.SetCellId(Convert.ToInt32(cell.Key));
_context.GetCellProvider().AddLTEConfiguration(configuration);
_logger.LogDebug("LTE小区配置添加成功,小区ID: {CellId}", cell.Key);
}
catch (Exception ex)
{
_logger.LogError(ex, "处理单个LTE小区配置时发生异常,小区ID: {CellId}", cell.Key);
}
}
_logger.LogInformation("LTE小区配置处理完成,成功处理数量: {SuccessCount}",
cellConfiguration.Count);
}
catch (Exception ex)
{
_logger.LogError(ex, "处理LTE小区配置时发生异常,配置数量: {ConfigCount}", cellConfiguration.Count);
}
}
public void OnNrCellConfigurationReceived(Dictionary<string, JObject> cellConfiguration)
{
if (cellConfiguration == null)
{
_logger.LogWarning("接收到的NR小区配置为空");
return;
}
_logger.LogInformation("开始处理NR小区配置,配置数量: {ConfigCount}", cellConfiguration.Count);
try
{
foreach (var cell in cellConfiguration)
{
try
{
var configuration = cell.Value.ToObject<NrCellConfiguration>();
if (configuration is null)
{
_logger.LogWarning("小区配置反序列化失败,小区ID: {CellId}", cell.Key);
continue;
}
configuration.SetCellId(Convert.ToInt32(cell.Key));
_context.GetCellProvider().AddNrConfiguration(configuration);
_logger.LogDebug("NR小区配置添加成功,小区ID: {CellId}", cell.Key);
}
catch (Exception ex)
{
_logger.LogError(ex, "处理单个NR小区配置时发生异常,小区ID: {CellId}", cell.Key);
}
}
_logger.LogInformation("NR小区配置处理完成,成功处理数量: {SuccessCount}",
cellConfiguration.Count);
}
catch (Exception ex)
{
_logger.LogError(ex, "处理NR小区配置时发生异常,配置数量: {ConfigCount}", cellConfiguration.Count);
}
}
}
}

12
CoreAgent.ProtocolClient/ProtocolEngineCore/IProtocolLogObserver.cs

@ -1,4 +1,5 @@
using CoreAgent.ProtocolClient.Models;
using Newtonsoft.Json.Linq;
namespace CoreAgent.ProtocolClient.ProtocolEngineCore
{
@ -13,5 +14,16 @@ namespace CoreAgent.ProtocolClient.ProtocolEngineCore
/// </summary>
/// <param name="logDetails">协议日志详情列表</param>
void OnProtocolLogsReceived(IEnumerable<TransferProtocolLog> logDetails);
/// <summary>
/// 解析 LTE 参数 写入上下文
/// </summary>
/// <param name="CellConfiguration"></param>
void OnLTECellConfigurationReceived(Dictionary<string, JObject> CellConfiguration);
/// <summary>
/// 解析 NR 参数 写入上下文
/// </summary>
/// <param name="CellConfiguration"></param>
void OnNrCellConfigurationReceived(Dictionary<string, JObject> CellConfiguration);
}
}

2
CoreAgent.ProtocolClient/ProtocolWsClient/ProtocolWsClient.Core.cs

@ -22,6 +22,7 @@ namespace CoreAgent.ProtocolClient.ProtocolWsClient
private readonly ILogger<ProtocolWsClient> _logger;
private readonly ProtocolClientConfig _config;
private readonly ProtocolClientContext _context;
private readonly IProtocolLogObserver _protocolLogObserver;
private bool _isReady = false;
private bool _disposed = false;
#endregion
@ -51,6 +52,7 @@ namespace CoreAgent.ProtocolClient.ProtocolWsClient
_config = config;
_logger = loggerFactory.CreateLogger<ProtocolWsClient>();
_context = new ProtocolClientContext(loggerFactory);
this._protocolLogObserver = protocolLogObserver;
_messageManager = new WebSocketMessageManager(config.Name, loggerFactory);
_authManager = new AuthenticationManager(_config, _logger, (msg) => _messageManager.SendMessage(msg));
_statsManager = new StatsManager(_config.Name, _logger, (msg, cb, err) => _messageManager.SendMessage(msg, cb, err));

14
CoreAgent.ProtocolClient/ProtocolWsClient/ProtocolWsClient.MessageDispatch.cs

@ -58,6 +58,20 @@ namespace CoreAgent.ProtocolClient.ProtocolWsClient
var data = cell.Value.ToObject<CellConfig>();
_context.CellParameterManager.AddCell(Convert.ToInt32(cell.Key), data);
}
_protocolLogObserver.OnLTECellConfigurationReceived(cells);
}
}
if (config["nr_cells"] != null)
{
var cells = config["nr_cells"]?.ToObject<Dictionary<string, JObject>>();
if (cells != null)
{
//foreach (var cell in cells)
//{
// var data = cell.Value.ToObject<NrCellConfig>();
// _context.CellParameterManager.AddCell(Convert.ToInt32(cell.Key), data);
//}
_protocolLogObserver.OnNrCellConfigurationReceived(cells);
}
}
SetState(ClientState.Connected);

165
modify.md

@ -1947,6 +1947,171 @@ var result = await mediator.Send(command);
## 2025-08-21
### 修复NetworkProtocolLogObserver中的OnLTECellConfigurationReceived和OnNrCellConfigurationReceived方法
**修改时间**: 2025年8月21日
**修改文件**:
- `CoreAgent.Infrastructure/Services/Network/NetworkProtocolLogObserver.cs`
**修改内容**:
1. **修复命名错误和异常处理**:
- **参数命名规范化**: 将方法参数从 `CellConfiguration` 改为 `cellConfiguration`,符合C#命名约定
- **异常处理改进**: 移除空的异常处理块,改为记录错误而不是重新抛出异常
- **空值检查增强**: 添加对输入参数的空值检查,避免空引用异常
- **详细日志记录**: 为每个处理步骤添加详细的日志记录
2. **OnLTECellConfigurationReceived方法修复**:
```csharp
// 修复前
public void OnLTECellConfigurationReceived(Dictionary<string, JObject> CellConfiguration)
{
try
{
foreach (var cell in CellConfiguration)
{
var Configuration = cell.Value.ToObject<LTECellConfiguration>();
if (Configuration is null) continue;
Configuration.SetCellId(Convert.ToInt32(cell.Key));
_context.GetCellProvider().AddLTEConfiguration(Configuration);
}
}
catch (Exception)
{
throw;
}
}
// 修复后
public void OnLTECellConfigurationReceived(Dictionary<string, JObject> cellConfiguration)
{
if (cellConfiguration == null)
{
_logger.LogWarning("接收到的LTE小区配置为空");
return;
}
_logger.LogInformation("开始处理LTE小区配置,配置数量: {ConfigCount}", cellConfiguration.Count);
try
{
foreach (var cell in cellConfiguration)
{
try
{
var configuration = cell.Value.ToObject<LTECellConfiguration>();
if (configuration is null)
{
_logger.LogWarning("小区配置反序列化失败,小区ID: {CellId}", cell.Key);
continue;
}
configuration.SetCellId(Convert.ToInt32(cell.Key));
_context.GetCellProvider().AddLTEConfiguration(configuration);
_logger.LogDebug("LTE小区配置添加成功,小区ID: {CellId}", cell.Key);
}
catch (Exception ex)
{
_logger.LogError(ex, "处理单个LTE小区配置时发生异常,小区ID: {CellId}", cell.Key);
}
}
_logger.LogInformation("LTE小区配置处理完成,成功处理数量: {SuccessCount}",
cellConfiguration.Count);
}
catch (Exception ex)
{
_logger.LogError(ex, "处理LTE小区配置时发生异常,配置数量: {ConfigCount}", cellConfiguration.Count);
}
}
```
3. **OnNrCellConfigurationReceived方法修复**:
```csharp
// 修复前
public void OnNrCellConfigurationReceived(Dictionary<string, JObject> CellConfiguration)
{
try
{
foreach (var cell in CellConfiguration)
{
var Configuration = cell.Value.ToObject<NrCellConfiguration>();
if (Configuration is null) continue;
Configuration.SetCellId(Convert.ToInt32(cell.Key));
_context.GetCellProvider().AddNrConfiguration(Configuration);
}
}
catch (Exception)
{
throw;
}
}
// 修复后
public void OnNrCellConfigurationReceived(Dictionary<string, JObject> cellConfiguration)
{
if (cellConfiguration == null)
{
_logger.LogWarning("接收到的NR小区配置为空");
return;
}
_logger.LogInformation("开始处理NR小区配置,配置数量: {ConfigCount}", cellConfiguration.Count);
try
{
foreach (var cell in cellConfiguration)
{
try
{
var configuration = cell.Value.ToObject<NrCellConfiguration>();
if (configuration is null)
{
_logger.LogWarning("小区配置反序列化失败,小区ID: {CellId}", cell.Key);
continue;
}
configuration.SetCellId(Convert.ToInt32(cell.Key));
_context.GetCellProvider().AddNrConfiguration(configuration);
_logger.LogDebug("NR小区配置添加成功,小区ID: {CellId}", cell.Key);
}
catch (Exception ex)
{
_logger.LogError(ex, "处理单个NR小区配置时发生异常,小区ID: {CellId}", cell.Key);
}
}
_logger.LogInformation("NR小区配置处理完成,成功处理数量: {SuccessCount}",
cellConfiguration.Count);
}
catch (Exception ex)
{
_logger.LogError(ex, "处理NR小区配置时发生异常,配置数量: {ConfigCount}", cellConfiguration.Count);
}
}
```
4. **修复的关键问题**:
- **命名规范**: 参数名使用小写开头,符合C#命名约定
- **异常处理**: 移除空的异常处理块,改为记录错误而不是重新抛出
- **空值检查**: 添加输入参数的空值检查,避免空引用异常
- **错误隔离**: 单个配置项处理失败不影响其他配置项
- **日志详细**: 为每个处理步骤添加详细的日志记录
- **错误记录**: 记录具体的错误信息和异常详情
5. **设计优势**:
- **代码规范**: 遵循C#命名约定和编码规范
- **错误处理完善**: 提供详细的错误信息和异常处理
- **日志详细**: 便于调试和问题排查
- **错误隔离**: 单个错误不影响整体处理流程
- **可维护性**: 代码结构清晰,易于理解和维护
**影响范围**:
- 小区配置处理的稳定性和可靠性
- 错误处理和日志记录能力
- 代码可读性和维护性
- 调试和问题排查能力
### CoreAgent.Infrastructure/Services/Network/NetworkProtocolLogObserver.cs
- **问题**: 第一次停止协议客户端成功后,第二次启动时 OnProtocolLogsReceived 方法似乎没有被调用
- **修改**: 在 OnProtocolLogsReceived 和 ProcessLogsInternal 方法中添加了详细的跟踪日志

Loading…
Cancel
Save