public async Task SendAsync_SingleRequest_DataSufficientlyTransported() { int port = Ports.GetNext(); using (new DicomServer<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 DicomClient(); client.AddRequest(request); await client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); var commandField = command.Get<ushort>(DicomTag.CommandField); Assert.Equal((ushort)1, commandField); var modality = dataset.Get<string>(DicomTag.Modality); Assert.Equal("CT", modality); } }
public void IsSendRequired_AddedRequestIsConnected_ReturnsFalse() { var port = Ports.GetNext(); using (DicomServer.Create <DicomCEchoProvider>(port)) { var counter = 0; var flag = new ManualResetEventSlim(); var client = new DicomClient { Linger = 100 }; client.AddRequest( new DicomCEchoRequest { OnResponseReceived = (req, res) => Interlocked.Increment(ref counter) }); client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); client.AddRequest( new DicomCEchoRequest { OnResponseReceived = (req, res) => { Interlocked.Increment(ref counter); flag.Set(); } }); Assert.False(client.IsSendRequired); flag.Wait(1000); Assert.Equal(2, counter); } }
public async Task Old_SendAsync_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 DicomClient(); client.AddRequest(request); await client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); var commandField = command.Get <ushort>(DicomTag.CommandField); Assert.Equal((ushort)1, commandField); var modality = dataset.Get <string>(DicomTag.Modality); Assert.Equal("CT", modality); } }
public static IAsyncResult BeginSend( this DicomClient @this, INetworkStream stream, string callingAe, string calledAe, AsyncCallback callback, object state) { return(AsyncFactory.ToBegin(@this.SendAsync(stream, callingAe, calledAe), callback, state)); }
public static IAsyncResult BeginSend( this DicomClient @this, string host, int port, bool useTls, string callingAe, string calledAe, AsyncCallback callback, object state) { return(AsyncFactory.ToBegin(@this.SendAsync(host, port, useTls, callingAe, calledAe), callback, state)); }
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 void WaitForAssociation_WithinTimeout_ReturnsTrue() { int port = Ports.GetNext(); using (DicomServer.Create <MockCEchoProvider>(port)) { var client = new DicomClient(); client.AddRequest(new DicomCEchoRequest()); var task = client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); var actual = client.WaitForAssociation(10000); task.Wait(10000); Assert.True(actual); } }
public async Task OldDicomClient_SendEchos() { var client = new Dicom.Network.DicomClient(); client.NegotiateAsyncOps(1, 1); client.Linger = 0; var requests = Enumerable.Range(0, 1000).Select(i => new DicomCEchoRequest()); foreach (var request in requests) { client.AddRequest(request); } await client.SendAsync("127.0.0.1", _server.Port, false, "SCU", "ANY-SCP").ConfigureAwait(false); }
public async Task SendAsync_RejectedAssociation_ShouldYieldException() { var port = Ports.GetNext(); using (DicomServer.Create <MockCEchoProvider>(port)) { var client = new DicomClient(); client.AddRequest(new DicomCEchoRequest()); var exception = await Record.ExceptionAsync(() => client.SendAsync("127.0.0.1", port, false, "SCU", "INVALID")) .ConfigureAwait(false); Assert.IsType <DicomAssociationRejectedException>(exception); } }
public void WaitForAssociation_Aborted_ReturnsFalse() { int port = Ports.GetNext(); using (new DicomServer <MockCEchoProvider>(port)) { var client = new DicomClient(); client.AddRequest(new DicomCEchoRequest()); var task = client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); client.Abort(); var actual = client.WaitForAssociation(500); Assert.Equal(false, actual); } }
public async Task WaitForAssociationAsync_TooShortTimeout_ReturnsFalse() { int port = Ports.GetNext(); using (new DicomServer <MockCEchoProvider>(port)) { var client = new DicomClient(); client.AddRequest(new DicomCEchoRequest()); var task = client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); var actual = await client.WaitForAssociationAsync(1); task.Wait(10000); Assert.Equal(false, actual); } }
public async Task WaitForAssociationAsync_Aborted_ReturnsFalse() { int port = Ports.GetNext(); using (DicomServer.Create <MockCEchoProvider>(port)) { var client = new DicomClient(); client.AddRequest(new DicomCEchoRequest()); var task = client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); client.Abort(); var actual = await client.WaitForAssociationAsync(500); Assert.False(actual); } }
public void Release_AfterAssociation_SendIsCompleted() { int port = Ports.GetNext(); using (DicomServer.Create <MockCEchoProvider>(port)) { var client = new DicomClient(); client.AddRequest(new DicomCEchoRequest()); var task = client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); client.WaitForAssociation(); client.Release(); Thread.Sleep(10); Assert.True(task.IsCompleted); } }
public void WaitForAssociation_TooShortTimeout_ReturnsFalse() { var port = Ports.GetNext(); using (DicomServer.Create <MockCEchoProvider>(port)) { var client = new DicomClient(); client.AddRequest(new DicomCEchoRequest { OnResponseReceived = (rq, rsp) => Thread.Sleep(100) }); var task = client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); var actual = client.WaitForAssociation(1); task.Wait(1000); Assert.False(actual); } }
public async Task SendAsync_SingleRequest_Recognized() { int port = Ports.GetNext(); using (DicomServer.Create <DicomCEchoProvider>(port)) { var counter = 0; var request = new DicomCEchoRequest { OnResponseReceived = (req, res) => Interlocked.Increment(ref counter) }; var client = new DicomClient(); client.AddRequest(request); var task = client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); await Task.WhenAny(task, Task.Delay(10000)); Assert.Equal(1, counter); } }
public async Task ReleaseAsync_AfterAssociation_SendIsCompleted() { int port = Ports.GetNext(); using (DicomServer.Create <MockCEchoProvider>(port)) { Task task = null; var client = new DicomClient(); client.AssociationAccepted += HandleAssociationAccepted; client.AddRequest(new DicomCEchoRequest()); task = client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); void HandleAssociationAccepted(object sender, AssociationAcceptedEventArgs e) { (sender as DicomClient).ReleaseAsync().Wait(); Thread.Sleep(10); Assert.True(task.IsCompleted); } } }
public async Task SendAsync_MultipleTimes_AllRecognized(int expected) { int port = Ports.GetNext(); var @lock = new object(); using (new DicomServer <DicomCEchoProvider>(port)) { var actual = 0; var client = new DicomClient(); for (var i = 0; i < expected; ++i) { client.AddRequest(new DicomCEchoRequest { OnResponseReceived = (req, res) => { lock (@lock) ++actual; } }); var task = client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); await Task.WhenAny(task, Task.Delay(1000)); } Assert.Equal(expected, actual); } }
public async Task SendAsync_MultipleRequests_AllRecognized(int expected) { int port = Ports.GetNext(); using (DicomServer.Create <DicomCEchoProvider>(port)) { var actual = 0; var client = new DicomClient(); client.NegotiateAsyncOps(expected, 1); for (var i = 0; i < expected; ++i) { client.AddRequest(new DicomCEchoRequest { OnResponseReceived = (req, res) => Interlocked.Increment(ref actual) }); } var task = client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); await Task.WhenAny(task, Task.Delay(30000)); Assert.Equal(expected, actual); } }
public async Task SendAsync_MultipleTimes_AllRecognized(int expected) { var port = Ports.GetNext(); var flag = new ManualResetEventSlim(); using (var server = DicomServer.Create <DicomCEchoProvider>(port)) { while (!server.IsListening) { await Task.Delay(50); } var actual = 0; var client = new DicomClient(); for (var i = 0; i < expected; i++) { client.AddRequest( new DicomCEchoRequest { OnResponseReceived = (req, res) => { Interlocked.Increment(ref actual); if (actual == expected) { flag.Set(); } } }); await client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); } flag.Wait(10000); Assert.Equal(expected, actual); } }
public async Task SendAsync_MultipleTimesParallel_AllRecognized(int expected) { int port = Ports.GetNext(); using ( var server = DicomServer.Create <DicomCEchoProvider>(port)) { await Task.Delay(500); Assert.True(server.IsListening, "Server is not listening"); var actual = 0; var requests = Enumerable.Range(0, expected).Select( async requestIndex => { var client = new DicomClient(); client.AddRequest( new DicomCEchoRequest { OnResponseReceived = (req, res) => { _testOutputHelper.WriteLine("Response #{0}", requestIndex); Interlocked.Increment(ref actual); } }); _testOutputHelper.WriteLine("Sending #{0}", requestIndex); await client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); _testOutputHelper.WriteLine("Sent (or timed out) #{0}", requestIndex); }).ToList(); await Task.WhenAll(requests); Assert.Equal(expected, actual); } }
public async Task SendAsync_SingleRequest_Recognized() { int port = Ports.GetNext(); using (DicomServer.Create<DicomCEchoProvider>(port)) { var counter = 0; var request = new DicomCEchoRequest { OnResponseReceived = (req, res) => ++counter }; var client = new DicomClient(); client.AddRequest(request); var task = client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); await Task.WhenAny(task, Task.Delay(10000)); Assert.Equal(1, counter); } }
public async Task SendAsync_RejectedAssociation_ShouldYieldException() { var port = Ports.GetNext(); using (DicomServer.Create<MockCEchoProvider>(port)) { var client = new DicomClient(); client.AddRequest(new DicomCEchoRequest()); var exception = await Record.ExceptionAsync(() => client.SendAsync("127.0.0.1", port, false, "SCU", "INVALID")) .ConfigureAwait(false); Assert.IsType<DicomAssociationRejectedException>(exception); } }
public async Task ReleaseAsync_AfterAssociation_SendIsCompleted() { int port = Ports.GetNext(); using (DicomServer.Create<MockCEchoProvider>(port)) { var client = new DicomClient(); client.AddRequest(new DicomCEchoRequest()); var task = client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); client.WaitForAssociation(); await client.ReleaseAsync(); Thread.Sleep(10); Assert.True(task.IsCompleted); } }
public async Task WaitForAssociationAsync_Aborted_ReturnsFalse() { int port = Ports.GetNext(); using (DicomServer.Create<MockCEchoProvider>(port)) { var client = new DicomClient(); client.AddRequest(new DicomCEchoRequest()); var task = client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); client.Abort(); var actual = await client.WaitForAssociationAsync(500); Assert.Equal(false, actual); } }
public void WaitForAssociation_TooShortTimeout_ReturnsFalse() { int port = Ports.GetNext(); using (DicomServer.Create<MockCEchoProvider>(port)) { var client = new DicomClient(); client.AddRequest(new DicomCEchoRequest()); var task = client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); var actual = client.WaitForAssociation(1); task.Wait(10000); Assert.Equal(false, actual); } }
public async Task SendAsync_MultipleTimesParallel_AllRecognized(int expected) { int port = Ports.GetNext(); using ( var server = DicomServer.Create<DicomCEchoProvider>(port)) { await Task.Delay(500); Assert.True(server.IsListening, "Server is not listening"); var actual = 0; var requests = Enumerable.Range(0, expected).Select( async requestIndex => { var client = new DicomClient(); client.AddRequest( new DicomCEchoRequest { OnResponseReceived = (req, res) => { _testOutputHelper.WriteLine("Response #{0}", requestIndex); Interlocked.Increment(ref actual); } }); _testOutputHelper.WriteLine("Sending #{0}", requestIndex); await client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); _testOutputHelper.WriteLine("Sent (or timed out) #{0}", requestIndex); }).ToList(); await Task.WhenAll(requests); Assert.Equal(expected, actual); } }
//[InlineData(100)] public async Task SendAsync_MultipleTimes_AllRecognized(int expected) { int port = Ports.GetNext(); using (var server = DicomServer.Create<DicomCEchoProvider>(port)) { while (!server.IsListening) await Task.Delay(50); var actual = 0; var client = new DicomClient(); for (var i = 0; i < expected; i++) { client.AddRequest(new DicomCEchoRequest { OnResponseReceived = (req, res) => Interlocked.Increment(ref actual) }); await client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); } await client.ReleaseAsync(); Assert.Equal(expected, actual); } }
public async Task SendAsync_MultipleRequests_AllRecognized(int expected) { int port = Ports.GetNext(); using (DicomServer.Create<DicomCEchoProvider>(port)) { var actual = 0; var client = new DicomClient(); client.NegotiateAsyncOps(expected, 1); for (var i = 0; i < expected; ++i) client.AddRequest(new DicomCEchoRequest { OnResponseReceived = (req, res) => ++actual }); var task = client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); await Task.WhenAny(task, Task.Delay(10000)); Assert.Equal(expected, actual); } }
public async Task SendAsync_MultipleTimes_AllRecognized(int expected) { int port = Ports.GetNext(); var @lock = new object(); using (new DicomServer<DicomCEchoProvider>(port)) { var actual = 0; var client = new DicomClient(); for (var i = 0; i < expected; ++i) { client.AddRequest(new DicomCEchoRequest { OnResponseReceived = (req, res) => { lock (@lock) ++actual; } }); var task = client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); await Task.WhenAny(task, Task.Delay(1000)); } Assert.Equal(expected, actual); } }
public async Task WaitForAssociationAsync_WithinTimeout_ReturnsTrue() { int port = Ports.GetNext(); using (new DicomServer<MockCEchoProvider>(port)) { var client = new DicomClient(); client.AddRequest(new DicomCEchoRequest()); var task = client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); var actual = await client.WaitForAssociationAsync(10000); task.Wait(10000); Assert.Equal(true, actual); } }