12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using Dicom;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using Vinno.FIS.Sonopost.Common;
- using Vinno.FIS.Sonopost.Helpers;
- using Vinno.FIS.Sonopost.Managers;
- using Vinno.FIS.Sonopost.Managers.Interfaces;
- using Vinno.IUS.Common.Utilities.Executors;
- namespace Vinno.FIS.Sonopost.Features.Dicom
- {
- internal abstract class DicomOperateQueue
- {
- private readonly SequenceExecutor<DicomFile> _dicomFilesQueue;
- protected IConfigManager _configManager;
- public DicomOperateQueue(string name)
- {
- _dicomFilesQueue = new SequenceExecutor<DicomFile>(name);
- _configManager = AppManager.Instance.GetManager<IConfigManager>();
- }
- public void Enqueue(DicomFile dicomFile)
- {
- _dicomFilesQueue.Add(DoWork, dicomFile);
- }
- protected abstract bool DoWork(DicomFile arg);
- protected string Save(string folderName, DicomFile file, string newGuid, string dateFolder = null)
- {
- var targetFolder = Path.Combine(SonopostConstants.DataFolder, folderName);
- if (dateFolder != null)
- {
- targetFolder = Path.Combine(SonopostConstants.DataFolder, folderName, dateFolder);
- }
- if (!Directory.Exists(targetFolder))
- {
- Directory.CreateDirectory(targetFolder);
- }
- var dicomFileName = Path.Combine(targetFolder, $"{newGuid}.dcm");
- DicomHelper.Save(dicomFileName, file);
- return dicomFileName;
- }
- protected void DeleteFiles(IEnumerable<FileInfo> files)
- {
- int skipLen = 10;
- if (files.Sum(t => t.Length) > 2147483648)//2GB
- {
- skipLen = 2;
- }
- if (files.Count() <= skipLen) return;
- foreach (var item in files.Skip(skipLen))
- {
- item.Delete();
- }
- }
- }
- }
|