private void PrintSCPService_PrintTaskEvent(PrintTaskInfo task) { Invoke((MethodInvoker)(() => { //new print task created by PrintSCP Service _printTasks.Add(task); bindingSource1.DataSource = null; bindingSource1.DataSource = _printTasks; })); }
void PrintSCUService_PrintTaskEvent(PrintTaskInfo task) { Invoke((MethodInvoker)(() => { if (task.HasError) { MessageBox.Show("Send print task failed due to " + task.ErrorMessage); } else { MessageBox.Show("Success print task success: " + task.TaskPath); } })); }
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 static string SendPrintTask(string callingAE, string calledAE, string calledIP, int calledPort, string taskPath) { PrintTaskInfo task = new PrintTaskInfo() { CallingAETitle = callingAE, TaskPath = taskPath }; string strErr = string.Empty; LogManager.Instance.Log("Start to send print task: " + taskPath); try { DirectoryInfo dirTask = new DirectoryInfo(taskPath); if (!dirTask.Exists) { throw new Exception("invalid task path"); } string filmSessionFile = Path.Combine(taskPath, "FilmSession.dcm"); if (!File.Exists(filmSessionFile)) { throw new Exception("can't find film session file"); } //load filmSession from dcmFile FilmSession filmSession = FilmSession.Load(filmSessionFile); //load filmBox from dcmFiles var subDirs = dirTask.EnumerateDirectories(); foreach (DirectoryInfo dirFilmBox in subDirs) { FilmBox filmBox = FilmBox.Load(filmSession, dirFilmBox.FullName); filmSession.BasicFilmBoxes.Add(filmBox); } var dicomClient = new DicomClient(); var filmSessionRequest = new DicomNCreateRequest(filmSession.SOPClassUID, filmSession.SOPInstanceUID); filmSessionRequest.Dataset = filmSession; dicomClient.AddRequest(filmSessionRequest); foreach (var filmbox in filmSession.BasicFilmBoxes) { var imageBoxRequests = new List <DicomNSetRequest>(); var filmBoxRequest = new DicomNCreateRequest(FilmBox.SOPClassUID, filmbox.SOPInstanceUID); filmBoxRequest.Dataset = filmbox; filmBoxRequest.OnResponseReceived = (request, response) => { if (response.HasDataset) { var seq = response.Dataset.Get <DicomSequence>(DicomTag.ReferencedImageBoxSequence); for (int i = 0; i < seq.Items.Count; i++) { var req = imageBoxRequests[i]; var imageBox = req.Dataset; var sopInstanceUid = seq.Items[i].Get <string>(DicomTag.ReferencedSOPInstanceUID); imageBox.AddOrUpdate(DicomTag.SOPInstanceUID, sopInstanceUid); req.Command.AddOrUpdate(DicomTag.RequestedSOPInstanceUID, sopInstanceUid); } } }; dicomClient.AddRequest(filmBoxRequest); foreach (var image in filmbox.BasicImageBoxes) { var req = new DicomNSetRequest(image.SOPClassUID, image.SOPInstanceUID) { Dataset = image }; imageBoxRequests.Add(req); dicomClient.AddRequest(req); } } dicomClient.AddRequest(new DicomNActionRequest(filmSession.SOPClassUID, filmSession.SOPInstanceUID, 0x0001)); dicomClient.Send(calledIP, calledPort, false, callingAE, calledAE); task.HasError = false; if (PrintTaskEvent != null) { PrintTaskEvent(task); } } catch (Exception e) { strErr = e.Message; LogManager.Instance.Log("Send task failed due to " + e.Message); task.HasError = true; task.ErrorMessage = e.Message; if (PrintTaskEvent != null) { PrintTaskEvent(task); } } return(strErr); }