public async Task OnNActionRequestAsync_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); 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); } }
public void SOPInstanceUIDGetter_ResponseCreatedFromRequest_DoesNotThrow() { var request = new DicomNActionRequest( DicomUID.BasicFilmSession, new DicomUID("1.2.3", null, DicomUidType.SOPInstance), 1); var response = new DicomNActionResponse(request, DicomStatus.Success); var exception = Record.Exception(() => response.SOPInstanceUID); Assert.Null(exception); }
public async Task OnSendNEventReportRequestAsync(DicomNActionRequest request) { // synchronously send NEvents if (request.Dataset.Contains(DicomTag.ReferencedSOPSequence)) { var referencedSequence = request.Dataset.GetSequence(DicomTag.ReferencedSOPSequence); foreach (var referencedDataset in referencedSequence) { var resultDs = new DicomDataset { { DicomTag.ReferencedSOPSequence, new DicomDataset { { DicomTag.ReferencedSOPClassUID, referencedDataset.GetString(DicomTag.ReferencedSOPClassUID) }, { DicomTag.ReferencedSOPInstanceUID, referencedDataset.GetString(DicomTag.ReferencedSOPInstanceUID) } } } }; await SendRequestAsync(new DicomNEventReportRequest(DicomUID.StorageCommitmentPushModel, DicomUID.StorageCommitmentPushModel, 2) { Dataset = resultDs }); } } }
public Task <DicomNActionResponse> OnNActionRequestAsync(DicomNActionRequest request) { /* * // first return the success-response * await SendResponseAsync(new DicomNActionResponse(request, DicomStatus.Success)); * * // then synchronously send NEvents * if (request.Dataset.Contains(DicomTag.ReferencedSOPSequence)) * { * var referencedSequence = request.Dataset.GetSequence(DicomTag.ReferencedSOPSequence); * foreach (var referencedDataset in referencedSequence) * { * // This can also be done within a thread later * //_ = Task.Run(async () => * // { * // await Task.Delay(TimeSpan.FromSeconds(1)); * var resultDs = new DicomDataset * { * { * DicomTag.ReferencedSOPSequence, * new DicomDataset * { * { DicomTag.ReferencedSOPClassUID, referencedDataset.GetString(DicomTag.ReferencedSOPClassUID) }, * { DicomTag.ReferencedSOPInstanceUID, referencedDataset.GetString(DicomTag.ReferencedSOPInstanceUID) } * } * } * }; * await SendRequestAsync(new DicomNEventReportRequest(DicomUID.StorageCommitmentPushModelSOPClass, DicomUID.Generate(), 1) { Dataset = resultDs }); * //}); * } * } * * return null; */ return(Task.FromResult(new DicomNActionResponse(request, DicomStatus.Success))); }
public async Task <DicomNActionResponse> OnNActionRequestAsync(DicomNActionRequest request) { Logger.Log(LogLevel.Info, "receiving N-Action, not supported"); return(new DicomNActionResponse(request, DicomStatus.UnrecognizedOperation)); }
public DicomNActionResponse OnNActionRequest(DicomNActionRequest request) { if (_filmSession == null) { this.Logger.Error("A basic film session does not exist for this association {0}", CallingAE); return(new DicomNActionResponse(request, DicomStatus.InvalidObjectInstance)); } lock (_synchRoot) { try { var filmBoxList = new List <FilmBox>(); if (request.SOPClassUID == DicomUID.BasicFilmSessionSOPClass && request.ActionTypeID == 0x0001) { this.Logger.Info("Creating new print job for film session {0}", _filmSession.SOPInstanceUID.UID); filmBoxList.AddRange(_filmSession.BasicFilmBoxes); } else if (request.SOPClassUID == DicomUID.BasicFilmBoxSOPClass && request.ActionTypeID == 0x0001) { this.Logger.Info("Creating new print job for film box {0}", request.SOPInstanceUID.UID); var filmBox = _filmSession.FindFilmBox(request.SOPInstanceUID); if (filmBox != null) { filmBoxList.Add(filmBox); } else { this.Logger.Error( "Received N-ACTION request for invalid film box {0} from {1}", request.SOPInstanceUID.UID, CallingAE); return(new DicomNActionResponse(request, DicomStatus.NoSuchObjectInstance)); } } else { if (request.ActionTypeID != 0x0001) { this.Logger.Error( "Received N-ACTION request for invalid action type {0} from {1}", request.ActionTypeID, CallingAE); return(new DicomNActionResponse(request, DicomStatus.NoSuchActionType)); } else { this.Logger.Error( "Received N-ACTION request for invalid SOP class {0} from {1}", request.SOPClassUID, CallingAE); return(new DicomNActionResponse(request, DicomStatus.NoSuchSOPClass)); } } var printJob = new PrintJob(null, Printer, CallingAE, this.Logger); printJob.SendNEventReport = _sendEventReports; printJob.StatusUpdate += OnPrintJobStatusUpdate; printJob.Print(filmBoxList); if (printJob.Error == null) { var result = new DicomDataset(); result.Add( new DicomSequence( new DicomTag(0x2100, 0x0500), new DicomDataset( new DicomUniqueIdentifier(DicomTag.ReferencedSOPClassUID, DicomUID.PrintJobSOPClass)), new DicomDataset( new DicomUniqueIdentifier( DicomTag.ReferencedSOPInstanceUID, printJob.SOPInstanceUID)))); var response = new DicomNActionResponse(request, DicomStatus.Success); response.Command.Add(DicomTag.AffectedSOPInstanceUID, printJob.SOPInstanceUID); response.Dataset = result; return(response); } else { throw printJob.Error; } } catch (Exception ex) { this.Logger.Error( "Error occured during N-ACTION {0} for SOP class {1} and instance {2}", request.ActionTypeID, request.SOPClassUID.UID, request.SOPInstanceUID.UID); this.Logger.Error(ex.Message); return(new DicomNActionResponse(request, DicomStatus.ProcessingFailure)); } } }
public DicomNActionResponse OnNActionRequest(DicomNActionRequest request) { if (_filmSession == null) { LogManager.Instance.Error("A basic film session does not exist for this association {0}", CallingAE); return(new DicomNActionResponse(request, DicomStatus.InvalidObjectInstance)); } lock (_synchRoot) { try { var filmBoxList = new List <FilmBox>(); if (request.SOPClassUID == DicomUID.BasicFilmSessionSOPClass && request.ActionTypeID == 0x0001) { LogManager.Instance.Info("Creating new print job for film session {0}", _filmSession.SOPInstanceUID.UID); filmBoxList.AddRange(_filmSession.BasicFilmBoxes); } else if (request.SOPClassUID == DicomUID.BasicFilmBoxSOPClass && request.ActionTypeID == 0x0001) { LogManager.Instance.Info("Creating new print job for film box {0}", request.SOPInstanceUID.UID); var filmBox = _filmSession.FindFilmBox(request.SOPInstanceUID); if (filmBox != null) { filmBoxList.Add(filmBox); } else { LogManager.Instance.Error( "Received N-ACTION request for invalid film box {0} from {1}", request.SOPInstanceUID.UID, CallingAE); return(new DicomNActionResponse(request, DicomStatus.NoSuchObjectInstance)); } } else { if (request.ActionTypeID != 0x0001) { LogManager.Instance.Error( "Received N-ACTION request for invalid action type {0} from {1}", request.ActionTypeID, CallingAE); return(new DicomNActionResponse(request, DicomStatus.NoSuchActionType)); } else { LogManager.Instance.Error( "Received N-ACTION request for invalid SOP class {0} from {1}", request.SOPClassUID, CallingAE); return(new DicomNActionResponse(request, DicomStatus.NoSuchSOPClass)); } } var printJob = new PrintJob(null, CallingIP, CallingAE, CalledAE); printJob.StatusUpdate += OnPrintJobStatusUpdate; printJob.Print(filmBoxList); PrintTaskInfo arg = new PrintTaskInfo(); arg.CallingAETitle = CallingAE; arg.CallingIP = CallingIP; arg.FilmSize = filmBoxList[0].FilmSizeID;//"TODO"; arg.TaskPath = printJob.PrintJobFolder; arg.HasError = printJob.IsFailed; arg.ErrorMessage = printJob.ErrorMessage; if (PrintSCPService.PrintTaskEvent != null) { PrintSCPService.PrintTaskEvent(arg); } if (!printJob.IsFailed) { var result = new DicomDataset(); result.Add( new DicomSequence( new DicomTag(0x2100, 0x0500), new DicomDataset( new DicomUniqueIdentifier(DicomTag.ReferencedSOPClassUID, DicomUID.PrintJobSOPClass)), new DicomDataset( new DicomUniqueIdentifier( DicomTag.ReferencedSOPInstanceUID, printJob.SOPInstanceUID)))); var response = new DicomNActionResponse(request, DicomStatus.Success); response.Command.Add(DicomTag.AffectedSOPInstanceUID, printJob.SOPInstanceUID); response.Dataset = result; return(response); } else { throw new Exception(printJob.ErrorMessage); } } catch (Exception ex) { LogManager.Instance.Error( "Error occured during N-ACTION {0} for SOP class {1} and instance {2}", request.ActionTypeID, request.SOPClassUID.UID, request.SOPInstanceUID.UID); LogManager.Instance.Error(ex.Message); return(new DicomNActionResponse(request, DicomStatus.ProcessingFailure)); } } }
public DicomNActionResponse OnNActionRequest(DicomNActionRequest request) { return(new DicomNActionResponse(request, DicomStatus.Success)); }
public Task <DicomNActionResponse> OnNActionRequestAsync(DicomNActionRequest request) => Task.FromResult(new DicomNActionResponse(request, DicomStatus.Success) { Dataset = request.Dataset });
public DicomNActionResponse OnNActionRequest(DicomNActionRequest request) { throw new NotImplementedException(); }
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); } }
public DicomNActionResponse OnNActionRequest(DicomNActionRequest request) { return(null); }
public Task OnSendNEventReportRequestAsync(DicomNActionRequest request) => SendRequestAsync(new DicomNEventReportRequest(DicomUID.StorageCommitmentPushModel, DicomUID.StorageCommitmentPushModel, 2) { Dataset = request.Dataset });
public bool SendStore(Object directory) { var client = new DicomClient(); string Directory = directory as string; var dcmFiles = System.IO.Directory.GetFiles(Directory, "*.DCM", System.IO.SearchOption.AllDirectories); var sopIds = new List <KeyValuePair <string, string> >(); if (dcmFiles == null || dcmFiles.Count() == 0) { return(false); } var first = dcmFiles.ElementAt(0); var fi = DicomFile.Open(first); string temp = fi.Dataset.Get <string>(DicomTag.StudyInstanceUID); foreach (var df in dcmFiles) { var file = DicomFile.Open(df); sopIds.Add(new KeyValuePair <string, string>(file.Dataset.Get <string>(DicomTag.SOPClassUID), file.Dataset.Get <string>(DicomTag.SOPInstanceUID))); string st = file.Dataset.Get <string>(DicomTag.StudyInstanceUID); var dicomCStoreReQuest = new DicomCStoreRequest(df); dicomCStoreReQuest.OnResponseReceived = (DicomCStoreRequest request, DicomCStoreResponse response) => { if (response.Status == DicomStatus.Success) { if (!StudyInstanceList.Find(x => { x == st })) { StudyInstanceList.Add(st); } } }; client.AddRequest(dicomCStoreReQuest); // string se = file.Dataset.Get<string>(DicomTag.SeriesInstanceUID); } client.Send(remoteserver.RemoteIP, remoteserver.RemotePort, false, localserver.LocalAE, remoteserver.RemoteAE); var cmdDataset = new DicomDataset(); var refImgSeq = new DicomSequence(DicomTag.ReferencedSOPSequence); foreach (var ax in sopIds) { var rImg = new DicomDataset(); rImg.Add(DicomTag.ReferencedSOPClassUID, ax.Key); rImg.Add(DicomTag.ReferencedSOPInstanceUID, ax.Value); refImgSeq.Items.Add(rImg); } var cmb = new DicomUIDGenerator(); cmdDataset.Add(refImgSeq); cmdDataset.Add <string>(DicomTag.TransactionUID, cmb.Generate().UID); var nActionReq = new DicomNActionRequest(DicomUID.StorageCommitmentPushModelSOPClass, cmb.Generate(), 0x0001); nActionReq.Dataset = cmdDataset; nActionReq.OnResponseReceived = (DicomNActionRequest request, DicomNActionResponse response) => { }; client.AddRequest(nActionReq); client.Send(remoteserver.RemoteIP, remoteserver.RemotePort, false, localserver.LocalAE, remoteserver.RemoteAE); return(true); }
public DicomNActionResponse OnNActionRequest(DicomNActionRequest request) { Logger.Log(LogLevel.Info, "receiving N-Action, not supported"); Log.Loger("receiving N-Action, not supported"); return(new DicomNActionResponse(request, DicomStatus.UnrecognizedOperation)); }