|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using CoreAgent.Domain.Entities;
|
|
|
|
using CoreAgent.Domain.Interfaces;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
namespace CoreAgent.Infrastructure.Services
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// 网络配置服务实现
|
|
|
|
/// </summary>
|
|
|
|
public class NetworkConfigurationService : INetworkConfigurationService
|
|
|
|
{
|
|
|
|
private readonly INetworkConfigurationRepository _repository;
|
|
|
|
private readonly ILogger<NetworkConfigurationService> _logger;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 构造函数
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="repository">网络配置仓储</param>
|
|
|
|
/// <param name="logger">日志记录器</param>
|
|
|
|
public NetworkConfigurationService(
|
|
|
|
INetworkConfigurationRepository repository,
|
|
|
|
ILogger<NetworkConfigurationService> logger)
|
|
|
|
{
|
|
|
|
_repository = repository;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 创建网络配置
|
|
|
|
/// </summary>
|
|
|
|
public async Task<(bool Success, NetworkConfiguration Configuration)> CreateAsync(
|
|
|
|
string configKey,
|
|
|
|
string ragConfig,
|
|
|
|
List<CoreImsConfig> coreOrImsConfigs,
|
|
|
|
string apn,
|
|
|
|
List<string> band,
|
|
|
|
string comment = null)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
_logger.LogInformation("开始创建网络配置,配置键:{ConfigKey}", configKey);
|
|
|
|
_logger.LogDebug("创建网络配置参数 - RAN配置:{RagConfig}, APN:{Apn}, 频段:{Band}, 说明:{Comment}",
|
|
|
|
ragConfig, apn, string.Join(",", band), comment);
|
|
|
|
|
|
|
|
// 检查配置键是否已存在
|
|
|
|
_logger.LogInformation("检查配置键是否存在:{ConfigKey}", configKey);
|
|
|
|
var existingConfig = await _repository.GetByConfigKeyAsync(configKey);
|
|
|
|
if (existingConfig != null)
|
|
|
|
{
|
|
|
|
_logger.LogWarning("配置键已存在,创建失败:{ConfigKey}", configKey);
|
|
|
|
return (false, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
_logger.LogInformation("开始创建新的网络配置:{ConfigKey}", configKey);
|
|
|
|
var config = await _repository.CreateAsync(configKey, ragConfig, coreOrImsConfigs, apn, band, comment);
|
|
|
|
|
|
|
|
_logger.LogInformation("网络配置创建成功:{ConfigKey}", configKey);
|
|
|
|
_logger.LogDebug("网络配置详情 - RAN配置:{RagConfig}, APN:{Apn}, 频段:{Band}, 说明:{Comment}",
|
|
|
|
config.RagConfig, config.Apn, string.Join(",", config.Band), config.Comment);
|
|
|
|
|
|
|
|
return (true, config);
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
_logger.LogError(ex, "创建网络配置失败,配置键:{ConfigKey},错误信息:{ErrorMessage}",
|
|
|
|
configKey, ex.Message);
|
|
|
|
return (false, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 保存网络配置
|
|
|
|
/// </summary>
|
|
|
|
public Task<bool> SaveAsync(NetworkConfiguration configuration)
|
|
|
|
{
|
|
|
|
return _repository.SaveAsync(configuration);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 删除网络配置
|
|
|
|
/// </summary>
|
|
|
|
public Task<bool> DeleteAsync(string configKey)
|
|
|
|
{
|
|
|
|
return _repository.DeleteAsync(configKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获取所有网络配置
|
|
|
|
/// </summary>
|
|
|
|
public Task<List<NetworkConfiguration>> GetAllAsync()
|
|
|
|
{
|
|
|
|
return _repository.GetAllAsync();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 根据配置键获取网络配置
|
|
|
|
/// </summary>
|
|
|
|
public Task<NetworkConfiguration> GetByConfigKeyAsync(string configKey)
|
|
|
|
{
|
|
|
|
return _repository.GetByConfigKeyAsync(configKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|