public InsertFilesystemQueueCommand(FilesystemQueueTypeEnum queueType, ServerEntityKey filesystemKey,
                                     ServerEntityKey studyStorageKey, DateTime scheduledTime, XmlDocument queueXml)
     : base("Insert FilesystemQueue Record of type " + queueType)
 {
     _queueType = queueType;
     _filesystemKey = filesystemKey;
     _studyStorageKey = studyStorageKey;
     _scheduledTime = scheduledTime;
 	_queueXml = queueXml;
 }
 public FilesystemQueue(
      FilesystemQueueTypeEnum _filesystemQueueTypeEnum_
     ,ServerEntityKey _studyStorageKey_
     ,ServerEntityKey _filesystemKey_
     ,DateTime _scheduledTime_
     ,String _seriesInstanceUid_
     ,XmlDocument _queueXml_
     ):base("FilesystemQueue")
 {
     FilesystemQueueTypeEnum = _filesystemQueueTypeEnum_;
     StudyStorageKey = _studyStorageKey_;
     FilesystemKey = _filesystemKey_;
     ScheduledTime = _scheduledTime_;
     SeriesInstanceUid = _seriesInstanceUid_;
     QueueXml = _queueXml_;
 }
Example #3
0
 public FilesystemQueue(
     FilesystemQueueTypeEnum _filesystemQueueTypeEnum_
     , ServerEntityKey _studyStorageKey_
     , ServerEntityKey _filesystemKey_
     , DateTime _scheduledTime_
     , String _seriesInstanceUid_
     , XmlDocument _queueXml_
     ) : base("FilesystemQueue")
 {
     FilesystemQueueTypeEnum = _filesystemQueueTypeEnum_;
     StudyStorageKey         = _studyStorageKey_;
     FilesystemKey           = _filesystemKey_;
     ScheduledTime           = _scheduledTime_;
     SeriesInstanceUid       = _seriesInstanceUid_;
     QueueXml = _queueXml_;
 }
		/// <summary>
		/// Get a list of candidates from the <see cref="FilesystemQueue"/>.
		/// </summary>
		/// <param name="item">The ServiceLock item.</param>
		/// <param name="scheduledTime">The scheduled time to query against</param>
		/// <param name="type">The type of FilesystemQueue entry.</param>
		/// <param name="statusCheck">If true, check for specific status value WorkQueue entries already existing, otherwise check for any WorkQueue entry.</param>
		/// <returns>The list of queue entries.</returns>
        protected IList<FilesystemQueue> GetFilesystemQueueCandidates(Model.ServiceLock item, DateTime scheduledTime, FilesystemQueueTypeEnum type, bool statusCheck)
        {
			using (ServerExecutionContext context = new ServerExecutionContext())
			{
				IFilesystemQueueEntityBroker broker = context.ReadContext.GetBroker<IFilesystemQueueEntityBroker>();
				FilesystemQueueSelectCriteria fsQueueCriteria = new FilesystemQueueSelectCriteria();

				fsQueueCriteria.FilesystemKey.EqualTo(item.FilesystemKey);
				fsQueueCriteria.ScheduledTime.LessThanOrEqualTo(scheduledTime);
				fsQueueCriteria.FilesystemQueueTypeEnum.EqualTo(type);

				// Do the select based on the QueueStudyState (used to be based on a link to the WorkQueue table)
				StudyStorageSelectCriteria studyStorageSearchCriteria = new StudyStorageSelectCriteria();
				studyStorageSearchCriteria.QueueStudyStateEnum.EqualTo(QueueStudyStateEnum.Idle);
				fsQueueCriteria.StudyStorage.Exists(studyStorageSearchCriteria);

				fsQueueCriteria.ScheduledTime.SortAsc(0);

				IList<FilesystemQueue> list = broker.Find(fsQueueCriteria, 0, ServiceLockSettings.Default.FilesystemQueueResultCount);

				return list;
			}
        }
		/// <summary>
		/// Process StudyDelete Candidates retrieved from the <see cref="Model.FilesystemQueue"/> table
		/// </summary>
		/// <param name="candidateList">The list of candidate studies for deleting.</param>
		/// <param name="type">The type of compress.</param>
		private void ProcessCompressCandidates(IEnumerable<FilesystemQueue> candidateList, FilesystemQueueTypeEnum type)
		{
			DateTime scheduledTime = Platform.Time.AddSeconds(10);

			foreach (FilesystemQueue queueItem in candidateList)
			{
				// Check for Shutdown/Cancel
				if (CancelPending) break;

				// First, get the StudyStorage locations for the study, and calculate the disk usage.
				StudyStorageLocation location;
				if (!FilesystemMonitor.Instance.GetWritableStudyStorageLocation(queueItem.StudyStorageKey, out location))
					continue;

				// Get the disk usage
				StudyXml studyXml = LoadStudyXml(location);

				using (IUpdateContext update = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
				{
					ILockStudy lockstudy = update.GetBroker<ILockStudy>();
					LockStudyParameters lockParms = new LockStudyParameters();
					lockParms.StudyStorageKey = location.Key;
					lockParms.QueueStudyStateEnum = QueueStudyStateEnum.CompressScheduled;
					if (!lockstudy.Execute(lockParms) || !lockParms.Successful)
					{
						Platform.Log(LogLevel.Warn, "Unable to lock study for inserting Lossy Compress, skipping study ({0}",
									 location.StudyInstanceUid);
						continue;
					}

					scheduledTime = scheduledTime.AddSeconds(3);

					IInsertWorkQueueFromFilesystemQueue workQueueInsert = update.GetBroker<IInsertWorkQueueFromFilesystemQueue>();

					InsertWorkQueueFromFilesystemQueueParameters insertParms = new InsertWorkQueueFromFilesystemQueueParameters();
				    insertParms.WorkQueueTypeEnum = WorkQueueTypeEnum.CompressStudy;
					insertParms.FilesystemQueueTypeEnum = FilesystemQueueTypeEnum.LossyCompress;
					insertParms.StudyStorageKey = location.GetKey();
					insertParms.ServerPartitionKey = location.ServerPartitionKey;
					DateTime expirationTime = scheduledTime;
					insertParms.ScheduledTime = expirationTime;
					insertParms.DeleteFilesystemQueue = true;
					insertParms.Data = queueItem.QueueXml;
					insertParms.WorkQueueTypeEnum = WorkQueueTypeEnum.CompressStudy;
					insertParms.FilesystemQueueTypeEnum = type;
					
					try
					{
						WorkQueue entry = workQueueInsert.FindOne(insertParms);

						InsertWorkQueueUidFromStudyXml(studyXml,update,entry.GetKey());

						update.Commit();
						_studiesInserted++;
					}
					catch(Exception e) 
					{
						Platform.Log(LogLevel.Error, e, "Unexpected problem inserting 'CompressStudy' record into WorkQueue for Study {0}", location.StudyInstanceUid);
						// throw; -- would cause abort of inserts, go ahead and try everything
					}
				}
			}
		}