/// <summary> /// Cleanup any failed items in the queue and delete the queue entry. /// </summary> public override void Delete() { using (var context = new DataAccessContext(DataAccessContext.WorkItemMutex)) { var broker = context.GetWorkItemUidBroker(); var uidBroker = context.GetWorkItemUidBroker(); var list = broker.GetWorkItemUidsForWorkItem(Proxy.Item.Oid); foreach (WorkItemUid sop in list) { uidBroker.Delete(sop); } context.Commit(); } if (PublishFiles != null && (PublishFiles.DeletionBehaviour == DeletionBehaviour.DeleteAlways || PublishFiles.DeletionBehaviour == DeletionBehaviour.DeleteOnSuccess)) { foreach (string file in PublishFiles.FilePaths) { try { FileUtils.Delete(file); DirectoryUtility.DeleteIfEmpty(Path.GetDirectoryName(file)); } catch (Exception e) { Platform.Log(LogLevel.Warn, "Unable to delete temporary publish file {0}: {1}", file, e.Message); } } } Proxy.Delete(); }
protected override void OnExecute(CommandProcessor theProcessor) { var broker = DataAccessContext.GetWorkItemUidBroker(); _uid = broker.GetWorkItemUid(_uid.Oid); _uid.Complete = true; }
/// <summary> /// Routine for failing a work queue uid record. /// </summary> /// <param name="uid">The WorkItemUid entry to fail.</param> /// <param name="retry">A boolean value indicating whether a retry will be attempted later.</param> protected WorkItemUid FailWorkItemUid(WorkItemUid uid, bool retry) { using (var context = new DataAccessContext(DataAccessContext.WorkItemMutex)) { var broker = context.GetWorkItemUidBroker(); var sop = broker.GetWorkItemUid(uid.Oid); if (!sop.FailureCount.HasValue) { sop.FailureCount = 1; } else { sop.FailureCount = (byte)(sop.FailureCount.Value + 1); } if (sop.FailureCount > WorkItemServiceSettings.Default.RetryCount) { sop.Failed = true; } context.Commit(); return(sop); } }
public void TestAddAndGet() { DeleteAllWorkItemUids(); long oid, workItemOid; string version; using (var context = new DataAccessContext()) { WorkItem workItem; var workItemBroker = context.GetWorkItemBroker(); workItemBroker.AddWorkItem(workItem = CreateWorkItem("A")); var workItemUid = CreateWorkItemUid(workItem, "ABCDEF", "2", "3", true, true, 123); var broker = context.GetWorkItemUidBroker(); broker.AddWorkItemUid(workItemUid); context.Commit(); workItemOid = workItem.Oid; Assert.AreNotEqual(0, oid = workItemUid.Oid, "Oid should have been assigned on insert"); Assert.IsNotNull(workItemUid.Version, "Version should have been assigned on insert"); version = workItemUid.Version.ToString(); } using (var context = new DataAccessContext()) { var broker = context.GetWorkItemUidBroker(); var workItemUid = broker.GetWorkItemUid(oid); Assert.AreEqual("ABCDEF", workItemUid.File, "File"); Assert.AreEqual("2", workItemUid.SeriesInstanceUid, "SeriesInstanceUid"); Assert.AreEqual("3", workItemUid.SopInstanceUid, "SopInstanceUid"); Assert.AreEqual(workItemOid, workItemUid.WorkItemOid, "WorkItemOid"); Assert.AreEqual(true, workItemUid.Complete, "Complete"); Assert.AreEqual(true, workItemUid.Failed, "Failed"); Assert.AreEqual(123, workItemUid.FailureCount, "FailureCount"); workItemUid.Failed = false; workItemUid.FailureCount = null; context.Commit(); Assert.AreNotEqual(version, workItemUid.Version, "Version should have been changed on update"); } using (var context = new DataAccessContext()) { var broker = context.GetWorkItemUidBroker(); var workItemUid = broker.GetWorkItemUid(oid); Assert.AreEqual("ABCDEF", workItemUid.File, "File"); Assert.AreEqual("2", workItemUid.SeriesInstanceUid, "SeriesInstanceUid"); Assert.AreEqual("3", workItemUid.SopInstanceUid, "SopInstanceUid"); Assert.AreEqual(workItemOid, workItemUid.WorkItemOid, "WorkItemOid"); Assert.AreEqual(true, workItemUid.Complete, "Complete"); Assert.AreEqual(false, workItemUid.Failed, "Failed"); Assert.AreEqual(null, workItemUid.FailureCount, "FailureCount"); } }
/// <summary> /// Load the specific SOP Instance Uids in the database for the WorkQueue item. /// </summary> protected void LoadUids() { using (var context = new DataAccessContext()) { var broker = context.GetWorkItemUidBroker(); _uidList = broker.GetWorkItemUidsForWorkItem(Proxy.Item.Oid); } }
private static void DeleteAllWorkItemUids() { using (var context = new DataAccessContext()) { var workItemUidBroker = context.GetWorkItemUidBroker(); workItemUidBroker.DeleteAll(); var workItemBroker = context.GetWorkItemBroker(); workItemBroker.DeleteAll(); context.Commit(); } }
/// <summary> /// Complete a <see cref="WorkItem"/>. /// </summary> public void Complete() { using (var context = new DataAccessContext(DataAccessContext.WorkItemMutex)) { var broker = context.GetWorkItemBroker(); Item = broker.GetWorkItem(Item.Oid); DateTime now = Platform.Time; // Since we're completing, no need for additional status, its done. Progress.StatusDetails = string.Empty; Item.Progress = Progress; Item.ProcessTime = now; Item.ExpirationTime = now; Item.DeleteTime = now.AddMinutes(WorkItemServiceSettings.Default.DeleteDelayMinutes); Item.Status = WorkItemStatusEnum.Complete; var uidBroker = context.GetWorkItemUidBroker(); foreach (var entity in Item.WorkItemUids) { uidBroker.Delete(entity); } context.Commit(); } Publish(false); var studyRequest = Item.Request as WorkItemStudyRequest; if (studyRequest != null) { Platform.Log(LogLevel.Info, "Completing {0} WorkItem for OID {1}: {2}, {3}:{4}", Item.Type, Item.Oid, Item.Request.ActivityDescription, studyRequest.Patient.PatientsName, studyRequest.Patient.PatientId); } else { Platform.Log(LogLevel.Info, "Completing {0} WorkItem for OID {1}: {2}", Item.Type, Item.Oid, Item.Request.ActivityDescription); } }
/// <summary> /// Cleanup any failed items in the queue and delete the queue entry. /// </summary> public override void Delete() { LoadUids(); var studyXml = Location.LoadStudyXml(); foreach (WorkItemUid sop in WorkQueueUidList) { var defaultFilePath = String.IsNullOrEmpty(sop.File); var file = GetFilePath(sop); if (sop.Failed || !sop.Complete) { if (!defaultFilePath) { try { FileUtils.Delete(file); } catch (Exception e) { Platform.Log(LogLevel.Error, e, "Unexpected exception attempting to cleanup file for Work Item {0}", Proxy.Item.Oid); } } else { try { // Only delete the file if its not in the study Xml file. This should handle collisions with // multiple WorkItems that may have been canceled when others succeeded. if (!studyXml.Contains(sop.SeriesInstanceUid, sop.SopInstanceUid)) { FileUtils.Delete(file); } } catch (Exception e) { Platform.Log(LogLevel.Error, e, "Unexpected exception attempting to cleanup file for Work Item {0}", Proxy.Item.Oid); } } } } try { DirectoryUtility.DeleteIfEmpty(Location.StudyFolder); } catch (Exception e) { Platform.Log(LogLevel.Error, e, "Unexpected exception attempting to delete folder: {0}", Location.StudyFolder); } // Now cleanup the actual WorkItemUid references using (var context = new DataAccessContext(DataAccessContext.WorkItemMutex)) { var broker = context.GetWorkItemUidBroker(); var uidBroker = context.GetWorkItemUidBroker(); var list = broker.GetWorkItemUidsForWorkItem(Proxy.Item.Oid); foreach (WorkItemUid sop in list) { uidBroker.Delete(sop); } context.Commit(); } Proxy.Delete(); }
private static void DeleteAllWorkItemUids() { using (var context = new DataAccessContext()) { var workItemUidBroker = context.GetWorkItemUidBroker(); workItemUidBroker.DeleteAll(); var workItemBroker = context.GetWorkItemBroker(); workItemBroker.DeleteAll(); context.Commit(); } }
public void TestGetWorkItemUidsForWorkItem() { DeleteAllWorkItemUids(); long workItemOidA, workItemOidB, workItemOidC, workItemOidD; using (var context = new DataAccessContext()) { WorkItem workItemA, workItemB, workItemC, workItemD; var workItemBroker = context.GetWorkItemBroker(); workItemBroker.AddWorkItem(workItemA = CreateWorkItem("A")); workItemBroker.AddWorkItem(workItemB = CreateWorkItem("B")); workItemBroker.AddWorkItem(workItemC = CreateWorkItem("C")); workItemBroker.AddWorkItem(workItemD = CreateWorkItem("D")); var broker = context.GetWorkItemUidBroker(); broker.AddWorkItemUid(CreateWorkItemUid(workItemA, "file1", "series1", "sop1")); broker.AddWorkItemUid(CreateWorkItemUid(workItemA, "file4", "series2", "sop4")); broker.AddWorkItemUid(CreateWorkItemUid(workItemB, "file6", "series4", "sop6")); broker.AddWorkItemUid(CreateWorkItemUid(workItemA, "file3", "series2", "sop3")); broker.AddWorkItemUid(CreateWorkItemUid(workItemA, "file2", "series1", "sop2")); broker.AddWorkItemUid(CreateWorkItemUid(workItemB, "file5", "series3", "sop5")); context.Commit(); workItemOidA = workItemA.Oid; workItemOidB = workItemB.Oid; workItemOidC = workItemC.Oid; workItemOidD = workItemD.Oid; } using (var context = new DataAccessContext()) { var workItemBroker = context.GetWorkItemBroker(); workItemBroker.Delete(workItemBroker.GetWorkItem(workItemOidD)); context.Commit(); } using (var context = new DataAccessContext()) { var broker = context.GetWorkItemUidBroker(); var listA = broker.GetWorkItemUidsForWorkItem(workItemOidA).OrderBy(x => x.File).ToList(); var listB = broker.GetWorkItemUidsForWorkItem(workItemOidB).OrderBy(x => x.File).ToList(); var listC = broker.GetWorkItemUidsForWorkItem(workItemOidC); var listD = broker.GetWorkItemUidsForWorkItem(workItemOidD); Assert.AreEqual(4, listA.Count, "Unexpected number of results for work item A"); Assert.AreEqual("file1", listA[0].File, "Unexpected result for work item A"); Assert.AreEqual("file2", listA[1].File, "Unexpected result for work item A"); Assert.AreEqual("file3", listA[2].File, "Unexpected result for work item A"); Assert.AreEqual("file4", listA[3].File, "Unexpected result for work item A"); Assert.AreEqual(2, listB.Count, "Unexpected number of results for work item B"); Assert.AreEqual("file5", listB[0].File, "Unexpected result for work item A"); Assert.AreEqual("file6", listB[1].File, "Unexpected result for work item A"); Assert.AreEqual(0, listC.Count, "Unexpected results for work item C"); Assert.AreEqual(0, listD.Count, "Unexpected results for work item D"); } }
protected override void OnExecute(CommandProcessor theProcessor) { var workItemBroker = DataAccessContext.GetWorkItemBroker(); DateTime now = Platform.Time; if (WorkItem != null) { // Already have a committed WorkItem, just set the Oid WorkItemUid.WorkItemOid = WorkItem.Oid; WorkItem = workItemBroker.GetWorkItem(WorkItem.Oid); if (WorkItem.Status == WorkItemStatusEnum.Idle || WorkItem.Status == WorkItemStatusEnum.Pending || WorkItem.Status == WorkItemStatusEnum.InProgress) { WorkItem.ExpirationTime = now.AddSeconds(ExpirationDelaySeconds); var workItemUidBroker = DataAccessContext.GetWorkItemUidBroker(); workItemUidBroker.AddWorkItemUid(WorkItemUid); } else { WorkItem = null; } } if (WorkItem == null) { var list = workItemBroker.GetWorkItems(_request.WorkItemType, WorkItemStatusFilter.Active, _studyInstanceUid); if (list != null) { foreach (var item in list) { if (item.Request.GetType() == _request.GetType()) { var thisRequest = _request as DicomReceiveRequest; if (thisRequest != null) { var request = item.Request as DicomReceiveRequest; if (request != null) { if (request.SourceServerName.Equals(thisRequest.SourceServerName)) { WorkItem = item; break; } } } else { WorkItem = item; break; } } } } if (WorkItem == null) { WorkItem = new WorkItem { ScheduledTime = now.AddSeconds(WorkItemServiceSettings.Default.InsertDelaySeconds), Request = _request, ProcessTime = now.AddSeconds(WorkItemServiceSettings.Default.InsertDelaySeconds), Priority = _request.Priority, Type = _request.WorkItemType, DeleteTime = now.AddHours(2), ExpirationTime = now.AddSeconds(ExpirationDelaySeconds), RequestedTime = now, StudyInstanceUid = _studyInstanceUid, Status = WorkItemStatusEnum.Pending, Progress = _progress }; workItemBroker.AddWorkItem(WorkItem); WorkItemUid.WorkItem = WorkItem; var workItemUidBroker = DataAccessContext.GetWorkItemUidBroker(); workItemUidBroker.AddWorkItemUid(WorkItemUid); } else { WorkItem.ExpirationTime = now.AddSeconds(ExpirationDelaySeconds); WorkItemUid.WorkItemOid = WorkItem.Oid; var workItemUidBroker = DataAccessContext.GetWorkItemUidBroker(); workItemUidBroker.AddWorkItemUid(WorkItemUid); } } }
public void TestAddAndGet() { DeleteAllWorkItemUids(); long oid, workItemOid; string version; using (var context = new DataAccessContext()) { WorkItem workItem; var workItemBroker = context.GetWorkItemBroker(); workItemBroker.AddWorkItem(workItem = CreateWorkItem("A")); var workItemUid = CreateWorkItemUid(workItem, "ABCDEF", "2", "3", true, true, 123); var broker = context.GetWorkItemUidBroker(); broker.AddWorkItemUid(workItemUid); context.Commit(); workItemOid = workItem.Oid; Assert.AreNotEqual(0, oid = workItemUid.Oid, "Oid should have been assigned on insert"); Assert.IsNotNull(workItemUid.Version, "Version should have been assigned on insert"); version = workItemUid.Version.ToString(); } using (var context = new DataAccessContext()) { var broker = context.GetWorkItemUidBroker(); var workItemUid = broker.GetWorkItemUid(oid); Assert.AreEqual("ABCDEF", workItemUid.File, "File"); Assert.AreEqual("2", workItemUid.SeriesInstanceUid, "SeriesInstanceUid"); Assert.AreEqual("3", workItemUid.SopInstanceUid, "SopInstanceUid"); Assert.AreEqual(workItemOid, workItemUid.WorkItemOid, "WorkItemOid"); Assert.AreEqual(true, workItemUid.Complete, "Complete"); Assert.AreEqual(true, workItemUid.Failed, "Failed"); Assert.AreEqual(123, workItemUid.FailureCount, "FailureCount"); workItemUid.Failed = false; workItemUid.FailureCount = null; context.Commit(); Assert.AreNotEqual(version, workItemUid.Version, "Version should have been changed on update"); } using (var context = new DataAccessContext()) { var broker = context.GetWorkItemUidBroker(); var workItemUid = broker.GetWorkItemUid(oid); Assert.AreEqual("ABCDEF", workItemUid.File, "File"); Assert.AreEqual("2", workItemUid.SeriesInstanceUid, "SeriesInstanceUid"); Assert.AreEqual("3", workItemUid.SopInstanceUid, "SopInstanceUid"); Assert.AreEqual(workItemOid, workItemUid.WorkItemOid, "WorkItemOid"); Assert.AreEqual(true, workItemUid.Complete, "Complete"); Assert.AreEqual(false, workItemUid.Failed, "Failed"); Assert.AreEqual(null, workItemUid.FailureCount, "FailureCount"); } }
public void TestGetWorkItemUidsForWorkItem() { DeleteAllWorkItemUids(); long workItemOidA, workItemOidB, workItemOidC, workItemOidD; using (var context = new DataAccessContext()) { WorkItem workItemA, workItemB, workItemC, workItemD; var workItemBroker = context.GetWorkItemBroker(); workItemBroker.AddWorkItem(workItemA = CreateWorkItem("A")); workItemBroker.AddWorkItem(workItemB = CreateWorkItem("B")); workItemBroker.AddWorkItem(workItemC = CreateWorkItem("C")); workItemBroker.AddWorkItem(workItemD = CreateWorkItem("D")); var broker = context.GetWorkItemUidBroker(); broker.AddWorkItemUid(CreateWorkItemUid(workItemA, "file1", "series1", "sop1")); broker.AddWorkItemUid(CreateWorkItemUid(workItemA, "file4", "series2", "sop4")); broker.AddWorkItemUid(CreateWorkItemUid(workItemB, "file6", "series4", "sop6")); broker.AddWorkItemUid(CreateWorkItemUid(workItemA, "file3", "series2", "sop3")); broker.AddWorkItemUid(CreateWorkItemUid(workItemA, "file2", "series1", "sop2")); broker.AddWorkItemUid(CreateWorkItemUid(workItemB, "file5", "series3", "sop5")); context.Commit(); workItemOidA = workItemA.Oid; workItemOidB = workItemB.Oid; workItemOidC = workItemC.Oid; workItemOidD = workItemD.Oid; } using (var context = new DataAccessContext()) { var workItemBroker = context.GetWorkItemBroker(); workItemBroker.Delete(workItemBroker.GetWorkItem(workItemOidD)); context.Commit(); } using (var context = new DataAccessContext()) { var broker = context.GetWorkItemUidBroker(); var listA = broker.GetWorkItemUidsForWorkItem(workItemOidA).OrderBy(x => x.File).ToList(); var listB = broker.GetWorkItemUidsForWorkItem(workItemOidB).OrderBy(x => x.File).ToList(); var listC = broker.GetWorkItemUidsForWorkItem(workItemOidC); var listD = broker.GetWorkItemUidsForWorkItem(workItemOidD); Assert.AreEqual(4, listA.Count, "Unexpected number of results for work item A"); Assert.AreEqual("file1", listA[0].File, "Unexpected result for work item A"); Assert.AreEqual("file2", listA[1].File, "Unexpected result for work item A"); Assert.AreEqual("file3", listA[2].File, "Unexpected result for work item A"); Assert.AreEqual("file4", listA[3].File, "Unexpected result for work item A"); Assert.AreEqual(2, listB.Count, "Unexpected number of results for work item B"); Assert.AreEqual("file5", listB[0].File, "Unexpected result for work item A"); Assert.AreEqual("file6", listB[1].File, "Unexpected result for work item A"); Assert.AreEqual(0, listC.Count, "Unexpected results for work item C"); Assert.AreEqual(0, listD.Count, "Unexpected results for work item D"); } }