diff --git a/src/X1.Application/Features/DeviceRuntimes/Commands/StartDeviceRuntime/StartDeviceRuntimeCommandHandler.cs b/src/X1.Application/Features/DeviceRuntimes/Commands/StartDeviceRuntime/StartDeviceRuntimeCommandHandler.cs index eab4d00..5ee5bdc 100644 --- a/src/X1.Application/Features/DeviceRuntimes/Commands/StartDeviceRuntime/StartDeviceRuntimeCommandHandler.cs +++ b/src/X1.Application/Features/DeviceRuntimes/Commands/StartDeviceRuntime/StartDeviceRuntimeCommandHandler.cs @@ -327,14 +327,14 @@ public class StartDeviceRuntimeCommandHandler : IRequestHandler { var deviceNetworkConfigs = networkConfigsByCode[deviceRequest.NetworkStackCode]; - - // 构建CoreNetworkImsConfiguration列表 - var coreNetworkImsConfigurations = deviceNetworkConfigs - .Where(s => !string.IsNullOrEmpty(s.IMSConfigContent) && !string.IsNullOrEmpty(s.CoreNetworkConfigContent)) - .Select(networkConfig => new CoreNetworkImsConfiguration - { - Index = networkConfig.Index ?? 0, - Plmn = "000000", + + // 构建CoreNetworkImsConfiguration列表 + var coreNetworkImsConfigurations = deviceNetworkConfigs + .Where(s => !string.IsNullOrEmpty(s.IMSConfigContent) && !string.IsNullOrEmpty(s.CoreNetworkConfigContent)) + .Select(networkConfig => new CoreNetworkImsConfiguration + { + Index = networkConfig.Index ?? 0, + Plmn = ExtractPlmnFromConfig(networkConfig.CoreNetworkConfigContent), CoreNetworkConfiguration = networkConfig.CoreNetworkConfigContent!, ImsServiceConfiguration = networkConfig.IMSConfigContent! }) @@ -445,4 +445,41 @@ public class StartDeviceRuntimeCommandHandler : IRequestHandler + /// 从网络配置中提取PLMN值 + /// + /// 网络配置内容 + /// 提取的PLMN值,如果未找到则返回默认值"000000" + private string ExtractPlmnFromConfig(string configContent) + { + if (string.IsNullOrEmpty(configContent)) + { + return "000000"; + } + + try + { + // 使用正则表达式匹配PLMN值(支持双引号和单引号) + var match = System.Text.RegularExpressions.Regex.Match( + configContent, + @"""plmn""\s*:\s*[""']([^""']+)[""']", + System.Text.RegularExpressions.RegexOptions.IgnoreCase); + + if (match.Success && match.Groups.Count > 1) + { + var plmnValue = match.Groups[1].Value.Trim(); + _logger.LogDebug("从配置中提取到PLMN值: {PlmnValue}", plmnValue); + return string.IsNullOrEmpty(plmnValue) ? "000000" : plmnValue; + } + + _logger.LogDebug("未从配置中找到PLMN值,使用默认值: 000000"); + return "000000"; + } + catch (Exception ex) + { + _logger.LogWarning(ex, "提取PLMN值时发生异常,使用默认值: 000000"); + return "000000"; + } + } +} \ No newline at end of file diff --git a/src/modify.md b/src/modify.md index 6f73a71..d304f6e 100644 --- a/src/modify.md +++ b/src/modify.md @@ -5801,4 +5801,41 @@ private static DeviceRuntimeDto MapToDto(CellularDeviceRuntime runtime) #### 3. 建议的长期改进 - **模型重构**: 考虑将 `CoreNetworkImsConfiguration` 改为单个对象而非集合 - **性能优化**: 避免不必要的集合创建和内存分配 -- **代码简化**: 简化对象创建和访问逻辑 \ No newline at end of file +- **代码简化**: 简化对象创建和访问逻辑 + +## 2025-01-29 - 修复StartDeviceRuntimeCommandHandler语法错误 + +### 修改原因 +在 `StartDeviceRuntimeCommandHandler.cs` 文件的第330行存在语法错误,包含不完整的注释和错误的代码,导致编译失败。 + +### 修改文件 +- `X1.Application/Features/DeviceRuntimes/Commands/StartDeviceRuntime/StartDeviceRuntimeCommandHandler.cs` - 修复语法错误 + +### 修改内容 + +#### 1. 修复语法错误 +- **删除错误代码**:移除第330行的不完整注释和错误代码 +- **修复PLMN提取**:将硬编码的 `Plmn = "000000"` 改为调用 `ExtractPlmnFromConfig` 方法 +- **添加PLMN提取方法**:实现从网络配置中提取PLMN值的功能 + +#### 2. 新增ExtractPlmnFromConfig方法 +- **功能**:从网络配置内容中提取PLMN值 +- **实现**:使用正则表达式匹配PLMN值 +- **错误处理**:包含完整的异常处理和日志记录 +- **默认值**:如果未找到PLMN值,返回默认值"000000" + +#### 3. 技术特性 +- **正则表达式匹配**:使用 `@"plmn""\s*:\s*[""']([^""']+)[""']` 模式匹配PLMN值(支持双引号和单引号) +- **大小写不敏感**:使用 `RegexOptions.IgnoreCase` 忽略大小写 +- **空值处理**:正确处理空配置内容的情况 +- **异常处理**:捕获正则表达式异常并提供友好的错误处理 + +### 业务价值 +- **数据准确性**:从实际配置中提取PLMN值,而不是使用硬编码值 +- **系统稳定性**:修复编译错误,确保系统正常运行 +- **代码质量**:提高代码的可维护性和健壮性 + +### 影响范围 +- **编译错误**:修复了导致编译失败的语法错误 +- **PLMN处理**:改进了PLMN值的提取和处理逻辑 +- **错误处理**:增强了异常处理和日志记录功能 \ No newline at end of file