|
|
@ -263,36 +263,17 @@ public class CellularNetworkService : ICellularNetworkService |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
// 确保临时目录和配置目录存在
|
|
|
|
if (!Directory.Exists(_appSettings.TempDirectory)) |
|
|
|
{ |
|
|
|
Directory.CreateDirectory(_appSettings.TempDirectory); |
|
|
|
} |
|
|
|
if (!Directory.Exists(_appSettings.RanConfigDirectory)) |
|
|
|
{ |
|
|
|
Directory.CreateDirectory(_appSettings.RanConfigDirectory); |
|
|
|
} |
|
|
|
if (!Directory.Exists(_appSettings.MmeConfigDirectory)) |
|
|
|
{ |
|
|
|
Directory.CreateDirectory(_appSettings.MmeConfigDirectory); |
|
|
|
} |
|
|
|
// 确保所需目录存在
|
|
|
|
EnsureDirectoriesExist(); |
|
|
|
|
|
|
|
// 复制 RAG 配置文件
|
|
|
|
if (!string.IsNullOrEmpty(networkConfig.RagConfig)) |
|
|
|
{ |
|
|
|
if (!File.Exists(networkConfig.RagConfig)) |
|
|
|
if (!CopyConfigFile(networkConfig.RagConfig, _appSettings.RanConfigDirectory, |
|
|
|
path => networkConfig.RagConfig = path, "RAG")) |
|
|
|
{ |
|
|
|
_logger.LogError("RAG配置文件不存在: {FilePath}", networkConfig.RagConfig); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
var ragFileName = Path.GetFileName(networkConfig.RagConfig); |
|
|
|
var ragTempPath = Path.Combine(_appSettings.TempDirectory, ragFileName); |
|
|
|
var ragRanPath = Path.Combine(_appSettings.RanConfigDirectory, ragFileName); |
|
|
|
|
|
|
|
File.Copy(networkConfig.RagConfig, ragTempPath, true); |
|
|
|
File.Copy(networkConfig.RagConfig, ragRanPath, true); |
|
|
|
networkConfig.RagConfig = ragRanPath; |
|
|
|
} |
|
|
|
|
|
|
|
// 复制核心网络配置文件和IMS配置文件
|
|
|
@ -300,36 +281,20 @@ public class CellularNetworkService : ICellularNetworkService |
|
|
|
{ |
|
|
|
if (!string.IsNullOrEmpty(config.CoreNetworkConfig)) |
|
|
|
{ |
|
|
|
if (!File.Exists(config.CoreNetworkConfig)) |
|
|
|
if (!CopyConfigFile(config.CoreNetworkConfig, _appSettings.MmeConfigDirectory, |
|
|
|
path => config.CoreNetworkConfig = path, "核心网络")) |
|
|
|
{ |
|
|
|
_logger.LogError("核心网络配置文件不存在: {FilePath}", config.CoreNetworkConfig); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
var coreFileName = Path.GetFileName(config.CoreNetworkConfig); |
|
|
|
var coreTempPath = Path.Combine(_appSettings.TempDirectory, coreFileName); |
|
|
|
var coreMmePath = Path.Combine(_appSettings.MmeConfigDirectory, coreFileName); |
|
|
|
|
|
|
|
File.Copy(config.CoreNetworkConfig, coreTempPath, true); |
|
|
|
File.Copy(config.CoreNetworkConfig, coreMmePath, true); |
|
|
|
config.CoreNetworkConfig = coreMmePath; |
|
|
|
} |
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(config.ImsConfig)) |
|
|
|
{ |
|
|
|
if (!File.Exists(config.ImsConfig)) |
|
|
|
if (!CopyConfigFile(config.ImsConfig, _appSettings.MmeConfigDirectory, |
|
|
|
path => config.ImsConfig = path, "IMS")) |
|
|
|
{ |
|
|
|
_logger.LogError("IMS配置文件不存在: {FilePath}", config.ImsConfig); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
var imsFileName = Path.GetFileName(config.ImsConfig); |
|
|
|
var imsTempPath = Path.Combine(_appSettings.TempDirectory, imsFileName); |
|
|
|
var imsMmePath = Path.Combine(_appSettings.MmeConfigDirectory, imsFileName); |
|
|
|
|
|
|
|
File.Copy(config.ImsConfig, imsTempPath, true); |
|
|
|
File.Copy(config.ImsConfig, imsMmePath, true); |
|
|
|
config.ImsConfig = imsMmePath; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -342,6 +307,52 @@ public class CellularNetworkService : ICellularNetworkService |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void EnsureDirectoriesExist() |
|
|
|
{ |
|
|
|
if (!Directory.Exists(_appSettings.TempDirectory)) |
|
|
|
{ |
|
|
|
Directory.CreateDirectory(_appSettings.TempDirectory); |
|
|
|
} |
|
|
|
if (!Directory.Exists(_appSettings.RanConfigDirectory)) |
|
|
|
{ |
|
|
|
Directory.CreateDirectory(_appSettings.RanConfigDirectory); |
|
|
|
} |
|
|
|
if (!Directory.Exists(_appSettings.MmeConfigDirectory)) |
|
|
|
{ |
|
|
|
Directory.CreateDirectory(_appSettings.MmeConfigDirectory); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private bool CopyConfigFile(string sourcePath, string targetDirectory, Action<string> updatePath, string configType) |
|
|
|
{ |
|
|
|
if (!File.Exists(sourcePath)) |
|
|
|
{ |
|
|
|
_logger.LogError("{ConfigType}配置文件不存在: {FilePath}", configType, sourcePath); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
var fileName = Path.GetFileName(sourcePath); |
|
|
|
var tempPath = Path.Combine(_appSettings.TempDirectory, fileName); |
|
|
|
|
|
|
|
// 始终复制到临时目录
|
|
|
|
File.Copy(sourcePath, tempPath, true); |
|
|
|
|
|
|
|
// 如果不在目标目录下,则复制到该目录并更新路径
|
|
|
|
if (!sourcePath.StartsWith(targetDirectory)) |
|
|
|
{ |
|
|
|
var targetPath = Path.Combine(targetDirectory, fileName); |
|
|
|
File.Copy(sourcePath, targetPath, true); |
|
|
|
updatePath(targetPath); |
|
|
|
_logger.LogInformation("{ConfigType}配置文件已复制到目标目录: {FilePath}", configType, targetPath); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
_logger.LogInformation("{ConfigType}配置文件已在目标目录中: {FilePath}", configType, sourcePath); |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
private bool HasBothRagAndCoreConfigs(NetworkConfiguration config) |
|
|
|
{ |
|
|
|
return !string.IsNullOrWhiteSpace(config.RagConfig) && config.CoreOrImsConfigs.Any(); |
|
|
|