DicomOperateQueue.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using Dicom;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using Vinno.FIS.Sonopost.Common;
  7. using Vinno.FIS.Sonopost.Helpers;
  8. using Vinno.FIS.Sonopost.Managers;
  9. using Vinno.FIS.Sonopost.Managers.Interfaces;
  10. using Vinno.IUS.Common.Utilities.Executors;
  11. namespace Vinno.FIS.Sonopost.Features.Dicom
  12. {
  13. internal abstract class DicomOperateQueue
  14. {
  15. private readonly SequenceExecutor<DicomFile> _dicomFilesQueue;
  16. private readonly SequenceExecutor<VidInfo> _vidInfoQueue;
  17. protected IConfigManager _configManager;
  18. public DicomOperateQueue(string name)
  19. {
  20. _dicomFilesQueue = new SequenceExecutor<DicomFile>(name);
  21. _vidInfoQueue = new SequenceExecutor<VidInfo>(name);
  22. _configManager = AppManager.Instance.GetManager<IConfigManager>();
  23. }
  24. public void Enqueue(DicomFile dicomFile)
  25. {
  26. _dicomFilesQueue.Add(DoWork, dicomFile);
  27. }
  28. public void Enqueue(VidInfo vidInfo)
  29. {
  30. _vidInfoQueue.Add(DoWork, vidInfo);
  31. }
  32. protected abstract bool DoWork(DicomFile arg);
  33. protected abstract bool DoWork(VidInfo arg);
  34. protected string Save(string folderName, DicomFile file, string newGuid, string dateFolder = null)
  35. {
  36. var targetFolder = Path.Combine(SonopostConstants.DataFolder, folderName);
  37. if (dateFolder != null)
  38. {
  39. targetFolder = Path.Combine(SonopostConstants.DataFolder, folderName, dateFolder);
  40. }
  41. DirectoryHelper.CreateDirectory(targetFolder);
  42. var dicomFileName = Path.Combine(targetFolder, $"{newGuid}.{SonopostConstants.DicomFileName}");
  43. DicomHelper.Save(dicomFileName, file);
  44. return dicomFileName;
  45. }
  46. protected string Save(string folderName, string vidFilePath, string newGuid, string dateFolder = null)
  47. {
  48. var targetFolder = Path.Combine(SonopostConstants.DataFolder, folderName);
  49. if (dateFolder != null)
  50. {
  51. targetFolder = Path.Combine(SonopostConstants.DataFolder, folderName, dateFolder);
  52. }
  53. DirectoryHelper.CreateDirectory(targetFolder);
  54. var vidFileName = Path.Combine(targetFolder, $"{newGuid}.{SonopostConstants.VidFileName}");
  55. try
  56. {
  57. if (File.Exists(vidFilePath))
  58. {
  59. File.Move(vidFilePath, vidFileName);
  60. return vidFileName;
  61. }
  62. else
  63. {
  64. return null;
  65. }
  66. }
  67. catch (Exception ex)
  68. {
  69. IUS.Common.Log.Logger.WriteLineError($"Save Original Vid File Error:{ex}");
  70. return null;
  71. }
  72. }
  73. protected void DeleteFiles(IEnumerable<FileInfo> files)
  74. {
  75. int skipLen = 10;
  76. if (files.Sum(t => t.Length) > 2147483648)//2GB
  77. {
  78. skipLen = 2;
  79. }
  80. if (files.Count() <= skipLen) return;
  81. foreach (var item in files.Skip(skipLen))
  82. {
  83. item.Delete();
  84. }
  85. }
  86. }
  87. }