123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- 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
- {
- /// <summary>
- /// save dicom to file
- /// </summary>
- /// <param name="fileName"></param>
- /// <param name="dicomFile"></param>
- 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<bool> 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;
- }
- }
- }
|