private void WorkItemsChanged(object sender, WorkItemsChangedEventArgs e) { var workItems = e.ChangedItems; if (workItems.Any(item => item.Request.ConcurrencyType == WorkItemConcurrency.StudyUpdate || item.Request.ConcurrencyType == WorkItemConcurrency.StudyDelete || item.Type.Equals(ReindexRequest.WorkItemTypeString))) { _studyCountWatcher.Invalidate(); } var items = workItems.Select(item => new WorkItem(item)).ToList(); // by wrapping this in a transaction, we help the view to retain the current selection // and scroll position where possible using (_workItems.Items.BeginTransaction()) { var needSort = _workItemManager.Update(items, _workItems.SortParams.GetComparer().Compare); if (needSort) { _workItems.Sort(); } } _workItemActionModel.OnWorkItemsChanged(items); }
private void UpdateProgress(object sender, WorkItemsChangedEventArgs workItemsChangedEventArgs) { foreach (var item in workItemsChangedEventArgs.ChangedItems) { UpdateProgress(item); } }
/// <summary> /// Work Items Changed event handler. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnWorkItemsChangedAsync(object sender, WorkItemsChangedEventArgs args) { // ignore refresh events if (args.EventType == WorkItemsChangedEventType.Refresh || args.ChangedItems == null) { return; } var syncContext = _synchronizationContext; if (syncContext == null) { return; } lock (_syncLock) { var previousChangedStudiesCount = _setChangedStudies.Count; foreach (var item in args.ChangedItems) { var theItem = item; if (theItem.Type.Equals(ReindexRequest.WorkItemTypeString)) { syncContext.Post(ignore => UpdateReindexing(theItem.Status == WorkItemStatusEnum.InProgress), false); } if (item.Request.ConcurrencyType == WorkItemConcurrency.StudyRead) { continue; //If it's a "read" operation, don't update anything. } if (item.Request.ConcurrencyType == WorkItemConcurrency.StudyDelete) { _hastenUpdateQuery = true; //We want deleted studies to disappear quickly, so make a hasty update query. } //If it's not a read operation, but it has a Study UID, then it's probably updating studies. //(e.g. re-index, re-apply rules, import, process study). if (!String.IsNullOrEmpty(item.StudyInstanceUid)) { if (Platform.IsLogLevelEnabled(LogLevel.Debug)) { Platform.Log(LogLevel.Debug, "Study '{0}' has changed (Work Item: {1}, {2})", item.StudyInstanceUid, item.Identifier, item.Type); } _setChangedStudies[item.StudyInstanceUid] = item.StudyInstanceUid; } } if (_setChangedStudies.Count > previousChangedStudiesCount) { Platform.Log(LogLevel.Debug, "{0} studies changed since the last update.", _setChangedStudies.Count); //Only update this if we've received a message for a study not already in the set. //We're only interested in the unique set of studies that has changed (or is changing) //since the last time we updated the studies in the study list. _lastStudyChangeTime = DateTime.Now; } } }
private void WorkItemChanged3(object sender, WorkItemsChangedEventArgs e) { lock (_syncLock) { ++_workItemChanged3Count; --_expectedAsyncEventCount; Monitor.Pulse(_syncLock); } }
private void OnWorkItemsChanged(object sender, WorkItemsChangedEventArgs eventArgs) { if (eventArgs.EventType != WorkItemsChangedEventType.Update || eventArgs.ChangedItems.IsNullOrEmpty()) { return; // We are only interested in Update events } foreach (var workItemData in eventArgs.ChangedItems) { // Fire event when import ends or an item is removed if (workItemData.Type == "ProcessStudy") { if (workItemData.Status == WorkItemStatusEnum.Idle || workItemData.Status == WorkItemStatusEnum.Complete || workItemData.Status == WorkItemStatusEnum.Deleted) { // HACK: To minimize number of readings of annotation documents, we remember studies that were already updated when their Status == Idle long idleKey = 0x3B3402E0 ^ workItemData.Identifier ^ workItemData.StudyInstanceUid.GetHashCode(); if (workItemData.Status == WorkItemStatusEnum.Idle) { // NOTE: we cannot skip updating on any Idle status because there could be new SOPs processed just before the Idle status kicked in if (!_updatedIdleStudies.Contains(idleKey)) { _updatedIdleStudies.Add(idleKey); } } else { if (_updatedIdleStudies.Contains(idleKey)) { _updatedIdleStudies.Remove(idleKey); continue; // update event was sent already } } DoStudyUpdate(workItemData.StudyInstanceUid); } } else if (workItemData.Type == "DeleteSeries") { if (workItemData.Status == WorkItemStatusEnum.Complete) { DoStudyUpdate(workItemData.StudyInstanceUid); } } else if (workItemData.Type == "DeleteStudy") { if (workItemData.Status == WorkItemStatusEnum.Complete) { DoStudyUpdate(workItemData.StudyInstanceUid); } } } }
private void OnWorkItemsChanged(object sender, WorkItemsChangedEventArgs e) { foreach (var workItem in e.ChangedItems) { if (workItem.Request != null) { Console.WriteLine("Received WorkItemsChanged event: {0}:{1}.", workItem.Request.ActivityTypeString, workItem.Request.ActivityDescription); if (workItem.Progress != null) Console.WriteLine(" Progress: {0}, Details: {1}.", workItem.Progress.Status, workItem.Progress.StatusDetails); } else Console.WriteLine("Received WorkItemsChanged event."); } }
void WorkItemsChanged(object sender, WorkItemsChangedEventArgs e) { if (e.EventType == WorkItemsChangedEventType.Update) { foreach (var workItem in e.ChangedItems) { if (!String.IsNullOrEmpty(workItem.StudyInstanceUid) && workItem.Type == "ProcessStudy") { if (workItem.Status == WorkItemStatusEnum.Idle) { // Assume studies are all imported when an idle has been received for each import lock (_lock) { foreach (var item in e.ChangedItems) { if (_studyUidsTempFolders.ContainsKey(item.StudyInstanceUid)) { _asyncOperation.Post(delegate { ImportStatus = ImportStatus.Imported; }, this); } } } } if (workItem.Status == WorkItemStatusEnum.Complete) { // Actually delete the unzipped files from the XNAT download folder when a complete is received from the workitemactivitymonitor lock (_lock) { foreach (var item in e.ChangedItems) { if (_studyUidsTempFolders.ContainsKey(item.StudyInstanceUid)) { Directory.Delete(_studyUidsTempFolders[item.StudyInstanceUid], true); OnImportCompleted(this); _asyncOperation.Post(delegate { ImportStatus = ImportStatus.Searching; }, this); _studyUidsTempFolders.Remove(item.StudyInstanceUid); } } } } } } } }
private void OnWorkItemsChanged(object sender, WorkItemsChangedEventArgs e) { if (e.EventType != WorkItemsChangedEventType.Update || e.ChangedItems == null || !e.ChangedItems.Any()) { return; // We are only interested in Update events } var studiesWithAddedInstances = new HashSet <string>(); foreach (WorkItemData workItemData in e.ChangedItems) { if (workItemData.Type == "ProcessStudy") { if (workItemData.Status == WorkItemStatusEnum.Idle || workItemData.Status == WorkItemStatusEnum.Complete || workItemData.Status == WorkItemStatusEnum.Deleted) { if (workItemData.Status == WorkItemStatusEnum.Idle) { // NOTE: new SOPs are already available when Idle status kicked in if (!string.IsNullOrEmpty(workItemData.StudyInstanceUid)) { studiesWithAddedInstances.Add(workItemData.StudyInstanceUid); } } } } else if (workItemData.Type == "DeleteSeries") { // TODO: remove graphics if the Segmentation instance is deleted? //if (workItemData.Status == WorkItemStatusEnum.Complete) //{ //} } } if (studiesWithAddedInstances.Any()) { // Load new segmentations asynchronously SynchronizationContext.Current.Post((state => LoadNewSeries(studiesWithAddedInstances.ToList())), null); } }
private void OnWorkItemsChanged(object sender, WorkItemsChangedEventArgs e) { foreach (var workItem in e.ChangedItems) { if (workItem.Request != null) { Console.WriteLine("Received WorkItemsChanged event: {0}:{1}.", workItem.Request.ActivityTypeString, workItem.Request.ActivityDescription); if (workItem.Progress != null) { Console.WriteLine(" Progress: {0}, Details: {1}.", workItem.Progress.Status, workItem.Progress.StatusDetails); } } else { Console.WriteLine("Received WorkItemsChanged event."); } } }
private void WorkItemsChanged(object sender, WorkItemsChangedEventArgs e) { foreach (var item in e.ChangedItems) { if (item.Request is DicomReceiveRequest) { lock (StudyWorkItemsSyncLock) { WorkItem workItem; if (StudyWorkItems.TryGetValue(item.StudyInstanceUid, out workItem)) { if (workItem.Oid == item.Identifier) { workItem.Status = item.Status; workItem.Progress = item.Progress; } } } } } }
private void ActivityMonitorWorkItemsChanged(object sender, WorkItemsChangedEventArgs e) { foreach (var item in e.ChangedItems) { // check for a new failure, and raise an alert if necessary if (!_failedWorkItems.Contains(item.Identifier) && item.Status == WorkItemStatusEnum.Failed) { _failedWorkItems.Add(item.Identifier); if (item.Patient != null && item.Study != null) { var studyDate = DateParser.Parse(item.Study.StudyDate); var message = string.Format(SR.MessageWorkItemFailed, item.Request.ActivityTypeString, item.Patient.PatientsName, studyDate.HasValue ? Format.Date(studyDate.Value) : string.Empty, item.Study.AccessionNumber); _window.ShowAlert(AlertLevel.Error, message, SR.LinkOpenActivityMonitor, window => _showActivityMonitor(), true); } else { var message = string.Format(SR.MessageNonStudyWorkItemFailed, item.Request.ActivityTypeString); _window.ShowAlert(AlertLevel.Error, message, SR.LinkOpenActivityMonitor, window => _showActivityMonitor(), true); } } // if a previously failed item is re-tried, remove it from the set of failed items if (_failedWorkItems.Contains(item.Identifier) && item.Status != WorkItemStatusEnum.Failed) { _failedWorkItems.Remove(item.Identifier); } } }