DicomOperateQueue.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using Dicom;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using Vinno.FIS.Sonopost.Common;
  6. using Vinno.FIS.Sonopost.Helpers;
  7. using Vinno.FIS.Sonopost.Managers;
  8. using Vinno.FIS.Sonopost.Managers.Interfaces;
  9. using Vinno.IUS.Common.Utilities.Executors;
  10. namespace Vinno.FIS.Sonopost.Features.Dicom
  11. {
  12. internal abstract class DicomOperateQueue
  13. {
  14. private readonly SequenceExecutor<DicomFile> _dicomFilesQueue;
  15. protected IConfigManager _configManager;
  16. public DicomOperateQueue(string name)
  17. {
  18. _dicomFilesQueue = new SequenceExecutor<DicomFile>(name);
  19. _configManager = AppManager.Instance.GetManager<IConfigManager>();
  20. }
  21. public void Enqueue(DicomFile dicomFile)
  22. {
  23. _dicomFilesQueue.Add(DoWork, dicomFile);
  24. }
  25. protected abstract bool DoWork(DicomFile arg);
  26. protected string Save(string folderName, DicomFile file, string newGuid, string dateFolder = null)
  27. {
  28. var targetFolder = Path.Combine(SonopostConstants.DataFolder, folderName);
  29. if (dateFolder != null)
  30. {
  31. targetFolder = Path.Combine(SonopostConstants.DataFolder, folderName, dateFolder);
  32. }
  33. if (!Directory.Exists(targetFolder))
  34. {
  35. Directory.CreateDirectory(targetFolder);
  36. }
  37. var dicomFileName = Path.Combine(targetFolder, $"{newGuid}.dcm");
  38. DicomHelper.Save(dicomFileName, file);
  39. return dicomFileName;
  40. }
  41. protected void DeleteFiles(IEnumerable<FileInfo> files)
  42. {
  43. int skipLen = 10;
  44. if (files.Sum(t => t.Length) > 2147483648)//2GB
  45. {
  46. skipLen = 2;
  47. }
  48. if (files.Count() <= skipLen) return;
  49. foreach (var item in files.Skip(skipLen))
  50. {
  51. item.Delete();
  52. }
  53. }
  54. }
  55. }