protected void InsertRequest(WorkItemRequest request, WorkItemProgress progress) { WorkItemInsertResponse response = null; // Used for auditing purposes in the ShredHostService. if (string.IsNullOrEmpty(request.UserName)) { request.UserName = GetUserName(); } Request = request; Platform.GetService <IWorkItemService>(s => response = s.Insert(new WorkItemInsertRequest { Request = request, Progress = progress })); // TODO (CR Jun 2012): The passed-in WorkItem contract should not be updated; // it should be done by the service and a new instance returned, or something should be returned by this // method to let the caller decide what to do. if (response.Item == null) { WorkItem.Status = WorkItemStatusEnum.Deleted; } else { WorkItem = response.Item; } }
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; }