public async Task DicomSendFilesTest()
        {
            var dataSender        = new DicomDataSender();
            var applicationEntity = new GatewayApplicationEntity("RListenerTest", 131, "127.0.0.1");

            var dicomFiles = new DirectoryInfo(@"Images\1ValidSmall\").GetFiles().Select(x => DicomFile.Open(x.FullName)).ToArray();
            var rtFile     = await DicomFile.OpenAsync(@"Images\LargeSeriesWithContour\rtstruct.dcm").ConfigureAwait(false);

            var resultsDirectory = CreateTemporaryDirectory();

            using (var dicomDataReceiver = new ListenerDataReceiver(new ListenerDicomSaver(resultsDirectory.FullName)))
            {
                StartDicomDataReceiver(dicomDataReceiver, applicationEntity.Port);

                var results = await dataSender.SendFilesAsync(
                    "Hello",
                    applicationEntity.Title,
                    applicationEntity.Port,
                    applicationEntity.IpAddress,
                    dicomFiles).ConfigureAwait(false);

                foreach (var result in results)
                {
                    // Check we can send non-RT files
                    Assert.AreEqual(DicomOperationResult.Success, result.Item2);
                }

                var rtResult = await dataSender.SendFilesAsync(
                    "Hello",
                    applicationEntity.Title,
                    applicationEntity.Port,
                    applicationEntity.IpAddress,
                    rtFile).ConfigureAwait(false);

                Assert.AreEqual(1, rtResult.Count());

                foreach (var result in rtResult)
                {
                    // Check we can send RT files
                    Assert.AreEqual(DicomOperationResult.Success, result.Item2);
                }

                dicomDataReceiver.StopServer();
            }
        }
Exemple #2
0
        public async Task DicomDataReceiverServerStarts()
        {
            var applicationEntity = new GatewayApplicationEntity("RListenerTest", 191, "127.0.0.1");
            var resultsDirectory  = CreateTemporaryDirectory();

            using (var dicomDataReceiver = new ListenerDataReceiver(new ListenerDicomSaver(resultsDirectory.FullName)))
            {
                StartDicomDataReceiver(dicomDataReceiver, applicationEntity.Port);

                var eventCount = 0;
                var folderPath = string.Empty;

                dicomDataReceiver.DataReceived += (sender, e) =>
                {
                    folderPath = e.FolderPath;
                    Interlocked.Increment(ref eventCount);
                };

                Assert.ThrowsException <DicomNetworkException>(() => StartDicomDataReceiver(dicomDataReceiver, applicationEntity.Port));

                var dataSender = new DicomDataSender();
                var echoResult = await dataSender.DicomEchoAsync(
                    "RListener",
                    applicationEntity.Title,
                    applicationEntity.Port,
                    applicationEntity.IpAddress);

                // Check echo
                Assert.IsTrue(echoResult == DicomOperationResult.Success);

                DcmtkHelpers.SendFileUsingDCMTK(
                    @"Images\1ValidSmall\1.dcm",
                    applicationEntity.Port,
                    ScuProfile.LEExplicitCT,
                    TestContext);

                // Wait for all events to finish on the data received
                SpinWait.SpinUntil(() => eventCount >= 3, TimeSpan.FromSeconds(10));

                // Check the file exists
                Assert.IsTrue(File.Exists(Path.Combine(folderPath, @"1.2.840.113619.2.81.290.1.36662.3.1.20151027.220159.dcm")));

                dicomDataReceiver.StopServer();
            }
        }
        public async Task DicomEchoTest()
        {
            var dataSender = new DicomDataSender();

            var applicationEntity = new GatewayApplicationEntity(
                title: "RListenerTest",
                port: new Random().Next(130, ApplicationEntityValidationHelpers.MaximumPortNumber),
                ipAddress: "127.0.0.1");

            var resultsDirectory = CreateTemporaryDirectory();

            using (var dicomDataReceiver = new ListenerDataReceiver(new ListenerDicomSaver(resultsDirectory.FullName)))
            {
                StartDicomDataReceiver(dicomDataReceiver, applicationEntity.Port);

                var result1 = await dataSender.DicomEchoAsync(
                    "Hello",
                    applicationEntity.Title,
                    applicationEntity.Port,
                    applicationEntity.IpAddress).ConfigureAwait(false);

                Assert.AreEqual(DicomOperationResult.Success, result1);

                dicomDataReceiver.StopServer();
            }

            var result2 = await dataSender.DicomEchoAsync(
                "Hello",
                applicationEntity.Title,
                applicationEntity.Port,
                applicationEntity.IpAddress).ConfigureAwait(false);

            Assert.AreEqual(DicomOperationResult.NoResponse, result2);

            // Try ping with IPv6 Address
            var result3 = await dataSender.DicomEchoAsync("Hello", "RListenerTest", 105, "2a00:1450:4009:800::200e").ConfigureAwait(false);

            Assert.AreEqual(DicomOperationResult.NoResponse, result3);
        }
Exemple #4
0
        public async Task DownloadServiceLiveCloudMockConfigEndToEndTest()
        {
            var resultDirectory = CreateTemporaryDirectory();

            var(segmentationId, modelId, data) = await StartFakeSegmentationAsync(@"Images\1ValidSmall\").ConfigureAwait(false);

            var applicationEntity = new GatewayApplicationEntity("RListenerTest", 140, "localhost");

            // Create a Data receiver to receive the RT struct result
            using (var dicomDataReceiver = new ListenerDataReceiver(new ListenerDicomSaver(CreateTemporaryDirectory().FullName)))
            {
                var eventCount = 0;
                var folderPath = string.Empty;

                dicomDataReceiver.DataReceived += (sender, e) =>
                {
                    folderPath = e.FolderPath;
                    Interlocked.Increment(ref eventCount);
                };

                StartDicomDataReceiver(dicomDataReceiver, applicationEntity.Port);

                using (var mockSegmentationClient = GetMockInnerEyeSegmentationClient())
                    using (var pushService = CreatePushService())
                        using (var downloadService = CreateDownloadService(mockSegmentationClient))
                            using (var downloadQueue = downloadService.DownloadQueue)
                            {
                                pushService.Start();
                                downloadService.Start();

                                TransactionalEnqueue(
                                    downloadQueue,
                                    new DownloadQueueItem(
                                        segmentationId: segmentationId,
                                        modelId: modelId,
                                        resultsDirectory: resultDirectory.FullName,
                                        referenceDicomFiles: data,
                                        calledApplicationEntityTitle: applicationEntity.Title,
                                        callingApplicationEntityTitle: applicationEntity.Title,
                                        destinationApplicationEntity: applicationEntity,
                                        tagReplacementJsonString: JsonConvert.SerializeObject(_defaultTagReplacement),
                                        associationGuid: Guid.NewGuid(),
                                        associationDateTime: DateTime.UtcNow,
                                        isDryRun: false));

                                // Wait for all events to finish on the data received
                                SpinWait.SpinUntil(() => eventCount >= 3, TimeSpan.FromMinutes(3));
                            }

                dicomDataReceiver.StopServer();

#pragma warning disable CA1508 // Avoid dead conditional code
                Assert.IsFalse(string.IsNullOrWhiteSpace(folderPath));
#pragma warning restore CA1508 // Avoid dead conditional code

                var files = new DirectoryInfo(folderPath).GetFiles();

                // Check we have a file
                Assert.AreEqual(1, files.Length);

                var dicomFile = await DicomFile.OpenAsync(files[0].FullName).ConfigureAwait(false);

                Assert.IsNotNull(dicomFile);
            }
        }
Exemple #5
0
        public async Task DownloadServiceNoApiConnection()
        {
            var(segmentationId, modelId, data) = await StartFakeSegmentationAsync(@"Images\1ValidSmall\").ConfigureAwait(false);

            var applicationEntity = new GatewayApplicationEntity("RListenerTest", 144, "127.0.0.1");

            // Create a Data receiver to receive the RT struct result
            using (var dicomDataReceiver = new ListenerDataReceiver(new ListenerDicomSaver(CreateTemporaryDirectory().FullName)))
            {
                var eventCount = 0;
                var folderPath = string.Empty;

                dicomDataReceiver.DataReceived += (sender, e) =>
                {
                    folderPath = e.FolderPath;
                    Interlocked.Increment(ref eventCount);
                };

                StartDicomDataReceiver(dicomDataReceiver, applicationEntity.Port);

                using (var mockSegmentationClient = GetMockInnerEyeSegmentationClient())
                    using (var pushService = CreatePushService())
                        using (var downloadService = CreateDownloadService(mockSegmentationClient))
                            using (var downloadQueue = downloadService.DownloadQueue)
                                using (var deadLetterQueue = downloadService.DeadletterMessageQueue)
                                {
                                    // Fake a no response when getting progress
                                    mockSegmentationClient.SegmentationResultException = new HttpRequestException();

                                    pushService.Start();
                                    downloadService.Start();

                                    downloadQueue.Clear();

                                    TransactionalEnqueue(
                                        downloadQueue,
                                        new DownloadQueueItem(
                                            segmentationId: segmentationId,
                                            modelId: modelId,
                                            resultsDirectory: CreateTemporaryDirectory().FullName,
                                            referenceDicomFiles: data,
                                            calledApplicationEntityTitle: applicationEntity.Title,
                                            callingApplicationEntityTitle: applicationEntity.Title,
                                            destinationApplicationEntity: applicationEntity,
                                            tagReplacementJsonString: JsonConvert.SerializeObject(_defaultTagReplacement),
                                            associationGuid: Guid.NewGuid(),
                                            associationDateTime: DateTime.UtcNow,
                                            isDryRun: false));

                                    // Wait
                                    await Task.Delay(TimeSpan.FromSeconds(5)).ConfigureAwait(false);

                                    // Null the exception from the mock client
                                    mockSegmentationClient.SegmentationResultException = null;

                                    // Wait for all events to finish on the data received
                                    SpinWait.SpinUntil(() => eventCount >= 3, TimeSpan.FromMinutes(5));

                                    WaitUntilNoMessagesOnQueue(downloadQueue);

                                    // Check this message has been de-queued
                                    Assert.ThrowsException <MessageQueueReadException>(() => TransactionalDequeue <DownloadQueueItem>(downloadQueue));

                                    Assert.ThrowsException <MessageQueueReadException>(() => TransactionalDequeue <DownloadQueueItem>(deadLetterQueue));
                                }

                dicomDataReceiver.StopServer();

#pragma warning disable CA1508 // Avoid dead conditional code
                Assert.IsFalse(string.IsNullOrWhiteSpace(folderPath));
#pragma warning restore CA1508 // Avoid dead conditional code

                var files = new DirectoryInfo(folderPath).GetFiles();

                // Check we have a file
                Assert.AreEqual(1, files.Length);

                var dicomFile = await DicomFile.OpenAsync(files[0].FullName).ConfigureAwait(false);

                Assert.IsNotNull(dicomFile);
            }
        }