예제 #1
0
        public async Task CStoreRequestSend_16BitJpegFileToScpThatDoesNotSupportJpeg_TransferSuccessfulImplicitLENoPixelData()
        {
            const string file    = @"Test Data/GH538-jpeg14sv1.dcm";
            var          handle  = new ManualResetEventSlim();
            var          success = false;

            var port = Ports.GetNext();

            using (DicomServer.Create <VideoCStoreProvider>(port))
            {
                var request = new DicomCStoreRequest(file);
                request.OnResponseReceived = (req, rsp) =>
                {
                    if (req.Dataset.InternalTransferSyntax.Equals(DicomTransferSyntax.ImplicitVRLittleEndian) &&
                        !req.Dataset.Contains(DicomTag.PixelData) && rsp.Status == DicomStatus.Success)
                    {
                        success = true;
                    }
                    handle.Set();
                };

                var client = new Network.Client.DicomClient("localhost", port, false, "STORESCU", "STORESCP");
                await client.AddRequestAsync(request).ConfigureAwait(false);

                await client.SendAsync().ConfigureAwait(false);

                handle.Wait(10000);

                Assert.True(success);
            }
        }
예제 #2
0
        public async Task Send_SingleRequest_DataSufficientlyTransported()
        {
            int port = Ports.GetNext();

            using (DicomServer.Create <SimpleCStoreProvider>(port))
            {
                DicomDataset command = null, dataset = null;
                var          request = new DicomCStoreRequest(@".\Test Data\CT1_J2KI");
                request.OnResponseReceived = (req, res) =>
                {
                    command = request.Command;
                    dataset = request.Dataset;
                };

                var client = new Network.Client.DicomClient("127.0.0.1", port, false, "SCU", "ANY-SCP");
                await client.AddRequestAsync(request).ConfigureAwait(false);

                await client.SendAsync().ConfigureAwait(false);

                var commandField = command.Get <ushort>(DicomTag.CommandField);
                Assert.Equal((ushort)1, commandField);

                var modality = dataset.Get <string>(DicomTag.Modality);
                Assert.Equal("CT", modality);
            }
        }
예제 #3
0
        public async Task CStoreRequestSend_VideoFileServerSupportsMPEG2_TransferSuccessful()
        {
            const string fileName = @".\Test Data\ETIAM_video_002.dcm";

            var success = false;
            var handle  = new ManualResetEventSlim();

            var port = Ports.GetNext();

            using (DicomServer.Create <VideoCStoreProvider>(port))
            {
                var request = new DicomCStoreRequest(fileName);
                request.OnResponseReceived = (req, rsp) =>
                {
                    success = req.Dataset.InternalTransferSyntax.Equals(DicomTransferSyntax.MPEG2) &&
                              rsp.Status == DicomStatus.Success;
                    handle.Set();
                };

                var client = new Network.Client.DicomClient("localhost", port, false, "STORESCU", "STORESCP");
                await client.AddRequestAsync(request).ConfigureAwait(false);

                await client.SendAsync().ConfigureAwait(false);

                handle.Wait(10000);

                Assert.True(success);
            }
        }
예제 #4
0
        public async Task OnNDeleteRequestAsync_ShouldRespond()
        {
            var port = Ports.GetNext();

            using (DicomServer.Create <AsyncDicomNServiceProvider>(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)
                };

                DicomNDeleteResponse            response = null;
                DicomRequest.OnTimeoutEventArgs timeout  = null;
                var request = new DicomNDeleteRequest(
                    DicomUID.BasicFilmSession,
                    new DicomUID("1.2.3", null, DicomUidType.SOPInstance))
                {
                    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);
            }
        }
예제 #5
0
        public async Task CStoreRequestSend_VideoFileServerSupportsMPEG4_TransferSuccessful()
        {
            const string fileName = @"Test Data/test_720.dcm";
            var          success  = false;
            var          handle   = new ManualResetEventSlim();

            var port = Ports.GetNext();

            using (var server = DicomServer.Create <VideoCStoreProvider>(port))
            {
                server.Logger = _logger.IncludePrefix("VideoCStoreProvider");
                var request = new DicomCStoreRequest(fileName);
                request.OnResponseReceived = (req, rsp) =>
                {
                    success = req.Dataset.InternalTransferSyntax.Equals(
                        DicomTransferSyntax.Lookup(DicomUID.MPEG4AVCH264HighProfileLevel41)) &&
                              rsp.Status == DicomStatus.Success;
                    handle.Set();
                };

                var client = new Network.Client.DicomClient("localhost", port, false, "STORESCU", "STORESCP")
                {
                    Logger = _logger.IncludePrefix("DicomClient")
                };
                await client.AddRequestAsync(request).ConfigureAwait(false);

                await client.SendAsync().ConfigureAwait(false);

                handle.Wait(10000);

                Assert.True(success);
            }
        }
예제 #6
0
        public async Task Send_PrivateTags_DataSufficientlyTransported()
        {
            var port = Ports.GetNext();

            using (DicomServer.Create <SimpleCStoreProvider>(port))
            {
                DicomDataset command = null, requestDataset = null, responseDataset = null;
                var          request = new DicomCStoreRequest(new DicomDataset
                {
                    { DicomTag.CommandField, (ushort)DicomCommandField.CStoreRequest },
                    { DicomTag.AffectedSOPClassUID, DicomUID.CTImageStorage },
                    { DicomTag.MessageID, (ushort)1 },
                    { DicomTag.AffectedSOPInstanceUID, "1.2.3" },
                });

                var privateCreator = DicomDictionary.Default.GetPrivateCreator("Testing");
                var privTag1       = new DicomTag(4013, 0x008, privateCreator);
                var privTag2       = new DicomTag(4013, 0x009, privateCreator);
                DicomDictionary.Default.Add(new DicomDictionaryEntry(privTag1, "testTag1", "testKey1", DicomVM.VM_1, false, DicomVR.CS));
                DicomDictionary.Default.Add(new DicomDictionaryEntry(privTag2, "testTag2", "testKey2", DicomVM.VM_1, false, DicomVR.CS));

                request.Dataset = new DicomDataset();
                request.Dataset.Add(DicomTag.Modality, "CT");
                request.Dataset.Add(privTag1, "TESTA");
                request.Dataset.Add(new DicomCodeString(privTag2, "TESTB"));
                //{
                //    { DicomTag.Modality, "CT" },
                //    new DicomCodeString(privTag1, "test1"),
                //    { privTag2, "test2" },
                //};

                request.OnResponseReceived = (req, res) =>
                {
                    command         = req.Command;
                    requestDataset  = req.Dataset;
                    responseDataset = res.Dataset;
                };

                var client = new Network.Client.DicomClient("127.0.0.1", port, false, "SCU", "ANY-SCP");
                await client.AddRequestAsync(request).ConfigureAwait(false);

                await client.SendAsync().ConfigureAwait(false);

                Assert.Equal((ushort)1, command.Get <ushort>(DicomTag.CommandField));

                Assert.Equal("CT", requestDataset.Get <string>(DicomTag.Modality));
                Assert.Equal("TESTB", requestDataset.Get <string>(privTag2, null));
                Assert.Equal("TESTA", requestDataset.Get <string>(privTag1, null));

                Assert.Equal("CT", responseDataset.Get <string>(DicomTag.Modality));
                // Assert.Equal("test1", responseDataset.Get<DicomCodeString>(privTag1).Get<string>());
                Assert.Equal("TESTB", responseDataset.Get <string>(privTag2, -1, null));
                Assert.Equal("TESTA", responseDataset.Get <string>(privTag1, null));
            }
        }
예제 #7
0
파일: GH745.cs 프로젝트: fo-dicom/fo-dicom
        public async Task DicomClientShallNotCloseConnectionTooEarly_CEchoSerialAsync(int expected)
        {
            var port         = Ports.GetNext();
            var testLogger   = _logger.IncludePrefix("GH745");
            var clientLogger = _logger.IncludePrefix(nameof(Network.Client.DicomClient));
            var serverLogger = _logger.IncludePrefix(nameof(DicomCEchoProvider));

            using (var server = DicomServer.Create <DicomCEchoProvider>(port))
            {
                server.Logger = serverLogger;
                while (!server.IsListening)
                {
                    await Task.Delay(50);
                }

                var actual = 0;

                var client = new Network.Client.DicomClient("127.0.0.1", port, false, "SCU", "ANY-SCP", 600 * 1000)
                {
                    Logger = clientLogger,
                    AssociationLingerTimeoutInMs = 1 // No need to linger, we only send one request at a time
                };
                for (var i = 0; i < expected; i++)
                {
                    await client.AddRequestAsync(
                        new DicomCEchoRequest
                    {
                        OnResponseReceived = (req, res) =>
                        {
                            testLogger.Info("Response #{0} / expected #{1}", actual, req.UserState);
                            Interlocked.Increment(ref actual);
                            testLogger.Info("         #{0} / expected #{1}", actual - 1, req.UserState);
                        },
                        UserState = i
                    }
                        ).ConfigureAwait(false);

                    testLogger.Info("Sending #{0}", i);
                    await client.SendAsync().ConfigureAwait(false);

                    testLogger.Info("Sent (or timed out) #{0}", i);
                    //if (i != actual-1)
                    //{
                    //    output.WriteLine("  waiting #{0}", i);
                    //    await Task.Delay((int)TimeSpan.FromSeconds(1).TotalMilliseconds);
                    //    output.WriteLine("  waited #{0}", i);
                    //}
                }

                Assert.Equal(expected, actual);
            }
        }
예제 #8
0
        public async Task CStoreRequestSend_8And16BitJpegFiles_TransferSuccessful()
        {
            const string file1     = @"Test Data/GH538-jpeg1.dcm";
            const string file2     = @"Test Data/GH538-jpeg14sv1.dcm";
            var          handle1   = new ManualResetEventSlim();
            var          handle2   = new ManualResetEventSlim();
            var          successes = 0;

            var port = Ports.GetNext();

            using (DicomServer.Create <SimpleCStoreProvider>(port))
            {
                var request1 = new DicomCStoreRequest(file1);
                request1.OnResponseReceived = (req, rsp) =>
                {
                    if (req.Dataset.InternalTransferSyntax.Equals(DicomTransferSyntax.JPEGProcess1) &&
                        rsp.Status == DicomStatus.Success)
                    {
                        ++successes;
                    }
                    handle1.Set();
                };

                var request2 = new DicomCStoreRequest(file2);
                request2.OnResponseReceived = (req, rsp) =>
                {
                    if (req.Dataset.InternalTransferSyntax.Equals(DicomTransferSyntax.JPEGProcess14SV1) &&
                        rsp.Status == DicomStatus.Success)
                    {
                        ++successes;
                    }
                    handle2.Set();
                };

                var client = new Network.Client.DicomClient("localhost", port, false, "STORESCU", "STORESCP");
                await client.AddRequestAsync(request1).ConfigureAwait(false);

                await client.AddRequestAsync(request2).ConfigureAwait(false);

                await client.SendAsync();

                handle1.Wait(10000);
                handle2.Wait(10000);

                Assert.Equal(2, successes);
            }
        }
예제 #9
0
파일: GH745.cs 프로젝트: fo-dicom/fo-dicom
        public async Task DicomClientShallNotCloseConnectionTooEarly_CEchoParallelAsync(int expected)
        {
            int port = Ports.GetNext();

            var testLogger   = _logger.IncludePrefix("GH745");
            var clientLogger = _logger.IncludePrefix(nameof(Network.Client.DicomClient));
            var serverLogger = _logger.IncludePrefix(nameof(DicomCEchoProvider));

            using (var server = DicomServer.Create <DicomCEchoProvider>(port))
            {
                server.Logger = serverLogger;
                while (!server.IsListening)
                {
                    await Task.Delay(50);
                }

                var actual = 0;

                var requests = Enumerable.Range(0, expected).Select(
                    async requestIndex =>
                {
                    var client = new Network.Client.DicomClient("127.0.0.1", port, false, "SCU", "ANY-SCP", 600 * 1000)
                    {
                        Logger = clientLogger
                    };
                    await client.AddRequestAsync(
                        new DicomCEchoRequest
                    {
                        OnResponseReceived = (req, res) =>
                        {
                            testLogger.Info("Response #{0}", requestIndex);
                            Interlocked.Increment(ref actual);
                        }
                    }
                        ).ConfigureAwait(false);

                    testLogger.Info("Sending #{0}", requestIndex);
                    await client.SendAsync().ConfigureAwait(false);
                    testLogger.Info("Sent (or timed out) #{0}", requestIndex);
                }
                    ).ToArray();

                await Task.WhenAll(requests).ConfigureAwait(false);

                Assert.Equal(expected, actual);
            }
        }
예제 #10
0
        public async Task Send_FromDicomClient_DoesNotDeadlock()
        {
            var port = Ports.GetNext();

            using (var server = DicomServer.Create <DicomCEchoProvider>(port))
            {
                server.Logger = new XUnitDicomLogger(_output).IncludeTimestamps().IncludeThreadId().IncludePrefix("DicomCEchoProvider");
                var client = new Network.Client.DicomClient("127.0.0.1", port, false, "SCU", "ANY-SCP")
                {
                    Logger = new XUnitDicomLogger(_output).IncludeTimestamps().IncludeThreadId().IncludePrefix("DicomClient")
                };
                for (var i = 0; i < 10; i++)
                {
                    await client.AddRequestAsync(new DicomCEchoRequest()).ConfigureAwait(false);
                }

                await client.SendAsync().ConfigureAwait(false);

                Assert.Empty(client.QueuedRequests);
            }
        }
예제 #11
0
        public async Task DicomClientSend_TooManyPresentationContexts_YieldsInformativeException()
        {
            var port = Ports.GetNext();

            using (DicomServer.Create <DicomCEchoProvider>(port))
            {
                var client = new Network.Client.DicomClient("localhost", port, false, "SCU", "SCP");

                // this just illustrates the issue of too many presentation contexts, not real world application.
                var pcs =
                    DicomPresentationContext.GetScpRolePresentationContextsFromStorageUids(
                        DicomStorageCategory.None,
                        DicomTransferSyntax.ImplicitVRLittleEndian);

                client.AdditionalPresentationContexts.AddRange(pcs);

                var exception = await Record.ExceptionAsync(() => client.SendAsync());

                Assert.IsType <DicomNetworkException>(exception);
            }
        }