public async Task OnCGetRequestAsync_Pending_ShouldRespond() { var port = Ports.GetNext(); using (DicomServerFactory.Create <PendingAsyncDicomCGetProvider>(port, logger: _logger.IncludePrefix("DicomServer"))) { var client = DicomClientFactory.Create("127.0.0.1", port, false, "SCU", "ANY-SCP"); client.Logger = _logger.IncludePrefix(typeof(DicomClient).Name); var responses = new ConcurrentQueue <DicomCGetResponse>(); DicomRequest.OnTimeoutEventArgs timeout = null; var studyInstanceUID = DicomUIDGenerator.GenerateDerivedFromUUID().ToString(); var request = new DicomCGetRequest(studyInstanceUID) { OnResponseReceived = (req, res) => responses.Enqueue(res), OnTimeout = (sender, args) => timeout = args }; await client.AddRequestAsync(request).ConfigureAwait(false); await client.SendAsync().ConfigureAwait(false); Assert.Collection( responses, response1 => Assert.Equal(DicomStatus.Pending, response1.Status), response2 => Assert.Equal(DicomStatus.Pending, response2.Status), response3 => Assert.Equal(DicomStatus.Success, response3.Status) ); Assert.Null(timeout); } }
public async Task OnCStoreRequestAsync_PreferedTransfersyntax() { var port = Ports.GetNext(); using (DicomServerFactory.Create <AsyncDicomCStoreProviderPreferingUncompressedTS>(port, logger: _logger.IncludePrefix("DicomServer"))) { var client = DicomClientFactory.Create("127.0.0.1", port, false, "SCU", "ANY-SCP"); client.Logger = _logger.IncludePrefix(typeof(DicomClient).Name); int numberOfContexts = 0; DicomTransferSyntax accpetedTS = null; // create a request with a jpeg-encoded file var request = new DicomCStoreRequest(TestData.Resolve("CT1_J2KI")); client.AssociationAccepted += (sender, e) => { numberOfContexts = e.Association.PresentationContexts.Count; accpetedTS = e.Association.PresentationContexts.First().AcceptedTransferSyntax; }; await client.AddRequestAsync(request).ConfigureAwait(false); await client.SendAsync().ConfigureAwait(false); Assert.Equal(2, numberOfContexts); // one for the jpeg2k TS and one for the mandatory ImplicitLittleEndian Assert.Equal(DicomTransferSyntax.JPEG2000Lossy, accpetedTS); } }
public async Task AcceptStoreContexts() { int port = Ports.GetNext(); using (DicomServerFactory.Create <AcceptOnlyEchoStoreProvider>(port)) { var echoReq = new DicomCEchoRequest(); DicomStatus echoStatus = DicomStatus.Pending; echoReq.OnResponseReceived += (req, resp) => echoStatus = resp.Status; var storeReq = new DicomCStoreRequest(TestData.Resolve("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 = DicomClientFactory.Create("127.0.0.1", port, false, "SCU", "ANY-SCP"); await client.AddRequestsAsync(new DicomRequest[] { echoReq, storeReq, printReq }); await client.SendAsync(); Assert.Equal(DicomStatus.Success, echoStatus); Assert.Equal(DicomStatus.Success, storeStatus); Assert.Equal(DicomStatus.SOPClassNotSupported, printStatus); } }
public async Task CStoreRequestSend_16BitJpegFileToScpThatDoesNotSupportJpeg_TransferSuccessfulImplicitLENoPixelData() { string file = TestData.Resolve("GH538-jpeg14sv1.dcm"); var handle = new ManualResetEventSlim(); var success = false; var port = Ports.GetNext(); using (DicomServerFactory.Create <VideoCStoreProvider>(port)) { var request = new DicomCStoreRequest(file) { 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 = DicomClientFactory.Create("localhost", port, false, "STORESCU", "STORESCP"); await client.AddRequestAsync(request).ConfigureAwait(false); await client.SendAsync().ConfigureAwait(false); handle.Wait(10000); Assert.True(success); } }
public async Task OnCStoreRequestAsync_ShouldRespond() { var port = Ports.GetNext(); using (DicomServerFactory.Create <AsyncDicomCStoreProvider>(port, logger: _logger.IncludePrefix("DicomServer"))) { var client = DicomClientFactory.Create("127.0.0.1", port, false, "SCU", "ANY-SCP"); client.Logger = _logger.IncludePrefix(typeof(DicomClient).Name); DicomCStoreResponse response = null; DicomRequest.OnTimeoutEventArgs timeout = null; var request = new DicomCStoreRequest(TestData.Resolve("10200904.dcm")) { 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); } }
public async Task OnNDeleteRequestAsync_ShouldRespond() { var port = Ports.GetNext(); using (DicomServerFactory.Create <AsyncDicomNServiceProvider>(port, logger: _logger.IncludePrefix("DicomServer"))) { var client = DicomClientFactory.Create("127.0.0.1", port, false, "SCU", "ANY-SCP"); client.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); } }
public async Task Send_PrivateNotRegisteredSOPClass_SendFails() { var uid = new DicomUID("1.1.1.1", "Private Fo-Dicom Storage", DicomUidType.SOPClass); var ds = new DicomDataset( new DicomUniqueIdentifier(DicomTag.SOPClassUID, uid), new DicomUniqueIdentifier(DicomTag.SOPInstanceUID, "1.2.3.4.5")); var port = Ports.GetNext(); using (DicomServerFactory.Create <SimpleCStoreProvider>(port, logger: _logger.IncludePrefix("DicomServer"))) { DicomStatus status = null; var request = new DicomCStoreRequest(new DicomFile(ds)) { OnResponseReceived = (req, res) => status = res.Status }; var client = DicomClientFactory.Create("127.0.0.1", port, false, "SCU", "ANY-SCP"); client.Logger = _logger.IncludePrefix("DicomClient"); await client.AddRequestAsync(request).ConfigureAwait(false); await client.SendAsync().ConfigureAwait(false); Assert.Equal(DicomStatus.SOPClassNotSupported, status); } }
public void CreateDicomServer_NullDownloadAction_ThrowsException() { // Arrange var mockProvider = new MockProvider(); var serverFactory = new DicomServerFactory(mockProvider.GetSettingsProviderFake(), mockProvider.GetLoggerFake()); // Act + Assert Assert.That(() => serverFactory.CreateDicomServer(null), Throws.TypeOf<ArgumentNullException>()); }
public void IsListening_DicomServerNotInitializedOnPort_ReturnsFalse() { var port = Ports.GetNext(); using (DicomServerFactory.Create <DicomCEchoProvider>(port, logger: _logger.IncludePrefix("DicomServer"))) { Assert.False(DicomServerRegistry.Get(Ports.GetNext())?.DicomServer?.IsListening ?? false); } }
public void Create_MultipleInstancesSamePort_Throws() { var port = Ports.GetNext(); using (DicomServerFactory.Create <DicomCEchoProvider>(port, logger: _logger.IncludePrefix("DicomServer"))) { var e = Record.Exception(() => DicomServerFactory.Create <DicomCEchoProvider>(port, logger: _logger.IncludePrefix("DicomServer"))); Assert.IsType <DicomNetworkException>(e); } }
public void Create_GetInstanceDifferentPort_ReturnsNull() { var port = Ports.GetNext(); using (DicomServerFactory.Create <DicomCEchoProvider>(port, logger: _logger.IncludePrefix("DicomServer"))) { var server = DicomServerRegistry.Get(Ports.GetNext()); Assert.Null(server); } }
public void Create_GetInstanceSamePort_ReturnsInstance() { var port = Ports.GetNext(); using (DicomServerFactory.Create <DicomCEchoProvider>(port, logger: _logger.IncludePrefix("DicomServer"))) { var server = DicomServerRegistry.Get(port)?.DicomServer; Assert.Equal(port, server.Port); } }
public void Create_GetInstanceSamePortAfterDisposal_ReturnsNull() { var port = Ports.GetNext(); using (DicomServerFactory.Create <DicomCEchoProvider>(port, logger: _logger.IncludePrefix("DicomServer"))) { /* do nothing here */ } var server = DicomServerRegistry.Get(port)?.DicomServer; Assert.Null(server); }
public static void Start(int port, string aet) { AETitle = aet; _server = DicomServerFactory.Create <WorklistService>(port); // every 30 seconds the worklist source is queried and the current list of items is cached in _currentWorklistItems _itemsLoaderTimer = new Timer((state) => { var newWorklistItems = CreateItemsSourceService.GetAllCurrentWorklistItems(); CurrentWorklistItems = newWorklistItems; }, null, TimeSpan.Zero, TimeSpan.FromSeconds(30)); }
public void IsListening_DicomServerRunningOnPort_ReturnsTrue() { var port = Ports.GetNext(); using var server = DicomServerFactory.Create <DicomCEchoProvider>(port, logger: _logger.IncludePrefix("DicomServer")); while (!server.IsListening) { Thread.Sleep(10); } Assert.True(DicomServerRegistry.Get(port).DicomServer.IsListening); }
public void CreateDicomServer_CreatesNewInstanceOfDicomServer() { // Arrange var mockProvider = new MockProvider(); var serverFactory = new DicomServerFactory(mockProvider.GetSettingsProviderFake(), mockProvider.GetLoggerFake()); // Act var server1 = serverFactory.CreateDicomServer((a, b) => new MemoryStream()); var server2 = serverFactory.CreateDicomServer((a, b) => new MemoryStream()); // Assert Assert.That(server1, Is.Not.SameAs(server2)); }
private static void Main(string[] args) { // start DICOM server on port from command line argument or 11112 var port = args != null && args.Length > 0 && int.TryParse(args[0], out int tmp) ? tmp : 11112; Console.WriteLine($"Starting C-Store SCP server on port {port}"); using (var server = DicomServerFactory.Create <CStoreSCP>(port)) { // end process Console.WriteLine("Press <return> to end..."); Console.ReadLine(); } }
public async Task DicomService_reading_messages_with_invalid_UIDs_does_not_fail() { int port = Ports.GetNext(); var clientLogger = _output.IncludePrefix(nameof(DicomClient)); var serverLogger = _output.IncludePrefix(nameof(DicomCEchoProvider)); var source = new CancellationTokenSource(); using var server = DicomServerFactory.Create <SimpleCStoreProvider>(port, logger: serverLogger); server.Options.LogDataPDUs = true; server.Options.LogDimseDatasets = true; while (!server.IsListening) { await Task.Delay(50); } var client = DicomClientFactory.Create("127.0.0.1", port, false, "SCU", "ANY-SCP"); client.Logger = clientLogger; var command = new DicomDataset { ValidateItems = false }; command.Add(DicomTag.CommandField, (ushort)DicomCommandField.CStoreRequest); command.Add(DicomTag.MessageID, (ushort)1); command.Add(DicomTag.AffectedSOPClassUID, DicomUID.CTImageStorage); command.Add(new DicomUniqueIdentifier(DicomTag.AffectedSOPInstanceUID, "1.2.3.04")); var request = new DicomCStoreRequest(command) { File = new DicomFile(), Dataset = new DicomDataset() }; request.Dataset.ValidateItems = false; request.Dataset.Add(DicomTag.SOPClassUID, DicomUID.CTImageStorage); request.Dataset.Add(new DicomUniqueIdentifier(DicomTag.SOPInstanceUID, "1.2.3.04")); request.OnResponseReceived += (e, args) => { _output.Info("Response received. Cancelling in 500ms."); source.CancelAfter(100); }; await client.AddRequestAsync(request); await client.SendAsync(); }
public async Task CStoreRequestSend_8And16BitJpegFiles_TransferSuccessful() { string file1 = TestData.Resolve("GH538-jpeg1.dcm"); string file2 = TestData.Resolve("GH538-jpeg14sv1.dcm"); var handle1 = new ManualResetEventSlim(); var handle2 = new ManualResetEventSlim(); var successes = 0; var port = Ports.GetNext(); using (DicomServerFactory.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 = DicomClientFactory.Create("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); } }
public void CanCreateIpv4AndIpv6() { var port = Ports.GetNext(); using var server = DicomServerFactory.Create <DicomCEchoProvider>(port, logger: _logger.IncludePrefix("DicomServer")); var e = Record.Exception( () => { using (DicomServerFactory.Create <DicomCEchoProvider>(NetworkManager.IPv6Any, port, logger: _logger.IncludePrefix("DicomServer"))) { // do nothing here } }); Assert.Null(e); }
public async Task Send_FromIpv6ToIpv4AnyListenerKnownSOPClass_SendFails() { var port = Ports.GetNext(); using (DicomServerFactory.Create <SimpleCStoreProvider>(NetworkManager.IPv4Any, port, logger: _logger.IncludePrefix("DicomServer"))) { var request = new DicomCStoreRequest(TestData.Resolve("CT-MONO2-16-ankle")); var client = DicomClientFactory.Create(NetworkManager.IPv6Loopback, 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); } }
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); }
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); }
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); }
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); } }
public async Task DicomClientSend_TooManyPresentationContexts_YieldsInformativeException() { var port = Ports.GetNext(); using (DicomServerFactory.Create <DicomCEchoProvider>(port)) { var client = DicomClientFactory.Create("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); } }
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); }
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(); } }
public static void Start(int port, string aet) { Printer = new Printer(aet); _server = DicomServerFactory.Create <PrintService>(port); }
public static void Start(int port, string aet) { AETitle = aet; _server = DicomServerFactory.Create <QRService>(port); }
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); } }