using Dicom; using System; 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 _dicomFilesQueue; private readonly SequenceExecutor _vidInfoQueue; protected IConfigManager _configManager; public DicomOperateQueue(string name) { _dicomFilesQueue = new SequenceExecutor(name); _vidInfoQueue = new SequenceExecutor(name); _configManager = AppManager.Instance.GetManager(); } public void Enqueue(DicomFile dicomFile) { _dicomFilesQueue.Add(DoWork, dicomFile); } public void Enqueue(VidInfo vidInfo) { _vidInfoQueue.Add(DoWork, vidInfo); } protected abstract bool DoWork(DicomFile arg); protected abstract bool DoWork(VidInfo 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); } DirectoryHelper.CreateDirectory(targetFolder); var dicomFileName = Path.Combine(targetFolder, $"{newGuid}.{SonopostConstants.DicomFileName}"); DicomHelper.Save(dicomFileName, file); return dicomFileName; } protected string Save(string folderName, string vidFilePath, string newGuid, string dateFolder = null) { var targetFolder = Path.Combine(SonopostConstants.DataFolder, folderName); if (dateFolder != null) { targetFolder = Path.Combine(SonopostConstants.DataFolder, folderName, dateFolder); } DirectoryHelper.CreateDirectory(targetFolder); var vidFileName = Path.Combine(targetFolder, $"{newGuid}.{SonopostConstants.VidFileName}"); try { if (File.Exists(vidFilePath)) { File.Move(vidFilePath, vidFileName); return vidFileName; } else { return null; } } catch (Exception ex) { IUS.Common.Log.Logger.WriteLineError($"Save Original Vid File Error:{ex}"); return null; } } protected void DeleteFiles(IEnumerable 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(); } } } }