Esempio n. 1
0
        /// <summary>
        /// Finds all storage locations used for the study.
        /// </summary>
        protected void FindAllRelatedDirectories()
        {
            // Check the work queue for other entries
            IList<Model.WorkQueue> list;

            // NOTE: a local read context is used for lookup because we want to
            // release the lock on the rows asap.
            using (IReadContext ctx = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
            {
                IWorkQueueEntityBroker broker = ctx.GetBroker<IWorkQueueEntityBroker>();
                WorkQueueSelectCriteria criteria = new WorkQueueSelectCriteria();
                criteria.StudyStorageKey.EqualTo(WorkQueueItem.StudyStorageKey);
                list = broker.Find(criteria);
            }


            List<DirectoryInfo> dirs = new List<DirectoryInfo>();
            foreach(Model.WorkQueue item in list)
            {
                string path = GetWorkQueueSecondaryFolder(item);
                if (!string.IsNullOrEmpty(path))    
                    dirs.Add(new DirectoryInfo(path));
            }

            // NOTE: Under normal operation, the SIQ entries should be 
            // empty at this point because the Delete Study button is disabled otherwise.
            // This block of code is still needed just in case this DeleteStudy work queue entry
            // is inserted through different means.
            IList<StudyIntegrityQueue> siqList;
            using (IReadContext ctx = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
            {
                IStudyIntegrityQueueEntityBroker broker = ctx.GetBroker<IStudyIntegrityQueueEntityBroker>();
                StudyIntegrityQueueSelectCriteria criteria = new StudyIntegrityQueueSelectCriteria();
                criteria.StudyStorageKey.EqualTo(WorkQueueItem.StudyStorageKey);
                siqList = broker.Find(criteria);
            }

            foreach (StudyIntegrityQueue item in siqList)
            {
                string path = GetSIQItemStorageFolder(item);
                if (!string.IsNullOrEmpty(path))
                    dirs.Add(new DirectoryInfo(path));
            }


            _relatedDirectories = dirs;
        }
Esempio n. 2
0
        /// <summary>
        /// Finds a list of <see cref="WorkQueue"/> related to the specified <see cref="studyStorageKey"/>.
        /// </summary>
        /// <param name="studyStorageKey"></param>
        /// <param name="filter">A delegate that will be used to filter the returned list. Pass in Null to get the entire list.</param>
        /// <returns>A list of  <see cref="WorkQueue"/></returns>
        static public IList<WorkQueue> FindWorkQueueEntries(ServerEntityKey studyStorageKey, Predicate<WorkQueue> filter)
        {
            Platform.CheckForNullReference(studyStorageKey, "studyStorageKey");

            using (var scope = new ServerExecutionContext())
            {
                var broker = scope.PersistenceContext.GetBroker<IWorkQueueEntityBroker>();
                var criteria = new WorkQueueSelectCriteria();
                criteria.StudyStorageKey.EqualTo(studyStorageKey);
                criteria.InsertTime.SortDesc(0);
                IList<WorkQueue> list = broker.Find(criteria);
                if (filter != null)
                {
                    CollectionUtils.Remove(list, filter);
                }
                return list;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Checks for the existinance of a SOP for a given Study in the <see cref="WorkQueue"/> for a <see cref="WorkQueueTypeEnum.ReconcileStudy"/>.
        /// </summary>
        /// <param name="studyStorageKey">The StudyStorage primary key</param>
        /// <param name="seriesInstanceUid">The Series Instance Uid of the Sop</param>
        /// <param name="sopInstanceUid">The Sop Instance to look for</param>
        /// <returns>true if an entry exists, false if it doesn't</returns>
        static public bool WorkQueueUidExists(ServerEntityKey studyStorageKey, string seriesInstanceUid, string sopInstanceUid)
        {
            Platform.CheckForNullReference(studyStorageKey, "studyStorageKey");

            using (var scope = new ServerExecutionContext())
            {
                var broker = scope.PersistenceContext.GetBroker<IWorkQueueEntityBroker>();
                var uidSelectCriteria = new WorkQueueUidSelectCriteria();
                uidSelectCriteria.SeriesInstanceUid.EqualTo(seriesInstanceUid);
                uidSelectCriteria.SopInstanceUid.EqualTo(sopInstanceUid);
                var selectCriteria = new WorkQueueSelectCriteria();
                selectCriteria.StudyStorageKey.EqualTo(studyStorageKey);
                selectCriteria.WorkQueueTypeEnum.EqualTo(WorkQueueTypeEnum.ReconcileStudy);
                selectCriteria.WorkQueueUidRelatedEntityCondition.Exists(uidSelectCriteria);

                return broker.Count(selectCriteria) > 0;
            }
        }
        protected override void OnExecute(CommandProcessor theProcessor, IUpdateContext updateContext)
        {
            var filesystemQueueBroker= updateContext.GetBroker<IFilesystemQueueEntityBroker>();
            var criteria = new FilesystemQueueSelectCriteria();
            criteria.StudyStorageKey.EqualTo(_storageLocationKey);
            IList<FilesystemQueue> filesystemQueueItems = filesystemQueueBroker.Find(criteria);

            var workQueueBroker = updateContext.GetBroker<IWorkQueueEntityBroker>();
            var workQueueCriteria = new WorkQueueSelectCriteria();
            workQueueCriteria.StudyStorageKey.EqualTo(_storageLocationKey);
			workQueueCriteria.WorkQueueTypeEnum.In(new[] { WorkQueueTypeEnum.PurgeStudy, WorkQueueTypeEnum.DeleteStudy, WorkQueueTypeEnum.CompressStudy, WorkQueueTypeEnum.MigrateStudy });
            IList<WorkQueue> workQueueItems = workQueueBroker.Find(workQueueCriteria);

            foreach (FilesystemQueue queue in filesystemQueueItems)
            {
            	bool delete = false;
				if (_applyTime.Equals(ServerRuleApplyTimeEnum.StudyArchived))
				{
					if (queue.FilesystemQueueTypeEnum.Equals(FilesystemQueueTypeEnum.PurgeStudy))
						delete = true;
				}
				else
				{
					delete = true;
				}

				if (delete)
				{
					if (!filesystemQueueBroker.Delete(queue.GetKey()))
						throw new ApplicationException("Unable to delete items in the filesystem queue");
				}
            }

			if (!_applyTime.Equals(ServerRuleApplyTimeEnum.StudyArchived))
			{
				// delete work queue
				foreach (Model.WorkQueue item in workQueueItems)
				{
					if (!item.Delete(updateContext))
						throw new ApplicationException("Unable to delete items in the work queue");
				}
			}
        }
		private Study GetStudyAndQueues(StudyStorageLocation location, out int integrityQueueCount, out int workQueueCount)
		{
			using (IReadContext context = _store.OpenReadContext())
			{
				IStudyIntegrityQueueEntityBroker integrityBroker = context.GetBroker<IStudyIntegrityQueueEntityBroker>();
				StudyIntegrityQueueSelectCriteria integrityCriteria = new StudyIntegrityQueueSelectCriteria();
				integrityCriteria.StudyStorageKey.EqualTo(location.Key);
				integrityQueueCount = integrityBroker.Count(integrityCriteria);

				IWorkQueueEntityBroker workBroker = context.GetBroker<IWorkQueueEntityBroker>();
				WorkQueueSelectCriteria workCriteria = new WorkQueueSelectCriteria();
				workCriteria.StudyStorageKey.EqualTo(location.Key);
				workQueueCount = workBroker.Count(workCriteria);

				IStudyEntityBroker procedure = context.GetBroker<IStudyEntityBroker>();
				StudySelectCriteria criteria = new StudySelectCriteria();
				criteria.StudyStorageKey.EqualTo(location.Key);
				return procedure.FindOne(criteria);
			}
		}
Esempio n. 6
0
        public int GetCountPendingExternalEditWorkQueueItems(Study study)
        {
            Platform.CheckForNullReference(study, "Study");

            var adaptor = new WorkQueueAdaptor();
            var workQueueCriteria = new WorkQueueSelectCriteria();
            workQueueCriteria.StudyStorageKey.EqualTo(study.StudyStorageKey);
            workQueueCriteria.WorkQueueTypeEnum.EqualTo(WorkQueueTypeEnum.ExternalEdit);
            return adaptor.GetCount(workQueueCriteria);
        }
Esempio n. 7
0
        public int GetCountPendingWorkQueueItems(Study study)
        {
            Platform.CheckForNullReference(study, "Study");

            var adaptor = new WorkQueueAdaptor();
            var workQueueCriteria = new WorkQueueSelectCriteria();
            workQueueCriteria.StudyStorageKey.EqualTo(study.StudyStorageKey);
            workQueueCriteria.WorkQueueStatusEnum.In(new [] {WorkQueueStatusEnum.Idle, WorkQueueStatusEnum.InProgress, WorkQueueStatusEnum.Pending});
            return adaptor.GetCount(workQueueCriteria);
        }
Esempio n. 8
0
        public IList<WorkQueue> GetWorkQueueItems(Study study)
        {
            Platform.CheckForNullReference(study, "Study");

            WorkQueueAdaptor adaptor = new WorkQueueAdaptor();
            WorkQueueSelectCriteria workQueueCriteria = new WorkQueueSelectCriteria();
			workQueueCriteria.StudyStorageKey.EqualTo(study.StudyStorageKey);
            workQueueCriteria.ScheduledTime.SortAsc(0);
            return adaptor.Get(workQueueCriteria);
        }
Esempio n. 9
0
        /// <summary>
        /// Returns a value indicating whether the specified study has been scheduled for delete.
        /// </summary>
        /// <param name="study"></param>
        /// <param name="workQueueType"></param>
        /// <returns></returns>           
		private static bool IsStudyInWorkQueue(Study study, WorkQueueTypeEnum workQueueType)
        {
        	Platform.CheckForNullReference(study, "Study");

        	WorkQueueAdaptor adaptor = new WorkQueueAdaptor();
        	WorkQueueSelectCriteria workQueueCriteria = new WorkQueueSelectCriteria();
        	workQueueCriteria.WorkQueueTypeEnum.EqualTo(workQueueType);
        	workQueueCriteria.ServerPartitionKey.EqualTo(study.ServerPartitionKey);
        	workQueueCriteria.StudyStorageKey.EqualTo(study.StudyStorageKey);

        	workQueueCriteria.WorkQueueStatusEnum.EqualTo(WorkQueueStatusEnum.Pending);

        	IList<WorkQueue> list = adaptor.Get(workQueueCriteria);
        	if (list != null && list.Count > 0)
        		return true;

        	workQueueCriteria.WorkQueueStatusEnum.EqualTo(WorkQueueStatusEnum.Idle); // not likely but who knows
        	list = adaptor.Get(workQueueCriteria);
        	if (list != null && list.Count > 0)
        		return true;

        	return false;
        }
Esempio n. 10
0
        public IList<WorkQueueInfo> GetWorkQueueOverview()
        {            
            IList<WorkQueueInfo> workQueueInfo = new List<WorkQueueInfo>();
            
            WorkQueueProcessorIDsParameters parameters = new WorkQueueProcessorIDsParameters();
            IWorkQueueProcessorIDs broker = HttpContext.Current.GetSharedPersistentContext().GetBroker<IWorkQueueProcessorIDs>();
            IList<WorkQueue> processorIDList = broker.Find(parameters);

            WorkQueueSelectCriteria criteria = new WorkQueueSelectCriteria();
            WorkQueueAdaptor adaptor = new WorkQueueAdaptor();
            int numItems = 0;
            foreach(WorkQueue row in processorIDList)
            {
                criteria.ProcessorID.EqualTo(row.ProcessorID);
                numItems = adaptor.GetCount(criteria);
                workQueueInfo.Add(new WorkQueueInfo(row.ProcessorID, numItems));
            }
            return workQueueInfo;
        }
Esempio n. 11
0
 public WorkQueueSelectCriteria(WorkQueueSelectCriteria other)
     : base(other)
 {
 }
Esempio n. 12
0
        private static bool CheckIfStudyIsInWorkQueue(ScanResultEntry scanResult)
        {

            using (IReadContext ctx = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
            {
                IWorkQueueEntityBroker broker = ctx.GetBroker<IWorkQueueEntityBroker>();
                WorkQueueSelectCriteria criteria = new WorkQueueSelectCriteria();
                criteria.StudyStorageKey.EqualTo(scanResult.Storage.Key);
                var list = broker.Find(criteria);
                scanResult.IsInWorkQueue = list != null && list.Count > 0;
            } 
            
            return scanResult.IsInWorkQueue;
        }
        /// <summary>
        /// Returns number of Delete Study, Tier Migrate, and Study Purge work queue items 
        /// that are still Pending or In Progress for the filesystem associated with the
        /// specified <see cref="ServiceLock"/>.
        /// </summary>
        /// <param name="item">The ServiceLock item.</param>
        /// <returns>The number of WorkQueue entries pending.</returns>
        private int CheckWorkQueueCount(Model.ServiceLock item)
        {
			using (ServerExecutionContext context = new ServerExecutionContext())
			{
				IWorkQueueEntityBroker select = context.ReadContext.GetBroker<IWorkQueueEntityBroker>();

				WorkQueueSelectCriteria criteria = new WorkQueueSelectCriteria();

				criteria.WorkQueueTypeEnum.In(new[]
				                              	{
				                              		WorkQueueTypeEnum.DeleteStudy, WorkQueueTypeEnum.MigrateStudy,
				                              		WorkQueueTypeEnum.PurgeStudy
				                              	});

				// Do Pending status, in case there's a Failure status entry, we don't want to 
				// block on that.
				criteria.WorkQueueStatusEnum.In(new[] {WorkQueueStatusEnum.Pending, WorkQueueStatusEnum.InProgress});

				FilesystemStudyStorageSelectCriteria filesystemCriteria = new FilesystemStudyStorageSelectCriteria();

				filesystemCriteria.FilesystemKey.EqualTo(item.FilesystemKey);

				criteria.FilesystemStudyStorageRelatedEntityCondition.Exists(filesystemCriteria);
				int count = select.Count(criteria);

				return count;

			}
        }
Esempio n. 14
0
 public int GetRelatedWorkQueueCount(Device device)
 {
     WorkQueueAdaptor workQueueAdaptor = new WorkQueueAdaptor();
     WorkQueueSelectCriteria criteria = new WorkQueueSelectCriteria();
     criteria.DeviceKey.EqualTo(device.Key);
     return workQueueAdaptor.GetCount(criteria);
 }
 public WorkQueueSelectCriteria(WorkQueueSelectCriteria other)
 : base(other)
 {}
Esempio n. 16
0
    	protected override bool CanStart()
        {
            WorkQueueSelectCriteria workQueueCriteria = new WorkQueueSelectCriteria();
            workQueueCriteria.StudyStorageKey.EqualTo(WorkQueueItem.StudyStorageKey);

            IList<Model.WorkQueue> relatedItems = FindRelatedWorkQueueItems(WorkQueueItem,
                                                        new [] { WorkQueueTypeEnum.StudyProcess, WorkQueueTypeEnum.ReconcileStudy },
                                                         new [] { WorkQueueStatusEnum.Idle, WorkQueueStatusEnum.Pending, WorkQueueStatusEnum.InProgress });

            if (! (relatedItems == null || relatedItems.Count == 0))
            {
                // Note, due to GUI restrictions this shouldn't work.  Still reinserting just in case.
                Platform.Log(LogLevel.Info, "Study {0} cannot be deleted at this time because of pending reconciliation. Reinserting into FilesystemQueue", StorageLocation.StudyInstanceUid);
                TimeSpan delay = TimeSpan.FromMinutes(60);
                ReinsertFilesystemQueue(delay);
                PostProcessing(WorkQueueItem, WorkQueueProcessorStatus.Complete, WorkQueueProcessorDatabaseUpdate.ResetQueueState);
                return false;
            }
    		return true;
        }