private void Publish(bool saveToDatabase) { if (saveToDatabase) { try { using (var context = new DataAccessContext(DataAccessContext.WorkItemMutex)) { var broker = context.GetWorkItemBroker(); Item = broker.GetWorkItem(Item.Oid); Item.Progress = Progress; context.Commit(); } } catch (Exception) { // Saw ChangeCOnflictException here a few times } } else { Item.Progress = Progress; } WorkItemPublishSubscribeHelper.PublishWorkItemChanged(WorkItemsChangedEventType.Update, WorkItemDataHelper.FromWorkItem(Item)); }
protected override void ProcessItem(Study study) { var result = EventResult.Success; try { WorkItem item; using (var context = new DataAccessContext(DataAccessContext.WorkItemMutex)) { item = ProcessStudy(study.Oid, context); context.Commit(); } if (item != null) { WorkItemPublishSubscribeHelper.PublishWorkItemChanged(WorkItemsChangedEventType.Update, WorkItemDataHelper.FromWorkItem(item)); } } catch (Exception) { result = EventResult.MajorFailure; throw; } finally { var instances = new AuditedInstances(); instances.AddInstance(study.PatientId, study.PatientsName, study.StudyInstanceUid); AuditHelper.LogDeleteStudies(AuditHelper.LocalAETitle, instances, EventSource.CurrentUser, result); } }
public WorkItemInsertResponse Insert(WorkItemInsertRequest request) { // TODO (CR Jun 2012): The fact that there is special processing in here for particular types of work items // indicates there is something wrong with the design that may make adding custom work item types difficult. // Maybe the different "processors" need to perform the insert, or at least have some kind of method (rule) // for processing the insert? var response = new WorkItemInsertResponse(); var now = DateTime.Now; var item = new Interface.WorkItem { Request = request.Request, Progress = request.Progress, Type = request.Request.WorkItemType, Priority = request.Request.Priority, ScheduledTime = now.AddSeconds(WorkItemServiceSettings.Default.InsertDelaySeconds), ProcessTime = now.AddSeconds(WorkItemServiceSettings.Default.InsertDelaySeconds), DeleteTime = now.AddMinutes(WorkItemServiceSettings.Default.DeleteDelayMinutes), ExpirationTime = now.AddSeconds(WorkItemServiceSettings.Default.ExpireDelaySeconds), RequestedTime = now, Status = WorkItemStatusEnum.Pending }; IoC.Get <IWorkItemOperation>().AddWorkItem(item); WorkItemPublishSubscribeHelper.PublishWorkItemChanged(WorkItemsChangedEventType.Update, response.Item); if (WorkItemProcessor.Instance != null) { WorkItemProcessor.Instance.SignalThread(); } return(response); }
public WorkItemPublishResponse Publish(WorkItemPublishRequest request) { try { WorkItemPublishSubscribeHelper.PublishWorkItemChanged(WorkItemsChangedEventType.Update, request.Item); return(new WorkItemPublishResponse()); } catch (Exception e) { var message = "Failed to process WorkItem Publish request."; var exceptionMessage = String.Format("{0}\nDetail:{1}", message, e.Message); throw new WorkItemServiceException(exceptionMessage); } }
public WorkItemUpdateResponse Update(WorkItemUpdateRequest request) { var response = new WorkItemUpdateResponse(); var workItem = IoC.Get <IWorkItemOperation>().GetWorkItem(request.Identifier); if (workItem == null) { response.Item = null; return(response); } var deleted = false; if (request.Delete.HasValue && request.Delete.Value) { if (workItem.Status != WorkItemStatusEnum.InProgress) { workItem.Status = WorkItemStatusEnum.Deleted; deleted = true; // If StudyDelete we're removing, "undelete" the study // CheckDeleteStudyCanceled(context, workItem); } } if (!deleted) { if (request.ExpirationTime.HasValue) { workItem.ExpirationTime = request.ExpirationTime.Value; } if (request.Priority.HasValue) { workItem.Priority = request.Priority.Value; } if (request.Status.HasValue && workItem.Status != WorkItemStatusEnum.InProgress) { workItem.Status = request.Status.Value; if (request.Status.Value == WorkItemStatusEnum.Canceled) { workItem.DeleteTime = DateTime.Now.AddMinutes(WorkItemServiceSettings.Default.DeleteDelayMinutes); } else if (request.Status.Value == WorkItemStatusEnum.Pending) { workItem.ScheduledTime = DateTime.Now; workItem.FailureCount = 0; } // Cache the UserIdentityContext for later use by the shred //if (workItem.Request.WorkItemType.Equals(ImportFilesRequest.WorkItemTypeString) && // request.Status.Value == WorkItemStatusEnum.Pending) // UserIdentityCache.Put(workItem.Oid, UserIdentityContext.CreateFromCurrentThreadPrincipal()); } if (request.ProcessTime.HasValue) { workItem.ProcessTime = request.ProcessTime.Value; } // Cancel if (request.Cancel.HasValue && request.Cancel.Value) { if (workItem.Progress == null || workItem.Progress.IsCancelable) { if (workItem.Status.Equals(WorkItemStatusEnum.Idle) || workItem.Status.Equals(WorkItemStatusEnum.Pending)) { workItem.Status = WorkItemStatusEnum.Canceled; // If StudyDelete we're removing, "undelete" the study // CheckDeleteStudyCanceled(context, workItem); } else if (workItem.Status.Equals(WorkItemStatusEnum.InProgress)) { // Abort the WorkItem WorkItemProcessor.Instance.Cancel(workItem.Oid); } } } // Pause if (request.Pause.HasValue && request.Pause.Value) { if (workItem.Progress == null || workItem.Progress.IsPauseable) { if (workItem.Status.Equals(WorkItemStatusEnum.Idle) || workItem.Status.Equals(WorkItemStatusEnum.Pending)) { workItem.Status = WorkItemStatusEnum.Pause; } else if (workItem.Status.Equals(WorkItemStatusEnum.InProgress)) { // Pause the WorkItem WorkItemProcessor.Instance.Pause(workItem.Oid); } } } IoC.Get <IWorkItemOperation>().SaveWorkItem(workItem); response.Item = WorkItemDataHelper.FromWorkItem(workItem); } WorkItemPublishSubscribeHelper.PublishWorkItemChanged(WorkItemsChangedEventType.Update, response.Item); return(response); }
public WorkItemInsertResponse Insert(WorkItemInsertRequest request) { // TODO (CR Jun 2012): The fact that there is special processing in here for particular types of work items // indicates there is something wrong with the design that may make adding custom work item types difficult. // Maybe the different "processors" need to perform the insert, or at least have some kind of method (rule) // for processing the insert? var response = new WorkItemInsertResponse(); using (var context = new DataAccessContext(DataAccessContext.WorkItemMutex)) { DateTime now = Platform.Time; var broker = context.GetWorkItemBroker(); if (request.Request.WorkItemType.Equals(ReindexRequest.WorkItemTypeString)) { var list = broker.GetWorkItems(request.Request.WorkItemType, null, null); foreach (var workItem in list) { if (workItem.Status == WorkItemStatusEnum.Pending || workItem.Status == WorkItemStatusEnum.InProgress) { response.Item = WorkItemDataHelper.FromWorkItem(workItem); return(response); } } } var deleteStudyRequest = request.Request as DeleteStudyRequest; if (deleteStudyRequest != null) { var list = broker.GetWorkItems(request.Request.WorkItemType, null, deleteStudyRequest.Study.StudyInstanceUid); foreach (var workItem in list) { if (workItem.Status == WorkItemStatusEnum.Pending || workItem.Status == WorkItemStatusEnum.InProgress) { // Mark studies to delete as "deleted" in the database. var studyBroker = context.GetStudyBroker(); var study = studyBroker.GetStudy(deleteStudyRequest.Study.StudyInstanceUid); if (study != null) { study.Deleted = true; context.Commit(); } response.Item = WorkItemDataHelper.FromWorkItem(workItem); return(response); } } } var item = new WorkItem { Request = request.Request, Progress = request.Progress, Type = request.Request.WorkItemType, Priority = request.Request.Priority, ScheduledTime = now.AddSeconds(WorkItemServiceSettings.Default.InsertDelaySeconds), ProcessTime = now.AddSeconds(WorkItemServiceSettings.Default.InsertDelaySeconds), DeleteTime = now.AddMinutes(WorkItemServiceSettings.Default.DeleteDelayMinutes), ExpirationTime = now.AddSeconds(WorkItemServiceSettings.Default.ExpireDelaySeconds), RequestedTime = now, Status = WorkItemStatusEnum.Pending }; var studyRequest = request.Request as WorkItemStudyRequest; if (studyRequest != null) { item.StudyInstanceUid = studyRequest.Study.StudyInstanceUid; if (request.Request.WorkItemType.Equals(DeleteStudyRequest.WorkItemTypeString)) { // Mark studies to delete as "deleted" in the database. var studyBroker = context.GetStudyBroker(); var study = studyBroker.GetStudy(studyRequest.Study.StudyInstanceUid); if (study != null) { study.Deleted = true; } } } broker.AddWorkItem(item); context.Commit(); response.Item = WorkItemDataHelper.FromWorkItem(item); } // Cache the UserIdentityContext for later use by the shred if (request.Request.WorkItemType.Equals(ImportFilesRequest.WorkItemTypeString)) { UserIdentityCache.Put(response.Item.Identifier, UserIdentityContext.CreateFromCurrentThreadPrincipal()); } WorkItemPublishSubscribeHelper.PublishWorkItemChanged(WorkItemsChangedEventType.Update, response.Item); if (WorkItemProcessor.Instance != null) { WorkItemProcessor.Instance.SignalThread(); } return(response); }