Пример #1
0
        public async Task Send_FromIpv4ToIpv6AnyListenerKnownSOPClass_SendFails()
        {
            var port = Ports.GetNext();

            using (DicomServerFactory.Create <SimpleCStoreProvider>(NetworkManager.IPv6Any, port, logger: _logger.IncludePrefix("DicomServer")))
            {
                var request = new DicomCStoreRequest(TestData.Resolve("CT-MONO2-16-ankle"));

                var client = DicomClientFactory.Create(NetworkManager.IPv4Loopback, port, false, "SCU", "ANY-SCP");
                client.Logger = _logger.IncludePrefix("DicomClient");
                await client.AddRequestAsync(request);

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

                Assert.NotNull(exception);
                Assert.Contains("Socket", (exception.InnerException ?? exception).GetType().Name);
            }
        }
Пример #2
0
        public void Constructor_EstablishTwoWithSamePort_ShouldYieldAccessibleException()
        {
            var port = Ports.GetNext();

            var server1 = DicomServerFactory.Create <DicomCEchoProvider>(port, logger: _logger.IncludePrefix("DicomServer"));

            while (!server1.IsListening)
            {
                Thread.Sleep(10);
            }

            var exception = Record.Exception(() => DicomServerFactory.Create <DicomCEchoProvider>(port, logger: _logger.IncludePrefix("DicomServer")));

            Assert.IsType <DicomNetworkException>(exception);

            Assert.True(server1.IsListening);
            Assert.Null(server1.Exception);
        }
Пример #3
0
        public void Create_TwiceOnSamePortWithDisposalInBetween_DoesNotThrow()
        {
            var port = Ports.GetNext();

            using (DicomServerFactory.Create <DicomCEchoProvider>(port, logger: _logger.IncludePrefix("DicomServer")))
            {
                /* do nothing here */
            }

            var e = Record.Exception(
                () =>
            {
                using (DicomServerFactory.Create <DicomCEchoProvider>(port, logger: _logger.IncludePrefix("DicomServer")))
                {
                    Assert.NotNull(DicomServerRegistry.Get(port)?.DicomServer);
                }
            });

            Assert.Null(e);
        }
Пример #4
0
        public void IsListening_DicomServerStoppedOnPort_ReturnsFalse()
        {
            var port = Ports.GetNext();

            using var server = DicomServerFactory.Create <DicomCEchoProvider>(port, logger: _logger.IncludePrefix("DicomServer"));
            while (!server.IsListening)
            {
                Thread.Sleep(10);
            }
            server.Stop();
            while (server.IsListening)
            {
                Thread.Sleep(10);
            }

            var dicomServer = DicomServerRegistry.Get(port)?.DicomServer;

            Assert.NotNull(dicomServer);
            Assert.False(dicomServer.IsListening);
        }
Пример #5
0
        public async Task Send_FromDicomClient_DoesNotDeadlock()
        {
            var port = Ports.GetNext();

            using var server = DicomServerFactory.Create <DicomCEchoProvider>(port);

            server.Logger = new XUnitDicomLogger(_output).IncludeTimestamps().IncludeThreadId().IncludePrefix("DicomCEchoProvider");
            var client = DicomClientFactory.Create("127.0.0.1", port, false, "SCU", "ANY-SCP");

            client.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.False(client.IsSendRequired);
        }
Пример #6
0
        public async Task Send_LoopbackListenerKnownSOPClass_SendSucceeds()
        {
            var port = Ports.GetNext();

            using (DicomServerFactory.Create <SimpleCStoreProvider>(NetworkManager.IPv4Loopback, port, logger: _logger.IncludePrefix("DicomServer")))
            {
                DicomStatus status  = null;
                var         request = new DicomCStoreRequest(TestData.Resolve("CT-MONO2-16-ankle"))
                {
                    OnResponseReceived = (req, res) => status = res.Status
                };

                var client = DicomClientFactory.Create(NetworkManager.IPv4Loopback, port, false, "SCU", "ANY-SCP");
                client.Logger = _logger.IncludePrefix("DicomClient");
                await client.AddRequestAsync(request);

                await client.SendAsync();

                Assert.Equal(DicomStatus.Success, status);
            }
        }
Пример #7
0
        public void Stop_IsListening_TrueUntilStopRequested()
        {
            var port = Ports.GetNext();

            var server = DicomServerFactory.Create <DicomCEchoProvider>(port, logger: _logger.IncludePrefix("DicomServer"));

            while (!server.IsListening)
            {
                Thread.Sleep(10);
            }

            for (var i = 0; i < 10; ++i)
            {
                Thread.Sleep(500);
                Assert.True(server.IsListening);
            }

            server.Stop();
            Thread.Sleep(1000);

            Assert.False(server.IsListening);
        }
Пример #8
0
        public async Task SendMaxPDU()
        {
            var  port            = Ports.GetNext();
            uint serverPduLength = 400000;
            uint clientPduLength = serverPduLength / 2;

            using var server            = DicomServerFactory.Create <DicomCEchoProvider>(port);
            server.Options.MaxPDULength = serverPduLength;

            var client = DicomClientFactory.Create("127.0.0.1", port, false, "SCU", "ANY-SCP");

            client.ServiceOptions.MaxPDULength = clientPduLength; // explicitly choose a different value
            await client.AddRequestAsync(new DicomCEchoRequest());

            uint serverPduInAssociationAccepted = 0;

            client.AssociationAccepted += (sender, e) => serverPduInAssociationAccepted = e.Association.MaximumPDULength;

            await client.SendAsync();

            Assert.Equal(serverPduLength, serverPduInAssociationAccepted);
        }
Пример #9
0
        public void Create_MultipleInstancesDifferentPorts_AllRegistered()
        {
            var ports = new int[20].Select(i => Ports.GetNext()).ToArray();

            foreach (var port in ports)
            {
                var server = DicomServerFactory.Create <DicomCEchoProvider>(port, logger: _logger.IncludePrefix("DicomServer"));
                while (!server.IsListening)
                {
                    Thread.Sleep(10);
                }
            }

            foreach (var port in ports)
            {
                Assert.Equal(port, DicomServerRegistry.Get(port)?.DicomServer.Port);
            }

            foreach (var port in ports)
            {
                DicomServerRegistry.Get(port)?.DicomServer.Dispose();
            }
        }
Пример #10
0
        public async Task ClientHandleNEventReport_SynchronousEvent()
        {
            var port = Ports.GetNext();

            using (DicomServerFactory.Create <SimpleStorageComitmentProvider>(port))
            {
                DicomStatus status                   = null;
                int         verifiedInstances        = 0;
                DateTime    stampNActionResponse     = DateTime.MinValue;
                DateTime    stampNEventReportRequest = DateTime.MinValue;

                var dicomClient = DicomClientFactory.Create("127.0.0.1", port, false, "SCU", "ANY-SCP");

                var nActionDicomDataSet = new DicomDataset
                {
                    { DicomTag.TransactionUID, DicomUIDGenerator.GenerateDerivedFromUUID().UID },
                    {
                        DicomTag.ReferencedSOPSequence,
                        new DicomDataset()
                        {
                            { DicomTag.ReferencedSOPClassUID, "1.2.840.10008.5.1.4.1.1.1" },
                            { DicomTag.ReferencedSOPInstanceUID, "1.3.46.670589.30.2273540226.4.54" }
                        },
                        new DicomDataset()
                        {
                            { DicomTag.ReferencedSOPClassUID, "1.2.840.10008.5.1.4.1.1.1" },
                            { DicomTag.ReferencedSOPInstanceUID, "1.3.46.670589.30.2273540226.4.59" }
                        }
                    }
                };

                var nActionRequest = new DicomNActionRequest(DicomUID.StorageCommitmentPushModel, DicomUID.StorageCommitmentPushModel, 1)
                {
                    Dataset            = nActionDicomDataSet,
                    OnResponseReceived = (DicomNActionRequest request, DicomNActionResponse response) =>
                    {
                        status = response.Status;
                        stampNActionResponse = DateTime.Now;
                    },
                };

                await dicomClient.AddRequestAsync(nActionRequest);

                dicomClient.OnNEventReportRequest = (eventReq) =>
                {
                    var refSopSequence = eventReq.Dataset.GetSequence(DicomTag.ReferencedSOPSequence);
                    foreach (var item in refSopSequence.Items)
                    {
                        verifiedInstances += 1;
                    }
                    stampNEventReportRequest = DateTime.Now;
                    return(Task.FromResult(new DicomNEventReportResponse(eventReq, DicomStatus.Success)));
                };

                dicomClient.ClientOptions.AssociationLingerTimeoutInMs = (int)TimeSpan.FromSeconds(5).TotalMilliseconds;
                await dicomClient.SendAsync().ConfigureAwait(false);

                Assert.Equal(DicomStatus.Success, status);
                Assert.Equal(2, verifiedInstances);
                Assert.True(stampNActionResponse < stampNEventReportRequest);
            }
        }