public async Task OnCEchoRequestAsync_ShouldRespond() { var port = Ports.GetNext(); using (DicomServerFactory.Create <AsyncDicomCEchoProvider>(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); 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); } }
public async Task CStoreRequestSend_VideoFileServerSupportsMPEG4_TransferSuccessful() { string fileName = TestData.Resolve("test_720.dcm"); var success = false; var handle = new ManualResetEventSlim(); var port = Ports.GetNext(); using var server = DicomServerFactory.Create <VideoCStoreProvider>(port); server.Logger = _logger.IncludePrefix("VideoCStoreProvider"); var request = new DicomCStoreRequest(fileName) { OnResponseReceived = (req, rsp) => { success = req.Dataset.InternalTransferSyntax.Equals( DicomTransferSyntax.Lookup(DicomUID.MPEG4HP41)) && rsp.Status == DicomStatus.Success; handle.Set(); } }; var client = DicomClientFactory.Create("localhost", port, false, "STORESCU", "STORESCP"); client.Logger = _logger.IncludePrefix("DicomClient"); await client.AddRequestAsync(request).ConfigureAwait(false); await client.SendAsync().ConfigureAwait(false); handle.Wait(10000); Assert.True(success); }
public async Task OnCFindRequestAsync_ImmediateSuccess_ShouldRespond() { var port = Ports.GetNext(); using (DicomServer.Create <ImmediateSuccessAsyncDicomCFindProvider>(port, logger: _logger.IncludePrefix("DicomServer"))) { var client = new Client.DicomClient("127.0.0.1", port, false, "SCU", "ANY-SCP") { Logger = _logger.IncludePrefix(typeof(DicomClient).Name) }; DicomCFindResponse response = null; DicomRequest.OnTimeoutEventArgs timeout = null; var request = new DicomCFindRequest(DicomQueryRetrieveLevel.Study) { 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); } }
private IDicomServer CreateServer <T>(int port) where T : DicomService, IDicomServiceProvider { var server = DicomServer.Create <T>(port); server.Logger = _logger.IncludePrefix(typeof(T).Name).WithMinimumLevel(LogLevel.Debug); return(server); }
public async Task DicomService_reading_messages_with_invalid_UIDs_does_not_fail() { int port = Ports.GetNext(); var clientLogger = _output.IncludePrefix(nameof(Network.DicomClient)); var serverLogger = _output.IncludePrefix(nameof(DicomCEchoProvider)); var source = new CancellationTokenSource(); using (var server = DicomServer.Create <SimpleCStoreProvider>(port, logger: serverLogger, options: new DicomServiceOptions { LogDataPDUs = true, LogDimseDatasets = true })) { while (!server.IsListening) { await Task.Delay(50); } var client = new DicomClient { Logger = clientLogger }; var command = new DicomDataset(); command.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); }; client.AddRequest(request); await client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); } }
public async Task DicomClientShallNotCloseConnectionTooEarly_CEchoSerialAsync(int expected) { var port = Ports.GetNext(); var testLogger = _logger.IncludePrefix("GH745"); var clientLogger = _logger.IncludePrefix(nameof(DicomClient)); var serverLogger = _logger.IncludePrefix(nameof(DicomCEchoProvider)); using var server = DicomServerFactory.Create <DicomCEchoProvider>(port); server.Logger = serverLogger; while (!server.IsListening) { await Task.Delay(50); } var actual = 0; var client = DicomClientFactory.Create("127.0.0.1", port, false, "SCU", "ANY-SCP"); client.Logger = clientLogger; client.ClientOptions.AssociationRequestTimeoutInMs = 600 * 1000; client.ClientOptions.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); } Assert.Equal(expected, actual); }
public async Task OldDicomClientShallNotCloseConnectionTooEarly_CEchoSerialAsync(int expected) { var port = Ports.GetNext(); var testLogger = _logger.IncludePrefix("GH745"); var clientLogger = _logger.IncludePrefix(nameof(Network.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.DicomClient() { Logger = clientLogger, Linger = 1 // No need to linger, we only send one request at a time }; for (var i = 0; i < expected; i++) { client.AddRequest( 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 } ); testLogger.Info("Sending #{0}", i); await client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP", 600 * 1000).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); } }
public async Task OnNActionRequestAsync_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) }; DicomNActionResponse response = null; DicomRequest.OnTimeoutEventArgs timeout = null; var request = new DicomNActionRequest( DicomUID.BasicFilmSession, new DicomUID("1.2.3", null, DicomUidType.SOPInstance), 1) { 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); } }