/// <summary> /// Process a specified <see cref="WorkQueueUid"/> /// </summary> /// <param name="item">The <see cref="WorkQueue"/> item being processed</param> /// <param name="sop">The <see cref="WorkQueueUid"/> being processed</param> /// <param name="studyXml">The <see cref="StudyXml"/> object for the study being processed</param> /// <returns>true if the <see cref="WorkQueueUid"/> is successfully processed. false otherwise</returns> protected virtual bool ProcessWorkQueueUid(Model.WorkQueue item, WorkQueueUid sop, StudyXml studyXml) { Platform.CheckForNullReference(item, "item"); Platform.CheckForNullReference(sop, "sop"); Platform.CheckForNullReference(studyXml, "studyXml"); OnProcessUidBegin(item, sop); string path = null; try { if (sop.Duplicate && sop.Extension != null) { path = ServerPlatform.GetDuplicateUidPath(StorageLocation, sop); var file = new DicomFile(path); file.Load(); InstancePreProcessingResult result = PreProcessFile(sop, file); if (false == file.DataSet[DicomTags.StudyInstanceUid].ToString().Equals(StorageLocation.StudyInstanceUid) || result.DiscardImage) { RemoveWorkQueueUid(sop, null); } else { var duplicateResult = ProcessDuplicate(file, sop, studyXml); if (duplicateResult.ActionTaken == DuplicateProcessResultAction.Delete || duplicateResult.ActionTaken == DuplicateProcessResultAction.Accept) { // make sure the folder is also deleted if it's empty string folder = Path.GetDirectoryName(path); String reconcileRootFolder = ServerPlatform.GetDuplicateFolderRootPath(StorageLocation); DirectoryUtility.DeleteIfEmpty(folder, reconcileRootFolder); } } } else { try { path = StorageLocation.GetSopInstancePath(sop.SeriesInstanceUid, sop.SopInstanceUid); var file = new DicomFile(path); file.Load(); InstancePreProcessingResult result = PreProcessFile(sop, file); if (false == file.DataSet[DicomTags.StudyInstanceUid].ToString().Equals(StorageLocation.StudyInstanceUid) || result.DiscardImage) { RemoveWorkQueueUid(sop, path); } else { ProcessFile(sop, file, studyXml, !result.AutoReconciled); } } catch (DicomException ex) { // bad file. Remove it from the filesystem and the queue RemoveBadDicomFile(path, ex.Message); DeleteWorkQueueUid(sop); return(false); } } return(true); } catch (StudyIsNearlineException) { // handled by caller throw; } catch (Exception e) { Platform.Log(LogLevel.Error, e, "Unexpected exception when processing file: {0} SOP Instance: {1}", path, sop.SopInstanceUid); item.FailureDescription = e.InnerException != null? String.Format("{0}:{1}", e.GetType().Name, e.InnerException.Message) : String.Format("{0}:{1}", e.GetType().Name, e.Message); //No longer needed. Update was moved into the SopInstanceProcessor //sop.FailureCount++; //UpdateWorkQueueUid(sop); return(false); } finally { OnProcessUidEnd(item, sop); } }