Merge branch 'master' of http://192.168.1.2:8033/IRaCIS_Core_Api
						commit
						c58913062a
					
				| 
						 | 
					@ -296,15 +296,15 @@ namespace IRaCIS.Core.API.Controllers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var startTime = DateTime.Now;
 | 
					            var startTime = DateTime.Now;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (_provider.Exists($"StudyUid_{trialId}_{archiveStudyCommand.StudyInstanceUid}"))
 | 
					            //if (_provider.Exists($"StudyUid_{trialId}_{archiveStudyCommand.StudyInstanceUid}"))
 | 
				
			||||||
            {
 | 
					            //{
 | 
				
			||||||
                //---当前已有人正在上传和归档该检查!
 | 
					            //    //---当前已有人正在上传和归档该检查!
 | 
				
			||||||
                return ResponseOutput.NotOk(StaticData.International("UploadDownLoad_ArchiveInProgress"));
 | 
					            //    return ResponseOutput.NotOk(StaticData.International("UploadDownLoad_ArchiveInProgress"));
 | 
				
			||||||
            }
 | 
					            //}
 | 
				
			||||||
            else
 | 
					            //else
 | 
				
			||||||
            {
 | 
					            //{
 | 
				
			||||||
                _provider.Set($"StudyUid_{trialId}_{archiveStudyCommand.StudyInstanceUid}", _userInfo.Id, TimeSpan.FromMinutes(30));
 | 
					            //    _provider.Set($"StudyUid_{trialId}_{archiveStudyCommand.StudyInstanceUid}", _userInfo.Id, TimeSpan.FromMinutes(30));
 | 
				
			||||||
            }
 | 
					            //}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            //到了接口,代表上传结束了
 | 
					            //到了接口,代表上传结束了
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -219,8 +219,8 @@ namespace IRaCIS.Core.API
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            app.UseCors(t => t.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
 | 
					            app.UseCors(t => t.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            app.UseIRacisHostStaticFileStore(env);
 | 
					            //app.UseIRacisHostStaticFileStore(env);
 | 
				
			||||||
 | 
					            app.UseMiddleware<MultiDiskStaticFilesMiddleware>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            app.UseAuthentication();
 | 
					            app.UseAuthentication();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,6 +11,7 @@ using Microsoft.Extensions.Hosting.Internal;
 | 
				
			||||||
using Microsoft.Extensions.Logging;
 | 
					using Microsoft.Extensions.Logging;
 | 
				
			||||||
using Microsoft.Extensions.Options;
 | 
					using Microsoft.Extensions.Options;
 | 
				
			||||||
using Microsoft.VisualBasic;
 | 
					using Microsoft.VisualBasic;
 | 
				
			||||||
 | 
					using SharpCompress.Common;
 | 
				
			||||||
using System.IO;
 | 
					using System.IO;
 | 
				
			||||||
using System.Linq;
 | 
					using System.Linq;
 | 
				
			||||||
using System.Threading.Tasks;
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
| 
						 | 
					@ -23,16 +24,14 @@ namespace IRaCIS.Core.API
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        private readonly RequestDelegate _next;
 | 
					        private readonly RequestDelegate _next;
 | 
				
			||||||
        private readonly IWebHostEnvironment _hostingEnv;
 | 
					        private readonly IWebHostEnvironment _hostingEnv;
 | 
				
			||||||
        private readonly StaticFileOptions _options;
 | 
					 | 
				
			||||||
        private readonly ILoggerFactory _loggerFactory;
 | 
					        private readonly ILoggerFactory _loggerFactory;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private string iRaCISDefaultDataFolder = string.Empty;
 | 
					        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;
 | 
					            _next = next;
 | 
				
			||||||
            _hostingEnv = hostingEnv;
 | 
					            _hostingEnv = hostingEnv;
 | 
				
			||||||
            _options = options;
 | 
					 | 
				
			||||||
            _loggerFactory = loggerFactory;
 | 
					            _loggerFactory = loggerFactory;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            iRaCISDefaultDataFolder = FileStoreHelper.GetIRaCISRootDataFolder(_hostingEnv);
 | 
					            iRaCISDefaultDataFolder = FileStoreHelper.GetIRaCISRootDataFolder(_hostingEnv);
 | 
				
			||||||
| 
						 | 
					@ -66,8 +65,12 @@ namespace IRaCIS.Core.API
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                if (defaultFileProvider.GetFileInfo(context.Request.Path).Exists)
 | 
					                if (defaultFileProvider.GetFileInfo(context.Request.Path).Exists)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    var staticFileMiddleware = new StaticFileMiddleware(_next, _hostingEnv, Options.Create(staticFileOptions), _loggerFactory);
 | 
					                    //var staticFileMiddleware = new StaticFileMiddleware(_next, _hostingEnv, Options.Create(staticFileOptions), _loggerFactory);
 | 
				
			||||||
                    await staticFileMiddleware.Invoke(context);
 | 
					                    //await staticFileMiddleware.Invoke(context);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    var actrualPath = defaultFileProvider.GetFileInfo(context.Request.Path).PhysicalPath;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    await context.Response.SendFileAsync(new PhysicalFileInfo(new FileInfo(actrualPath)));
 | 
				
			||||||
                    return;
 | 
					                    return;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
| 
						 | 
					@ -82,6 +85,11 @@ namespace IRaCIS.Core.API
 | 
				
			||||||
                foreach (var item in disks)
 | 
					                foreach (var item in disks)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    var otherFileStoreFolder = Path.Combine(item, _hostingEnv.EnvironmentName);
 | 
					                    var otherFileStoreFolder = Path.Combine(item, _hostingEnv.EnvironmentName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    if (!Directory.Exists(otherFileStoreFolder))
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        continue;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
                 
 | 
					                 
 | 
				
			||||||
                    var otherFileProvider= new PhysicalFileProvider(otherFileStoreFolder);
 | 
					                    var otherFileProvider= new PhysicalFileProvider(otherFileStoreFolder);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -95,8 +103,15 @@ namespace IRaCIS.Core.API
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (otherFileProvider.GetFileInfo(context.Request.Path).Exists)
 | 
					                    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;
 | 
					                        return;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,8 @@
 | 
				
			||||||
using IRaCIS.Core.Domain.Share;
 | 
					using IRaCIS.Core.Domain.Share;
 | 
				
			||||||
using IRaCIS.Core.Infrastructure;
 | 
					using IRaCIS.Core.Infrastructure;
 | 
				
			||||||
using Microsoft.AspNetCore.Hosting;
 | 
					using Microsoft.AspNetCore.Hosting;
 | 
				
			||||||
 | 
					using Microsoft.Extensions.Hosting;
 | 
				
			||||||
 | 
					using Newtonsoft.Json.Linq;
 | 
				
			||||||
using System.Text.RegularExpressions;
 | 
					using System.Text.RegularExpressions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace IRaCIS.Core.Application.Helper;
 | 
					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)
 | 
					    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
 | 
					        //加入访视层级  和Data
 | 
				
			||||||
        var path = Path.Combine(rootPath, StaticData.Folder.TrialDataFolder, trialId.ToString(),
 | 
					        var path = Path.Combine(rootPath, StaticData.Folder.TrialDataFolder, trialId.ToString(),
 | 
				
			||||||
| 
						 | 
					@ -517,8 +524,64 @@ public static class FileStoreHelper
 | 
				
			||||||
        return (physicalPath, relativePath);
 | 
					        return (physicalPath, relativePath);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static string GetBestStoreDisk(IWebHostEnvironment _hostEnvironment)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        var json = File.ReadAllText( Path.Combine(_hostEnvironment.ContentRootPath, "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;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // 获取医生通用文件存放路径
 | 
					    // 获取医生通用文件存放路径
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,6 +17,7 @@ using System.Text.Encodings.Web;
 | 
				
			||||||
using Newtonsoft.Json.Linq;
 | 
					using Newtonsoft.Json.Linq;
 | 
				
			||||||
using Newtonsoft.Json;
 | 
					using Newtonsoft.Json;
 | 
				
			||||||
using IRaCIS.Core.Infrastructure;
 | 
					using IRaCIS.Core.Infrastructure;
 | 
				
			||||||
 | 
					using IRaCIS.Core.Application.Helper;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace IRaCIS.Core.Application.Service.Common
 | 
					namespace IRaCIS.Core.Application.Service.Common
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -45,9 +46,6 @@ namespace IRaCIS.Core.Application.Service.Common
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        public string GetBestStoreDisk()
 | 
					        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));
 | 
					            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  
 | 
					            ////最优盘符使用率超过百分之80  
 | 
				
			||||||
            if (((double)(drive.TotalSize - drive.TotalFreeSpace) / drive.TotalSize) * 100 > switchingRatio)
 | 
					            //if (((double)(drive.TotalSize - drive.TotalFreeSpace) / drive.TotalSize) * 100 > switchingRatio)
 | 
				
			||||||
            {
 | 
					            //{
 | 
				
			||||||
 | 
					            //}
 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!Directory.Exists(bestStoreRootFolder))
 | 
					            if (!Directory.Exists(bestStoreRootFolder))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
| 
						 | 
					@ -113,6 +110,9 @@ namespace IRaCIS.Core.Application.Service.Common
 | 
				
			||||||
            return bestStoreRootFolder;
 | 
					            return bestStoreRootFolder;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public class GeneralRule
 | 
					        public class GeneralRule
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            public string Endpoint { get; set; }
 | 
					            public string Endpoint { get; set; }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue