public async Task DicomClientSend_ToRejectedAssociation_ShouldNotSendRequest() { var port = Ports.GetNext(); using (DicomServer.Create <DicomClientTest.MockCEchoProvider>(port)) { var locker = new object(); DicomStatus status = null; var client = new Dicom.Network.Client.DicomClient("localhost", port, false, "SCU", "WRONG-SCP"); await client.AddRequestAsync( new DicomCEchoRequest { OnResponseReceived = (rq, rsp) => { lock (locker) status = rsp.Status; } }).ConfigureAwait(false); try { await client.SendAsync().ConfigureAwait(false); } catch { } Assert.Null(status); } }
public async Task DicomClientSend_ToAcceptedAssociation_ShouldSendRequest() { var port = Ports.GetNext(); using (DicomServer.Create <DicomClientTest.MockCEchoProvider>(port)) { var locker = new object(); var expected = DicomStatus.Success; DicomStatus actual = null; var client = new Dicom.Network.Client.DicomClient("localhost", port, false, "SCU", "ANY-SCP"); await client.AddRequestAsync( new DicomCEchoRequest { OnResponseReceived = (rq, rsp) => { lock (locker) actual = rsp.Status; } }).ConfigureAwait(false); await client.SendAsync().ConfigureAwait(false); Assert.Equal(expected, actual); } }
public async Task OnCFindRequestAsync_Pending_ShouldRespond() { var port = Ports.GetNext(); using (DicomServer.Create <PendingAsyncDicomCFindProvider>(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) }; var responses = new ConcurrentQueue <DicomCFindResponse>(); DicomRequest.OnTimeoutEventArgs timeout = null; var request = new DicomCFindRequest(DicomQueryRetrieveLevel.Study) { 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 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); } }
public async Task OnCStoreRequestAsync_PreferedTransfersyntax() { var port = Ports.GetNext(); using (DicomServer.Create <AsyncDicomCStoreProviderPreferingUncompressedTS>(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) }; int numberOfContexts = 0; DicomTransferSyntax accpetedTS = null; // create a request with a jpeg-encoded file var request = new DicomCStoreRequest(@"./Test Data/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 DicomClientSend_StorePart10File_ShouldSucceed() { var port = Ports.GetNext(); using (var server = DicomServer.Create <CStoreScp>(port)) { server.Logger = _logger.IncludePrefix("CStoreScp"); var file = DicomFile.Open(@".\Test Data\CT-MONO2-16-ankle"); var client = new Dicom.Network.Client.DicomClient("127.0.0.1", port, false, "SCU", "SCP") { Logger = _logger.IncludePrefix("DicomClient") }; await client.AddRequestAsync(new DicomCStoreRequest(file)).ConfigureAwait(false); var exception = await Record.ExceptionAsync(async() => await client.SendAsync()); Assert.Null(exception); } }
public async Task SendMaxPDU() { var port = Ports.GetNext(); uint serverPduLength = 400000; uint clientPduLength = serverPduLength / 2; using (var server = DicomServer.Create <DicomCEchoProvider>(port, null, new DicomServiceOptions { MaxPDULength = serverPduLength })) { uint serverPduInAssociationAccepted = 0; var client = new Client.DicomClient("127.0.0.1", port, false, "SCU", "ANY-SCP"); client.Options = new DicomServiceOptions { MaxPDULength = clientPduLength }; // explicitly choose a different value await client.AddRequestAsync(new DicomCEchoRequest()); client.AssociationAccepted += (sender, e) => serverPduInAssociationAccepted = e.Association.MaximumPDULength; await client.SendAsync(); Assert.Equal(serverPduLength, serverPduInAssociationAccepted); } }
/// <summary> /// Throttle requests using W(O) = mO(t) + c where W is the wait period, O is the opertaion duration, m and c are positive constants /// The request is added to the client which is unreleased at the end of this request send. /// </summary> /// #region ThrottleRequest public void ThrottleRequest(DicomRequest dicomRequest, DicomClient client, CancellationToken cancellationToken) { client.AddRequestAsync(dicomRequest).Wait(cancellationToken); ThrottleRequest(client, cancellationToken); }
/// <summary> /// Blocks until the request is received so calling code doesn't have to deal with asynchrony (see the EventWaitHandle in TrySend). /// Only the timeout is applied no Throtelling, the client is unreleased on return /// </summary> /// <param name="dicomRequest"></param> /// <param name="client"></param> #region SendRequest public void SendRequest(DicomRequest dicomRequest, DicomClient client, CancellationToken token) { client.AddRequestAsync(dicomRequest).Wait(token); SendRequest(client, token); }
public async Task ClientHandleNEventReport_SynchronousEvent() { var port = Ports.GetNext(); using (DicomServer.Create <SimpleStorageComitmentProvider>(port)) { DicomStatus status = null; int verifiedInstances = 0; DateTime stampNActionResponse = DateTime.MinValue; DateTime stampNEventReportRequest = DateTime.MinValue; var dicomClient = new Client.DicomClient("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.AssociationLingerTimeoutInMs = (int)TimeSpan.FromSeconds(5).TotalMilliseconds; await dicomClient.SendAsync().ConfigureAwait(false); Assert.Equal(DicomStatus.Success, status); Assert.Equal(2, verifiedInstances); Assert.True(stampNActionResponse < stampNEventReportRequest); } }