You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
196 lines
6.3 KiB
196 lines
6.3 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace CoreAgent.Domain.Entities
|
|
{
|
|
/// <summary>
|
|
/// 网络配置聚合根
|
|
/// </summary>
|
|
public class NetworkConfiguration : IValidatableObject
|
|
{
|
|
/// <summary>
|
|
/// 配置键值
|
|
/// </summary>
|
|
[Required(ErrorMessage = "配置键值不能为空")]
|
|
[JsonPropertyName("configKey")]
|
|
public string ConfigKey { get; set; }
|
|
|
|
/// <summary>
|
|
/// RAN配置文件路径
|
|
/// </summary>
|
|
[Required(ErrorMessage = "RAN配置路径不能为空")]
|
|
[JsonPropertyName("ragConfig")]
|
|
public string RagConfig { get; set; }
|
|
|
|
/// <summary>
|
|
/// 核心网和IMS配置列表
|
|
/// </summary>
|
|
[JsonPropertyName("coreOrImsConfigs")]
|
|
public List<CoreImsConfig> CoreOrImsConfigs { get; set; }
|
|
|
|
/// <summary>
|
|
/// APN配置
|
|
/// </summary>
|
|
[Required(ErrorMessage = "APN配置不能为空")]
|
|
[JsonPropertyName("apn")]
|
|
public string Apn { get; set; }
|
|
|
|
/// <summary>
|
|
/// 频段配置
|
|
/// </summary>
|
|
[Required(ErrorMessage = "频段配置不能为空")]
|
|
[MinLength(1, ErrorMessage = "至少需要一个频段配置")]
|
|
[JsonPropertyName("band")]
|
|
public List<string> Band { get; set; }
|
|
|
|
/// <summary>
|
|
/// 配置说明
|
|
/// </summary>
|
|
[JsonPropertyName("comment")]
|
|
public string Comment { get; set; }
|
|
|
|
/// <summary>
|
|
/// 构造函数
|
|
/// </summary>
|
|
[JsonConstructor]
|
|
public NetworkConfiguration()
|
|
{
|
|
CoreOrImsConfigs = new List<CoreImsConfig>();
|
|
Band = new List<string>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建新的网络配置
|
|
/// </summary>
|
|
public static NetworkConfiguration Create(
|
|
string configKey,
|
|
string ragConfig,
|
|
List<CoreImsConfig> coreOrImsConfigs,
|
|
string apn,
|
|
List<string> band,
|
|
string comment = null)
|
|
{
|
|
var config = new NetworkConfiguration
|
|
{
|
|
ConfigKey = configKey,
|
|
RagConfig = ragConfig,
|
|
Apn = apn,
|
|
Comment = comment,
|
|
CoreOrImsConfigs = coreOrImsConfigs ?? new List<CoreImsConfig>(),
|
|
Band = band ?? new List<string>()
|
|
};
|
|
|
|
var validationResults = new List<ValidationResult>();
|
|
if (!Validator.TryValidateObject(config, new ValidationContext(config), validationResults, true))
|
|
{
|
|
throw new ValidationException(string.Join(Environment.NewLine, validationResults.Select(r => r.ErrorMessage)));
|
|
}
|
|
|
|
return config;
|
|
}
|
|
|
|
/// <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 class NetworkConfigurationsWrapper
|
|
{
|
|
/// <summary>
|
|
/// 网络配置列表
|
|
/// </summary>
|
|
[JsonPropertyName("networkConfigurations")]
|
|
public List<NetworkConfiguration> NetworkConfigurations { get; set; } = new List<NetworkConfiguration>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 核心网和IMS配置实体
|
|
/// </summary>
|
|
public class CoreImsConfig
|
|
{
|
|
/// <summary>
|
|
/// 配置索引
|
|
/// </summary>
|
|
[Required(ErrorMessage = "配置索引不能为空")]
|
|
[Range(1, int.MaxValue, ErrorMessage = "配置索引必须大于0")]
|
|
[JsonPropertyName("index")]
|
|
public int Index { get; set; }
|
|
|
|
/// <summary>
|
|
/// PLMN码
|
|
/// </summary>
|
|
[Required(ErrorMessage = "PLMN码不能为空")]
|
|
[RegularExpression(@"^\d{5,6}$", ErrorMessage = "PLMN码必须是5-6位数字")]
|
|
[JsonPropertyName("plmn")]
|
|
public string Plmn { get; set; }
|
|
|
|
/// <summary>
|
|
/// 核心网配置文件路径
|
|
/// </summary>
|
|
[Required(ErrorMessage = "核心网配置路径不能为空")]
|
|
[RegularExpression(@"^Config/CoreNetwork/.*\.cfg$", ErrorMessage = "核心网配置路径格式不正确")]
|
|
[JsonPropertyName("coreNetworkConfig")]
|
|
public string CoreNetworkConfig { get; set; }
|
|
|
|
/// <summary>
|
|
/// IMS配置文件路径
|
|
/// </summary>
|
|
[Required(ErrorMessage = "IMS配置路径不能为空")]
|
|
[RegularExpression(@"^Config/Ims/.*\.cfg$", ErrorMessage = "IMS配置路径格式不正确")]
|
|
[JsonPropertyName("imsConfig")]
|
|
public string ImsConfig { get; set; }
|
|
}
|
|
}
|