コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
 public DicomCEchoResponse OnCEchoRequest(DicomCEchoRequest request)
 {
     return(new DicomCEchoResponse(request, DicomStatus.Success)
     {
         Dataset = request.Dataset
     });
 }
コード例 #6
0
            public DicomCEchoResponse OnCEchoRequest(DicomCEchoRequest request)
            {
                _onRequest(request);

                _requests.Add(request);

                return(new DicomCEchoResponse(request, DicomStatus.Success));
            }
コード例 #7
0
            public DicomCEchoResponse OnCEchoRequest(DicomCEchoRequest request)
            {
                _onRequest(request);

                _requests.Add(request);

                WaitForALittleBit().GetAwaiter().GetResult();

                return(new DicomCEchoResponse(request, DicomStatus.Success));
            }
コード例 #8
0
		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);
		}
コード例 #9
0
ファイル: DicomClientTest.cs プロジェクト: aerik/fo-dicom
        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);
            }
        }
コード例 #10
0
        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);
            }
        }
コード例 #11
0
ファイル: DicomClientTest.cs プロジェクト: zcr01/fo-dicom
        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);
            }
        }
コード例 #12
0
        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);
            }
        }
コード例 #13
0
        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);
        }
コード例 #14
0
ファイル: DicomClientTest.cs プロジェクト: aerik/fo-dicom
 public DicomCEchoResponse OnCEchoRequest(DicomCEchoRequest request)
 {
     return new DicomCEchoResponse(request, DicomStatus.Success);
 }
コード例 #15
0
ファイル: DicomClientTest.cs プロジェクト: aerik/fo-dicom
        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);
        }
コード例 #16
0
ファイル: DicomClientTest.cs プロジェクト: aerik/fo-dicom
        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);
            }
        }
コード例 #17
0
ファイル: PrintService.cs プロジェクト: dremerdt/fo-dicom
 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);
 }
コード例 #18
0
 public DicomCEchoResponse OnCEchoRequest(DicomCEchoRequest request)
 {
     return(new DicomCEchoResponse(request, DicomStatus.Success));
 }
コード例 #19
0
 public DicomCEchoResponse(DicomCEchoRequest request, DicomStatus status) : base(request, status)
 {
 }
コード例 #20
0
 public async Task <DicomCEchoResponse> OnCEchoRequestAsync(DicomCEchoRequest request)
 {
     return(new DicomCEchoResponse(request, DicomStatus.Success));
 }
コード例 #21
0
 public FoDicomNetwork.DicomCEchoResponse OnCEchoRequest(FoDicomNetwork.DicomCEchoRequest request)
 {
     _logger?.Log(LogLevel.Information, $"C-ECH request received");
     return(new FoDicomNetwork.DicomCEchoResponse(request, FoDicomNetwork.DicomStatus.Success));
 }
コード例 #22
0
ファイル: Program.cs プロジェクト: raysearchlabs/fo-dicom
			public DicomCEchoResponse OnCEchoRequest(DicomCEchoRequest request, DicomPresentationContext presentationContext) {
				return new DicomCEchoResponse(request, DicomStatus.Success);
			}
コード例 #23
0
 public DicomCEchoResponse OnCEchoRequest(DicomCEchoRequest request, DicomPresentationContext presentationContext)
 {
     return(new DicomCEchoResponse(request, DicomStatus.Success));
 }