minio 底层下载流 增加日志提示
continuous-integration/drone/push Build is passing Details

Test_HIR_Net8
hang 2026-03-16 11:14:05 +08:00
parent 4c11dd203c
commit b3976783df
2 changed files with 29 additions and 24 deletions

View File

@ -5,6 +5,7 @@ using ExcelDataReader;
using FellowOakDicom; using FellowOakDicom;
using FellowOakDicom.Imaging; using FellowOakDicom.Imaging;
using FellowOakDicom.IO.Buffer; using FellowOakDicom.IO.Buffer;
using FellowOakDicom.Media;
using Hangfire.Storage; using Hangfire.Storage;
using IRaCIS.Application.Contracts; using IRaCIS.Application.Contracts;
using IRaCIS.Application.Interfaces; using IRaCIS.Application.Interfaces;
@ -1050,25 +1051,27 @@ namespace IRaCIS.Core.API.Controllers
// ---------- DICOMDIR ---------- // ---------- DICOMDIR ----------
var dicomDirPath = $"{patient.PatientIdStr}/{studyTime}_{modalitysStr}/DICOMDIR"; var dicomDirPath = $"{patient.PatientIdStr}/{studyTime}_{modalitysStr}/DICOMDIR";
var dicomDirEntry = zip.CreateEntry(dicomDirPath, CompressionLevel.Fastest);
Log.Logger.Warning($"DIRPath: {study.StudyDIRPath}"); Log.Logger.Warning($"DIRPath: {study.StudyDIRPath}");
if (study.StudyDIRPath.IsNotNullOrEmpty()) if (study.StudyDIRPath.IsNotNullOrEmpty())
{ {
try try
{ {
await using (var entryStream = dicomDirEntry.Open())
await using (var dirStream = await _oSSService.GetStreamFromOSSAsync(study.StudyDIRPath)) await using (var dirStream = await _oSSService.GetStreamFromOSSAsync(study.StudyDIRPath))
{ {
var dicomDirEntry = zip.CreateEntry(dicomDirPath, CompressionLevel.Fastest);
await using var entryStream = dicomDirEntry.Open();
await dirStream.CopyToAsync(entryStream, 32 * 1024, abortToken); await dirStream.CopyToAsync(entryStream, 32 * 1024, abortToken);
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.Logger.Warning($"处理文件DIR{study.StudyDIRPath}失败: {ex.Message}"); Log.Logger.Warning($"处理文件{study.StudyCode}DIR失败: {ex.Message}");
} }
} }
@ -1083,7 +1086,7 @@ namespace IRaCIS.Core.API.Controllers
try try
{ {
//当前完成大小 //当前完成大小
receivedSize = receivedSize + instance.FileSize ?? 0; receivedSize += instance.FileSize ?? 0;
receivedCount++; receivedCount++;
@ -1091,9 +1094,7 @@ namespace IRaCIS.Core.API.Controllers
$"{patient.PatientIdStr}/{studyTime}_{modalitysStr}/IMAGE/{instance.FileName}"; $"{patient.PatientIdStr}/{studyTime}_{modalitysStr}/IMAGE/{instance.FileName}";
var entry = zip.CreateEntry(entryPath, CompressionLevel.Fastest); var entry = zip.CreateEntry(entryPath, CompressionLevel.Fastest);
await using var entryStream = entry.Open(); await using var entryStream = entry.Open();
await using var source = await _oSSService.GetStreamFromOSSAsync(instance.Path);
if (instance.IsEncapsulated && instance.NumberOfFrames > 1) if (instance.IsEncapsulated && instance.NumberOfFrames > 1)
{ {
@ -1165,20 +1166,17 @@ namespace IRaCIS.Core.API.Controllers
if (!ok) if (!ok)
{ {
await using var source2 = await _oSSService.GetStreamFromOSSAsync(instance.Path); await using var source = await _oSSService.GetStreamFromOSSAsync(instance.Path);
await source2.CopyToAsync(entryStream, 32 * 1024, abortToken); await source.CopyToAsync(entryStream, 32 * 1024, abortToken);
} }
} }
else else
{ {
await using var source = await _oSSService.GetStreamFromOSSAsync(instance.Path);
await source.CopyToAsync(entryStream, 32 * 1024, abortToken); await source.CopyToAsync(entryStream, 32 * 1024, abortToken);
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -1403,7 +1401,7 @@ namespace IRaCIS.Core.API.Controllers
try try
{ {
//当前完成大小 //当前完成大小
receivedSize = receivedSize + instance.FileSize ?? 0; receivedSize += instance.FileSize ?? 0;
receivedCount++; receivedCount++;
@ -1625,7 +1623,7 @@ namespace IRaCIS.Core.API.Controllers
try try
{ {
//当前完成大小 //当前完成大小
receivedSize = receivedSize + instance.FileSize ?? 0; receivedSize += instance.FileSize ?? 0;
receivedCount++; receivedCount++;
@ -1847,7 +1845,7 @@ namespace IRaCIS.Core.API.Controllers
try try
{ {
//当前完成大小 //当前完成大小
receivedSize = receivedSize + instance.FileSize ?? 0; receivedSize += instance.FileSize ?? 0;
receivedCount++; receivedCount++;
@ -2078,19 +2076,21 @@ namespace IRaCIS.Core.API.Controllers
// ---------- DICOMDIR ---------- // ---------- DICOMDIR ----------
var dicomDirPath = $"{visit.SubjectCode}_{visit.VisitName}/{studyTime}_{modalitysStr}/DICOMDIR"; var dicomDirPath = $"{visit.SubjectCode}_{visit.VisitName}/{studyTime}_{modalitysStr}/DICOMDIR";
var dicomDirEntry = zip.CreateEntry(dicomDirPath, CompressionLevel.Fastest);
Log.Logger.Warning($"DIRPath: {study.StudyDIRPath}"); Log.Logger.Warning($"DIRPath: {study.StudyDIRPath}");
if (study.StudyDIRPath.IsNotNullOrEmpty()) if (study.StudyDIRPath.IsNotNullOrEmpty())
{ {
try try
{ {
await using (var entryStream = dicomDirEntry.Open())
await using (var dirStream = await _oSSService.GetStreamFromOSSAsync(study.StudyDIRPath)) await using (var dirStream = await _oSSService.GetStreamFromOSSAsync(study.StudyDIRPath))
{ {
var dicomDirEntry = zip.CreateEntry(dicomDirPath, CompressionLevel.Fastest);
await using var entryStream = dicomDirEntry.Open();
await dirStream.CopyToAsync(entryStream, 32 * 1024, abortToken); await dirStream.CopyToAsync(entryStream, 32 * 1024, abortToken);
} }
} }
@ -2111,17 +2111,17 @@ namespace IRaCIS.Core.API.Controllers
try try
{ {
//当前完成大小 //当前完成大小
receivedSize = receivedSize + instance.FileSize ?? 0; receivedSize += instance.FileSize ?? 0;
receivedCount++; receivedCount++;
var entryPath = var entryPath =
$"{visit.SubjectCode}_{visit.VisitName}/{studyTime}_{modalitysStr}/IMAGE/{instance.FileName}"; $"{visit.SubjectCode}_{visit.VisitName}/{studyTime}_{modalitysStr}/IMAGE/{instance.FileName}";
var entry = zip.CreateEntry(entryPath, CompressionLevel.Fastest);
var entry = zip.CreateEntry(entryPath, CompressionLevel.Fastest);
await using var entryStream = entry.Open(); await using var entryStream = entry.Open();
await using var source = await _oSSService.GetStreamFromOSSAsync(instance.Path);
if (instance.IsEncapsulated && instance.NumberOfFrames > 1) if (instance.IsEncapsulated && instance.NumberOfFrames > 1)
@ -2194,17 +2194,20 @@ namespace IRaCIS.Core.API.Controllers
if (!ok) if (!ok)
{ {
await using var source = await _oSSService.GetStreamFromOSSAsync(instance.Path);
await source.CopyToAsync(entryStream, 32 * 1024, abortToken); await source.CopyToAsync(entryStream, 32 * 1024, abortToken);
} }
} }
else else
{ {
await using var source = await _oSSService.GetStreamFromOSSAsync(instance.Path);
await source.CopyToAsync(entryStream, 32 * 1024, abortToken); await source.CopyToAsync(entryStream, 32 * 1024, abortToken);
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
failedCount++;
Log.Logger.Warning($"处理文件{instance.Path}失败: {ex.Message}"); Log.Logger.Warning($"处理文件{instance.Path}失败: {ex.Message}");
} }

View File

@ -551,9 +551,9 @@ public class OSSService : IOSSService
var args = new GetObjectArgs() var args = new GetObjectArgs()
.WithBucket(minIOConfig.BucketName) .WithBucket(minIOConfig.BucketName)
.WithObject(ossRelativePath) .WithObject(ossRelativePath)
.WithCallbackStream( stream => .WithCallbackStream(async stream =>
{ {
stream.CopyTo(pipe.Writer.AsStream()); await stream.CopyToAsync(pipe.Writer.AsStream());
}); });
await minioClient.GetObjectAsync(args); await minioClient.GetObjectAsync(args);
@ -561,10 +561,12 @@ public class OSSService : IOSSService
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.Error($"minio 获取流错误:{ex.Message}");
await pipe.Writer.CompleteAsync(ex); await pipe.Writer.CompleteAsync(ex);
} }
}); });
return pipe.Reader.AsStream(); return pipe.Reader.AsStream();
#region 废弃 #region 废弃