1 changed files with 176 additions and 0 deletions
@ -0,0 +1,176 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using System.Linq; |
||||
|
|
||||
|
namespace CoreAgent.Domain.Entities |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 网络配置实体
|
||||
|
/// </summary>
|
||||
|
public class NetworkConfiguration : IValidatableObject |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 配置键值
|
||||
|
/// </summary>
|
||||
|
[Required(ErrorMessage = "配置键值不能为空")] |
||||
|
public string ConfigKey { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// RAN配置文件路径
|
||||
|
/// </summary>
|
||||
|
[Required(ErrorMessage = "RAN配置路径不能为空")] |
||||
|
public string RagConfig { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 核心网和IMS配置列表
|
||||
|
/// </summary>
|
||||
|
[Required(ErrorMessage = "核心网和IMS配置不能为空")] |
||||
|
[MinLength(1, ErrorMessage = "至少需要一个核心网和IMS配置")] |
||||
|
public List<CoreImsConfig> CoreOrImsConfigs { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// APN配置
|
||||
|
/// </summary>
|
||||
|
[Required(ErrorMessage = "APN配置不能为空")] |
||||
|
public string Apn { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 频段配置
|
||||
|
/// </summary>
|
||||
|
[Required(ErrorMessage = "频段配置不能为空")] |
||||
|
[MinLength(1, ErrorMessage = "至少需要一个频段配置")] |
||||
|
public List<string> Band { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 配置说明
|
||||
|
/// </summary>
|
||||
|
public string Comment { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 验证配置
|
||||
|
/// </summary>
|
||||
|
public IEnumerable<ValidationResult> 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 等格式"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 获取指定PLMN的配置
|
||||
|
/// </summary>
|
||||
|
public CoreImsConfig GetConfigByPlmn(string plmn) |
||||
|
{ |
||||
|
return CoreOrImsConfigs.FirstOrDefault(x => x.Plmn == plmn); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 获取指定索引的配置
|
||||
|
/// </summary>
|
||||
|
public CoreImsConfig GetConfigByIndex(int index) |
||||
|
{ |
||||
|
return CoreOrImsConfigs.FirstOrDefault(x => x.Index == index); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 验证配置文件是否存在
|
||||
|
/// </summary>
|
||||
|
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; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 核心网和IMS配置实体
|
||||
|
/// </summary>
|
||||
|
public class CoreImsConfig |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 配置索引
|
||||
|
/// </summary>
|
||||
|
[Required(ErrorMessage = "配置索引不能为空")] |
||||
|
[Range(1, int.MaxValue, ErrorMessage = "配置索引必须大于0")] |
||||
|
public int Index { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// PLMN码
|
||||
|
/// </summary>
|
||||
|
[Required(ErrorMessage = "PLMN码不能为空")] |
||||
|
[RegularExpression(@"^\d{5,6}$", ErrorMessage = "PLMN码必须是5-6位数字")] |
||||
|
public string Plmn { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 核心网配置文件路径
|
||||
|
/// </summary>
|
||||
|
[Required(ErrorMessage = "核心网配置路径不能为空")] |
||||
|
[RegularExpression(@"^Config/CoreNetwork/.*\.cfg$", ErrorMessage = "核心网配置路径格式不正确")] |
||||
|
public string CoreNetworkConfig { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// IMS配置文件路径
|
||||
|
/// </summary>
|
||||
|
[Required(ErrorMessage = "IMS配置路径不能为空")] |
||||
|
[RegularExpression(@"^Config/Ims/.*\.cfg$", ErrorMessage = "IMS配置路径格式不正确")] |
||||
|
public string ImsConfig { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 获取配置文件的完整路径
|
||||
|
/// </summary>
|
||||
|
public string GetFullCoreNetworkConfigPath() |
||||
|
{ |
||||
|
return System.IO.Path.GetFullPath(CoreNetworkConfig); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 获取IMS配置文件的完整路径
|
||||
|
/// </summary>
|
||||
|
public string GetFullImsConfigPath() |
||||
|
{ |
||||
|
return System.IO.Path.GetFullPath(ImsConfig); |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue