切换存储

Uat_Study
hang 2023-05-16 16:31:25 +08:00
parent ff3b0db3ea
commit 5210684c50
6 changed files with 114 additions and 31 deletions

View File

@ -296,15 +296,15 @@ namespace IRaCIS.Core.API.Controllers
var startTime = DateTime.Now;
if (_provider.Exists($"StudyUid_{trialId}_{archiveStudyCommand.StudyInstanceUid}"))
{
//---当前已有人正在上传和归档该检查!
return ResponseOutput.NotOk(StaticData.International("UploadDownLoad_ArchiveInProgress"));
}
else
{
_provider.Set($"StudyUid_{trialId}_{archiveStudyCommand.StudyInstanceUid}", _userInfo.Id, TimeSpan.FromMinutes(30));
}
//if (_provider.Exists($"StudyUid_{trialId}_{archiveStudyCommand.StudyInstanceUid}"))
//{
// //---当前已有人正在上传和归档该检查!
// return ResponseOutput.NotOk(StaticData.International("UploadDownLoad_ArchiveInProgress"));
//}
//else
//{
// _provider.Set($"StudyUid_{trialId}_{archiveStudyCommand.StudyInstanceUid}", _userInfo.Id, TimeSpan.FromMinutes(30));
//}
//到了接口,代表上传结束了

View File

@ -219,8 +219,8 @@ namespace IRaCIS.Core.API
app.UseCors(t => t.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
app.UseIRacisHostStaticFileStore(env);
//app.UseIRacisHostStaticFileStore(env);
app.UseMiddleware<MultiDiskStaticFilesMiddleware>();
app.UseAuthentication();

View File

@ -11,6 +11,7 @@ using Microsoft.Extensions.Hosting.Internal;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.VisualBasic;
using SharpCompress.Common;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
@ -23,16 +24,14 @@ namespace IRaCIS.Core.API
{
private readonly RequestDelegate _next;
private readonly IWebHostEnvironment _hostingEnv;
private readonly StaticFileOptions _options;
private readonly ILoggerFactory _loggerFactory;
private string iRaCISDefaultDataFolder = string.Empty;
public MultiDiskStaticFilesMiddleware(RequestDelegate next, IWebHostEnvironment hostingEnv, StaticFileOptions options, ILoggerFactory loggerFactory)
public MultiDiskStaticFilesMiddleware(RequestDelegate next, IWebHostEnvironment hostingEnv, ILoggerFactory loggerFactory)
{
_next = next;
_hostingEnv = hostingEnv;
_options = options;
_loggerFactory = loggerFactory;
iRaCISDefaultDataFolder = FileStoreHelper.GetIRaCISRootDataFolder(_hostingEnv);
@ -66,8 +65,12 @@ namespace IRaCIS.Core.API
{
if (defaultFileProvider.GetFileInfo(context.Request.Path).Exists)
{
var staticFileMiddleware = new StaticFileMiddleware(_next, _hostingEnv, Options.Create(staticFileOptions), _loggerFactory);
await staticFileMiddleware.Invoke(context);
//var staticFileMiddleware = new StaticFileMiddleware(_next, _hostingEnv, Options.Create(staticFileOptions), _loggerFactory);
//await staticFileMiddleware.Invoke(context);
var actrualPath = defaultFileProvider.GetFileInfo(context.Request.Path).PhysicalPath;
await context.Response.SendFileAsync(new PhysicalFileInfo(new FileInfo(actrualPath)));
return;
}
}
@ -82,6 +85,11 @@ namespace IRaCIS.Core.API
foreach (var item in disks)
{
var otherFileStoreFolder = Path.Combine(item, _hostingEnv.EnvironmentName);
if (!Directory.Exists(otherFileStoreFolder))
{
continue;
}
var otherFileProvider= new PhysicalFileProvider(otherFileStoreFolder);
@ -95,8 +103,15 @@ namespace IRaCIS.Core.API
if (otherFileProvider.GetFileInfo(context.Request.Path).Exists)
{
var staticFileMiddleware = new StaticFileMiddleware(_next, _hostingEnv, Options.Create(staticFileOptions), _loggerFactory);
await staticFileMiddleware.Invoke(context);
var actrualPath = otherFileProvider.GetFileInfo(context.Request.Path).PhysicalPath;
//方式一
await context.Response.SendFileAsync( new PhysicalFileInfo(new FileInfo(actrualPath)));
//方式二
//var staticFileMiddleware = new StaticFileMiddleware(_next, _hostingEnv, Options.Create(otherStaticFileOptions), _loggerFactory);
//await staticFileMiddleware.Invoke(context);
return;
}
}

View File

@ -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;
}
// 获取医生通用文件存放路径

View File

@ -7598,6 +7598,11 @@
上一次任务的新病灶评估为iCPD
</summary>
</member>
<member name="P:IRaCIS.Core.Application.ViewModel.IRECISTNewLesionAssessmentDto.ExistxIRECISTNewLesion">
<summary>
存在触发iRECIST后新病灶
</summary>
</member>
<member name="T:IRaCIS.Core.Application.ViewModel.IRECISTTargetLesionEvaluateDto">
<summary>
IRECIST整体肿瘤评估

View File

@ -17,6 +17,7 @@ using System.Text.Encodings.Web;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using IRaCIS.Core.Infrastructure;
using IRaCIS.Core.Application.Helper;
namespace IRaCIS.Core.Application.Service.Common
{
@ -45,9 +46,6 @@ namespace IRaCIS.Core.Application.Service.Common
}
public string GetBestStoreDisk()
{
@ -69,7 +67,7 @@ namespace IRaCIS.Core.Application.Service.Common
}
//默认存储的路径
var defaultStoreRootFolder = Path.Combine((Directory.GetParent(_hostEnvironment.ContentRootPath.TrimEnd('\\'))).IfNullThrowException().FullName, StaticData.Folder.IRaCISDataFolder);
var defaultStoreRootFolder = FileStoreHelper.GetIRaCISRootDataFolder(_hostEnvironment);
DriveInfo defaultDrive = new DriveInfo(Path.GetPathRoot(defaultStoreRootFolder));
@ -96,14 +94,13 @@ namespace IRaCIS.Core.Application.Service.Common
}
//找到最优驱动器
DriveInfo drive = new DriveInfo(Path.GetPathRoot(bestStoreRootFolder));
////找到最优驱动器
//DriveInfo drive = new DriveInfo(Path.GetPathRoot(bestStoreRootFolder));
//最优盘符使用率超过百分之80
if (((double)(drive.TotalSize - drive.TotalFreeSpace) / drive.TotalSize) * 100 > switchingRatio)
{
}
////最优盘符使用率超过百分之80
//if (((double)(drive.TotalSize - drive.TotalFreeSpace) / drive.TotalSize) * 100 > switchingRatio)
//{
//}
if (!Directory.Exists(bestStoreRootFolder))
{
@ -113,6 +110,9 @@ namespace IRaCIS.Core.Application.Service.Common
return bestStoreRootFolder;
}
public class GeneralRule
{
public string Endpoint { get; set; }