From 96f50b8881b4f81827c9835d0295c70f9c7c8b0c Mon Sep 17 00:00:00 2001 From: hyh Date: Wed, 11 Jun 2025 18:15:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=20NetworkConfigurati?= =?UTF-8?q?on=20=E5=AE=9E=E4=BD=93=E7=B1=BB=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E5=92=8C=E8=BE=85=E5=8A=A9=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/NetworkConfiguration.cs | 176 ++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 CoreAgent.Domain/Entities/NetworkConfiguration.cs diff --git a/CoreAgent.Domain/Entities/NetworkConfiguration.cs b/CoreAgent.Domain/Entities/NetworkConfiguration.cs new file mode 100644 index 0000000..1731b0a --- /dev/null +++ b/CoreAgent.Domain/Entities/NetworkConfiguration.cs @@ -0,0 +1,176 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; + +namespace CoreAgent.Domain.Entities +{ + /// + /// 网络配置实体 + /// + public class NetworkConfiguration : IValidatableObject + { + /// + /// 配置键值 + /// + [Required(ErrorMessage = "配置键值不能为空")] + public string ConfigKey { get; set; } + + /// + /// RAN配置文件路径 + /// + [Required(ErrorMessage = "RAN配置路径不能为空")] + public string RagConfig { get; set; } + + /// + /// 核心网和IMS配置列表 + /// + [Required(ErrorMessage = "核心网和IMS配置不能为空")] + [MinLength(1, ErrorMessage = "至少需要一个核心网和IMS配置")] + public List CoreOrImsConfigs { get; set; } + + /// + /// APN配置 + /// + [Required(ErrorMessage = "APN配置不能为空")] + public string Apn { get; set; } + + /// + /// 频段配置 + /// + [Required(ErrorMessage = "频段配置不能为空")] + [MinLength(1, ErrorMessage = "至少需要一个频段配置")] + public List Band { get; set; } + + /// + /// 配置说明 + /// + public string Comment { get; set; } + + /// + /// 验证配置 + /// + public IEnumerable Validate(ValidationContext validationContext) + { + // 验证PLMN是否重复 + var plmnGroups = CoreOrImsConfigs.GroupBy(x => x.Plmn); + foreach (var group in plmnGroups) + { + if (group.Count() > 1) + { + yield return new ValidationResult($"PLMN {group.Key} 重复配置"); + } + } + + // 验证索引是否连续 + var orderedConfigs = CoreOrImsConfigs.OrderBy(x => x.Index).ToList(); + for (int i = 0; i < orderedConfigs.Count; i++) + { + if (orderedConfigs[i].Index != i + 1) + { + yield return new ValidationResult($"配置索引不连续,期望 {i + 1},实际 {orderedConfigs[i].Index}"); + } + } + + // 验证频段格式 + foreach (var band in Band) + { + if (!band.StartsWith("B") || !int.TryParse(band.Substring(1), out _)) + { + yield return new ValidationResult($"频段格式不正确: {band},应为 B1、B2 等格式"); + } + } + } + + /// + /// 获取指定PLMN的配置 + /// + public CoreImsConfig GetConfigByPlmn(string plmn) + { + return CoreOrImsConfigs.FirstOrDefault(x => x.Plmn == plmn); + } + + /// + /// 获取指定索引的配置 + /// + public CoreImsConfig GetConfigByIndex(int index) + { + return CoreOrImsConfigs.FirstOrDefault(x => x.Index == index); + } + + /// + /// 验证配置文件是否存在 + /// + public bool ValidateConfigFiles() + { + if (!System.IO.File.Exists(RagConfig)) + { + throw new InvalidOperationException($"RAN配置文件不存在: {RagConfig}"); + } + + foreach (var config in CoreOrImsConfigs) + { + if (!System.IO.File.Exists(config.CoreNetworkConfig)) + { + throw new InvalidOperationException($"核心网配置文件不存在: {config.CoreNetworkConfig}"); + } + if (!System.IO.File.Exists(config.ImsConfig)) + { + throw new InvalidOperationException($"IMS配置文件不存在: {config.ImsConfig}"); + } + } + + return true; + } + } + + /// + /// 核心网和IMS配置实体 + /// + public class CoreImsConfig + { + /// + /// 配置索引 + /// + [Required(ErrorMessage = "配置索引不能为空")] + [Range(1, int.MaxValue, ErrorMessage = "配置索引必须大于0")] + public int Index { get; set; } + + /// + /// PLMN码 + /// + [Required(ErrorMessage = "PLMN码不能为空")] + [RegularExpression(@"^\d{5,6}$", ErrorMessage = "PLMN码必须是5-6位数字")] + public string Plmn { get; set; } + + /// + /// 核心网配置文件路径 + /// + [Required(ErrorMessage = "核心网配置路径不能为空")] + [RegularExpression(@"^Config/CoreNetwork/.*\.cfg$", ErrorMessage = "核心网配置路径格式不正确")] + public string CoreNetworkConfig { get; set; } + + /// + /// IMS配置文件路径 + /// + [Required(ErrorMessage = "IMS配置路径不能为空")] + [RegularExpression(@"^Config/Ims/.*\.cfg$", ErrorMessage = "IMS配置路径格式不正确")] + public string ImsConfig { get; set; } + + /// + /// 获取配置文件的完整路径 + /// + public string GetFullCoreNetworkConfigPath() + { + return System.IO.Path.GetFullPath(CoreNetworkConfig); + } + + /// + /// 获取IMS配置文件的完整路径 + /// + public string GetFullImsConfigPath() + { + return System.IO.Path.GetFullPath(ImsConfig); + } + } +} \ No newline at end of file