public async Task OnCEchoRequestAsync_ShouldRespond() { var port = Ports.GetNext(); using (DicomServer.Create <AsyncDicomCEchoProvider>(port, logger: _logger.IncludePrefix("DicomServer"))) { var client = new Network.Client.DicomClient("127.0.0.1", port, false, "SCU", "ANY-SCP") { Logger = _logger.IncludePrefix(typeof(DicomClient).Name) }; DicomCEchoResponse response = null; DicomRequest.OnTimeoutEventArgs timeout = null; var request = new DicomCEchoRequest { OnResponseReceived = (req, res) => response = res, OnTimeout = (sender, args) => timeout = args }; await client.AddRequestAsync(request).ConfigureAwait(false); await client.SendAsync().ConfigureAwait(false); Assert.NotNull(response); Assert.Equal(DicomStatus.Success, response.Status); Assert.Null(timeout); } }
private Task <DicomCEchoResponse> SendEchoRequestWithTimeout(DicomClient dicomClient, int timeoutInMilliseconds = 3000) { var request = new DicomCEchoRequest(); var logger = _logger.IncludePrefix("C-Echo request"); var responseCompletionSource = new TaskCompletionSource <DicomCEchoResponse>(); var responseCancellationSource = new CancellationTokenSource(timeoutInMilliseconds); var cancellationRegistration = responseCancellationSource.Token.Register(() => { logger.Error($"Request [{request.MessageID}] timed out!"); responseCompletionSource.SetCanceled(); }); request.OnResponseReceived += (req, res) => { logger.Info($"Response [{request.MessageID}] received!"); responseCompletionSource.SetResult(res); }; dicomClient.AddRequest(request); // ReSharper disable once MethodSupportsCancellation Let's not cancel the cancellation, ha ha! responseCompletionSource.Task.ContinueWith(_ => cancellationRegistration.Dispose()); return(responseCompletionSource.Task); }
public void Send_EchoRequestToExternalServer_ShouldSucceed() { var result = false; var awaiter = new ManualResetEventSlim(); var client = new DicomClient(); var req = new DicomCEchoRequest(); req.OnResponseReceived = (rq, rsp) => { if (rsp.Status == DicomStatus.Success) { result = true; } awaiter.Set(); }; client.AddRequest(req); try { client.Send("localhost", 11112, false, "SCU", "COMMON"); awaiter.Wait(); } catch (Exception ex) { result = false; client.Logger.Error("Send failed, exception: {0}", ex); awaiter.Set(); } Assert.True(result); }
public async Task AcceptStoreContexts() { int port = Ports.GetNext(); using (DicomServer.Create <AcceptOnlyEchoStoreProvider>(port)) { var echoReq = new DicomCEchoRequest(); DicomStatus echoStatus = DicomStatus.Pending; echoReq.OnResponseReceived += (req, resp) => echoStatus = resp.Status; var storeReq = new DicomCStoreRequest(@".\Test Data\CT1_J2KI"); DicomStatus storeStatus = DicomStatus.Pending; storeReq.OnResponseReceived += (req, resp) => storeStatus = resp.Status; var filmSession = new FilmSession(DicomUID.BasicFilmSession, DicomUID.Generate()); var printReq = new DicomNCreateRequest(filmSession.SOPClassUID, filmSession.SOPInstanceUID); DicomStatus printStatus = DicomStatus.Pending; printReq.OnResponseReceived += (req, resp) => printStatus = resp.Status; var client = new Client.DicomClient("127.0.0.1", port, false, "SCU", "ANY-SCP"); await client.AddRequestsAsync(echoReq, storeReq, printReq); await client.SendAsync(); Assert.Equal(DicomStatus.Success, echoStatus); Assert.Equal(DicomStatus.Success, storeStatus); Assert.Equal(DicomStatus.SOPClassNotSupported, printStatus); } }
public DicomCEchoResponse OnCEchoRequest(DicomCEchoRequest request) { return(new DicomCEchoResponse(request, DicomStatus.Success) { Dataset = request.Dataset }); }
public DicomCEchoResponse OnCEchoRequest(DicomCEchoRequest request) { _onRequest(request); _requests.Add(request); return(new DicomCEchoResponse(request, DicomStatus.Success)); }
public DicomCEchoResponse OnCEchoRequest(DicomCEchoRequest request) { _onRequest(request); _requests.Add(request); WaitForALittleBit().GetAwaiter().GetResult(); return(new DicomCEchoResponse(request, DicomStatus.Success)); }
public void Send_ToDicomServer_ReturnsSuccess() { Task.Run(() => new DicomServer<DicomCEchoProvider>(104)).Wait(100); var client = new DicomClient(); client.NegotiateAsyncOps(); DicomStatus status = null; var request = new DicomCEchoRequest { OnResponseReceived = (echoRequest, response) => status = response.Status }; client.AddRequest(request); client.Send("localhost", 104, false, "ECHOSCU", "ECHOSCP"); while (status == null) Thread.Sleep(10); Assert.AreEqual(DicomStatus.Success, status); }
public void Send_SingleRequest_Recognized() { int port = Ports.GetNext(); using (DicomServer.Create<DicomCEchoProvider>(port)) { var counter = 0; var request = new DicomCEchoRequest { OnResponseReceived = (req, res) => ++counter }; var client = new DicomClient(); client.AddRequest(request); client.Send("127.0.0.1", port, false, "SCU", "ANY-SCP"); Assert.Equal(1, counter); } }
public void Send_SingleRequest_Recognized() { int port = Ports.GetNext(); using (DicomServer.Create <DicomCEchoProvider>(port)) { var counter = 0; var request = new DicomCEchoRequest { OnResponseReceived = (req, res) => Interlocked.Increment(ref counter) }; var client = new DicomClient(); client.AddRequest(request); client.Send("127.0.0.1", port, false, "SCU", "ANY-SCP"); Assert.Equal(1, counter); } }
public void BeginSend_SingleRequest_Recognized() { int port = Ports.GetNext(); using (new DicomServer <DicomCEchoProvider>(port)) { var counter = 0; var request = new DicomCEchoRequest { OnResponseReceived = (req, res) => ++ counter }; var client = new DicomClient(); client.AddRequest(request); client.EndSend(client.BeginSend("127.0.0.1", port, false, "SCU", "ANY-SCP", null, null)); Assert.Equal(1, counter); } }
public async Task SendAsync_SingleRequest_Recognized() { int port = Ports.GetNext(); using (DicomServer.Create <DicomCEchoProvider>(port)) { var counter = 0; var request = new DicomCEchoRequest { OnResponseReceived = (req, res) => Interlocked.Increment(ref counter) }; var client = new DicomClient(); client.AddRequest(request); var task = client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); await Task.WhenAny(task, Task.Delay(10000)); Assert.Equal(1, counter); } }
public void Send_ToDicomServer_ReturnsSuccess() { Task.Run(() => new DicomServer <DicomCEchoProvider>(104)).Wait(100); var client = new DicomClient(); client.NegotiateAsyncOps(); DicomStatus status = null; var request = new DicomCEchoRequest { OnResponseReceived = (echoRequest, response) => status = response.Status }; client.AddRequest(request); client.Send("localhost", 104, false, "ECHOSCU", "ECHOSCP"); while (status == null) { Thread.Sleep(10); } Assert.AreEqual(DicomStatus.Success, status); }
public DicomCEchoResponse OnCEchoRequest(DicomCEchoRequest request) { return new DicomCEchoResponse(request, DicomStatus.Success); }
public void Send_EchoRequestToExternalServer_ShouldSucceed() { var result = false; var awaiter = new ManualResetEventSlim(); var client = new DicomClient(); var req = new DicomCEchoRequest(); req.OnResponseReceived = (rq, rsp) => { if (rsp.Status == DicomStatus.Success) { result = true; } awaiter.Set(); }; client.AddRequest(req); try { client.Send("localhost", 11112, false, "SCU", "COMMON"); awaiter.Wait(); } catch (Exception ex) { result = false; Console.WriteLine(ex); awaiter.Set(); } Assert.True(result); }
public async Task SendAsync_SingleRequest_Recognized() { int port = Ports.GetNext(); using (DicomServer.Create<DicomCEchoProvider>(port)) { var counter = 0; var request = new DicomCEchoRequest { OnResponseReceived = (req, res) => ++counter }; var client = new DicomClient(); client.AddRequest(request); var task = client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); await Task.WhenAny(task, Task.Delay(10000)); Assert.Equal(1, counter); } }
public DicomCEchoResponse OnCEchoRequest(DicomCEchoRequest request) { this.Logger.Info("Received verification request from AE {0} with IP: {1}", CallingAE, RemoteIP); return new DicomCEchoResponse(request, DicomStatus.Success); }
public DicomCEchoResponse OnCEchoRequest(DicomCEchoRequest request) { return(new DicomCEchoResponse(request, DicomStatus.Success)); }
public DicomCEchoResponse(DicomCEchoRequest request, DicomStatus status) : base(request, status) { }
public async Task <DicomCEchoResponse> OnCEchoRequestAsync(DicomCEchoRequest request) { return(new DicomCEchoResponse(request, DicomStatus.Success)); }
public FoDicomNetwork.DicomCEchoResponse OnCEchoRequest(FoDicomNetwork.DicomCEchoRequest request) { _logger?.Log(LogLevel.Information, $"C-ECH request received"); return(new FoDicomNetwork.DicomCEchoResponse(request, FoDicomNetwork.DicomStatus.Success)); }
public DicomCEchoResponse OnCEchoRequest(DicomCEchoRequest request, DicomPresentationContext presentationContext) { return new DicomCEchoResponse(request, DicomStatus.Success); }
public DicomCEchoResponse OnCEchoRequest(DicomCEchoRequest request, DicomPresentationContext presentationContext) { return(new DicomCEchoResponse(request, DicomStatus.Success)); }