using Dicom; using Dicom.Network; using System.IO; using System.Threading; using System.Threading.Tasks; using Vinno.IUS.Common.Log; using static Dicom.Network.DicomCEchoRequest; using DicomClient = Dicom.Network.Client.DicomClient; namespace Vinno.FIS.Sonopost.Helpers { internal class DicomHelper { /// /// save dicom to file /// /// /// public static void Save(string fileName, DicomFile dicomFile) { using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite, 65536, FileOptions.WriteThrough)) { dicomFile.Save(fs); fs.Flush(); } } public static async Task TestDicomAsync(string address, int port, string localAeTitle, string targetAeTitle) { try { bool success = false; var resetEvent = new ManualResetEvent(false); var dicomClient = new DicomClient(address, port, false, localAeTitle, targetAeTitle); var echo = new DicomCEchoRequest(); ResponseDelegate reponse = (DicomCEchoRequest req, DicomCEchoResponse response) => { success = response.Status == DicomStatus.Success; Logger.WriteLineInfo($"Test DicomAsync Status :{response.Status}"); resetEvent.Set(); }; echo.OnResponseReceived += reponse; await dicomClient.AddRequestAsync(echo); Task.Run(() => { try { dicomClient.SendAsync(); } catch { //ignore } }); resetEvent.WaitOne(5000); echo.OnResponseReceived -= reponse; return success; } catch { //ignore } return false; } } }