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 StatusSetter_SetWithoutErrorComment_DoesNotAddErrorComment() { DicomResponse x = new DicomNActionResponse(new DicomDataset()) { Status = DicomStatus.Success }; Assert.False(x.Command.Contains(DicomTag.ErrorComment)); }
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 void ToString_ResponseWithoutActionTypeID_DoesNotThrow() { var command = new DicomDataset(new DicomUnsignedShort(DicomTag.CommandField, (ushort)DicomCommandField.NActionResponse), new DicomUniqueIdentifier(DicomTag.SOPClassUID, DicomUID.BasicFilmSession), new DicomUniqueIdentifier(DicomTag.SOPInstanceUID, new DicomUID("1.2.3", null, DicomUidType.SOPInstance)), new DicomUnsignedShort(DicomTag.MessageIDBeingRespondedTo, 1)); var response = new DicomNActionResponse(command) { Status = DicomStatus.Success }; var exception = Record.Exception(() => response.ToString()); Assert.Null(exception); }
public void StatusSetter_ChangesFromStatusWithCommentToWithout_UpdatesErrorComment() { var comment = "This is a comment"; DicomResponse x = new DicomNActionResponse(new DicomDataset()); var status = new DicomStatus( "C303", DicomState.Failure, "Refused: The UPS may only become SCHEDULED via N-CREATE, not N-SET or N-ACTION", comment); x.Status = status; Assert.Equal(x.Command.GetString(DicomTag.ErrorComment), comment); x.Status = DicomStatus.Success; Assert.False(x.Command.Contains(DicomTag.ErrorComment)); }
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)); } } }