后端下载合并初步提交
parent
13f983bc21
commit
434cdf8529
|
|
@ -17,6 +17,7 @@ using Microsoft.AspNetCore.Authorization;
|
|||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MiniExcelLibs;
|
||||
using NPOI.Util;
|
||||
using SharpCompress.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -49,7 +50,51 @@ namespace IRaCIS.Core.Application.Service
|
|||
|
||||
|
||||
|
||||
private static async Task<bool> TryWriteMergedDicomAsync(Func<Task<Stream>> sourceFactory, Stream output)
|
||||
{
|
||||
try
|
||||
{
|
||||
await using var source = await sourceFactory();
|
||||
// 如果你是从 stream 打开
|
||||
var dicomFile = await DicomFile.OpenAsync(source);
|
||||
|
||||
//获取像素是否为封装形式
|
||||
var syntax = dicomFile.Dataset.InternalTransferSyntax;
|
||||
|
||||
//对于封装像素的文件做转换
|
||||
if (syntax.IsEncapsulated)
|
||||
{
|
||||
// 获取 Pixel Data 标签
|
||||
var pixelData = DicomPixelData.Create(dicomFile.Dataset);
|
||||
|
||||
// 创建一个新的片段序列
|
||||
var newFragments = new DicomOtherByteFragment(DicomTag.PixelData);
|
||||
// 获取每帧数据并封装为单独的片段
|
||||
for (int n = 0; n < pixelData.NumberOfFrames; n++)
|
||||
{
|
||||
var frameData = pixelData.GetFrame(n);
|
||||
newFragments.Fragments.Add(new MemoryByteBuffer(frameData.Data));
|
||||
}
|
||||
|
||||
var frag = dicomFile.Dataset.GetDicomItem<DicomOtherByteFragment>(DicomTag.PixelData);
|
||||
|
||||
var originOffsetTable = frag?.OffsetTable;
|
||||
|
||||
newFragments.OffsetTable.AddRange(originOffsetTable?.ToArray());
|
||||
// 替换原有的片段序列
|
||||
dicomFile.Dataset.AddOrUpdate(newFragments);
|
||||
}
|
||||
|
||||
await dicomFile.SaveAsync(output);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 只记录,不传播
|
||||
Log.Logger.Warning($"TryWriteMergedDicomAsync failed: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -88,7 +133,9 @@ namespace IRaCIS.Core.Application.Service
|
|||
|
||||
InstancePathList = z.DicomInstanceList.Where(t => t.IsReading).Select(k => new
|
||||
{
|
||||
k.Path
|
||||
k.Path,
|
||||
k.IsEncapsulated,
|
||||
k.NumberOfFrames,
|
||||
}).ToList()
|
||||
})
|
||||
|
||||
|
|
@ -171,9 +218,18 @@ namespace IRaCIS.Core.Application.Service
|
|||
// 复制文件到相应的文件夹
|
||||
string destinationPath = Path.Combine(studyDicomFolderPath, Path.GetFileName(instanceInfo.Path));
|
||||
|
||||
await using var output = File.Create(destinationPath);
|
||||
if (instanceInfo.IsEncapsulated)
|
||||
{
|
||||
//加入到下载任务里
|
||||
downloadJobs.Add(() => TryWriteMergedDicomAsync(() => _oSSService.GetStreamFromOSSAsync(instanceInfo.Path), output));
|
||||
}
|
||||
else
|
||||
{
|
||||
//加入到下载任务里
|
||||
downloadJobs.Add(() => _oSSService.DownLoadFromOSSAsync(instanceInfo.Path, destinationPath));
|
||||
}
|
||||
|
||||
//加入到下载任务里
|
||||
downloadJobs.Add(() => _oSSService.DownLoadFromOSSAsync(instanceInfo.Path, destinationPath));
|
||||
|
||||
//下载到当前目录
|
||||
//await _oSSService.DownLoadFromOSSAsync(instanceInfo.Path, destinationPath);
|
||||
|
|
|
|||
Loading…
Reference in New Issue