切换存储
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
using IRaCIS.Core.Domain.Share;
|
||||
using IRaCIS.Core.Infrastructure;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace IRaCIS.Core.Application.Helper;
|
||||
@@ -495,7 +497,12 @@ public static class FileStoreHelper
|
||||
|
||||
public static (string PhysicalPath, string RelativePath) GetDicomInstanceFilePath(IWebHostEnvironment _hostEnvironment, Guid trialId, Guid siteId, Guid subjectId, Guid subjectVisitId, Guid studyId, Guid instanceId)
|
||||
{
|
||||
var rootPath = FileStoreHelper.GetIRaCISRootDataFolder(_hostEnvironment);
|
||||
#region 切换存储前
|
||||
//var rootPath = FileStoreHelper.GetIRaCISRootDataFolder(_hostEnvironment);
|
||||
#endregion
|
||||
var rootPath = Path.Combine(FileStoreHelper.GetBestStoreDisk(_hostEnvironment), StaticData.Folder.IRaCISDataFolder) ;
|
||||
|
||||
|
||||
|
||||
//加入访视层级 和Data
|
||||
var path = Path.Combine(rootPath, StaticData.Folder.TrialDataFolder, trialId.ToString(),
|
||||
@@ -517,8 +524,64 @@ public static class FileStoreHelper
|
||||
return (physicalPath, relativePath);
|
||||
}
|
||||
|
||||
public static string GetBestStoreDisk(IWebHostEnvironment _hostEnvironment)
|
||||
{
|
||||
|
||||
var json = File.ReadAllText("appsettings.json");
|
||||
|
||||
JObject jsonObject = JObject.Parse(json, new JsonLoadSettings() { CommentHandling = CommentHandling.Load });
|
||||
|
||||
int switchingRatio = 80;
|
||||
|
||||
try
|
||||
{
|
||||
switchingRatio = (int)jsonObject["IRaCISImageStore"]["SwitchingRatio"];
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
//---解析Json文件配置出现问题
|
||||
throw new BusinessValidationFailedException(StaticData.International("SysMon_JsonConfig") + e.Message);
|
||||
}
|
||||
|
||||
//默认存储的路径
|
||||
var defaultStoreRootFolder = FileStoreHelper.GetIRaCISRootDataFolder(_hostEnvironment);
|
||||
|
||||
|
||||
DriveInfo defaultDrive = new DriveInfo(Path.GetPathRoot(defaultStoreRootFolder));
|
||||
|
||||
var drives = DriveInfo.GetDrives().Where(t => !t.Name.Contains("C") && !t.Name.Contains("c"))
|
||||
.Where(d => d.DriveType == DriveType.Fixed && d.IsReady)
|
||||
//剩余空间最多的
|
||||
.OrderByDescending(d => d.AvailableFreeSpace)
|
||||
|
||||
//存储空间相同,则按照按照总空间从大到小排序
|
||||
.ThenByDescending(d => d.TotalSize - d.TotalFreeSpace);
|
||||
|
||||
var bestDrive = drives.FirstOrDefault();
|
||||
var bestStoreRootFolder = string.Empty;
|
||||
|
||||
//仅仅只有C 盘
|
||||
if (bestDrive == null || ((double)(defaultDrive.TotalSize - defaultDrive.TotalFreeSpace) / defaultDrive.TotalSize) * 100 < switchingRatio)
|
||||
{
|
||||
bestStoreRootFolder = defaultStoreRootFolder;
|
||||
}
|
||||
else
|
||||
{
|
||||
bestStoreRootFolder = Path.Combine(bestDrive?.RootDirectory.FullName, _hostEnvironment.EnvironmentName);
|
||||
}
|
||||
|
||||
if (!Directory.Exists(bestStoreRootFolder))
|
||||
{
|
||||
Directory.CreateDirectory(bestStoreRootFolder);
|
||||
}
|
||||
|
||||
return bestStoreRootFolder;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 获取医生通用文件存放路径
|
||||
|
||||
|
||||
Reference in New Issue
Block a user