Ejemplo n.º 1
0
        /// <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);
            }
        }
        protected override void OnExecute(CommandProcessor theProcessor, IUpdateContext updateContext)
        {
            // update FilesystemStudyStorage
            if (Context != null)
            {
                Platform.Log(LogLevel.Info, "Updating database...");
                IFilesystemStudyStorageEntityBroker broker = updateContext.GetBroker <IFilesystemStudyStorageEntityBroker>();

                FilesystemStudyStorageSelectCriteria searchCriteria = new FilesystemStudyStorageSelectCriteria();
                searchCriteria.StudyStorageKey.EqualTo(Context.OriginalStudyLocation.GetKey());
                searchCriteria.FilesystemKey.EqualTo(Context.OriginalStudyLocation.FilesystemKey);
                FilesystemStudyStorage filesystemStudyStorage = broker.FindOne(searchCriteria);
                Debug.Assert(filesystemStudyStorage != null);

                // Update Filesystem for the StudyStorage entry
                filesystemStudyStorage.FilesystemKey = Context.Destination.Filesystem.GetKey();
                broker.Update(filesystemStudyStorage);


                // Update Filesystem for the remaining FilesystemQueue entries
                IFilesystemQueueEntityBroker  fsQueueBroker         = updateContext.GetBroker <IFilesystemQueueEntityBroker>();
                FilesystemQueueSelectCriteria fsQueueSearchCriteria = new FilesystemQueueSelectCriteria();
                fsQueueSearchCriteria.StudyStorageKey.EqualTo(Context.OriginalStudyLocation.GetKey());
                fsQueueSearchCriteria.FilesystemKey.EqualTo(Context.OriginalStudyLocation.FilesystemKey);

                FilesystemQueueUpdateColumns fsQueueUpdateColumns = new FilesystemQueueUpdateColumns();
                fsQueueUpdateColumns.FilesystemKey = Context.Destination.Filesystem.GetKey();
                fsQueueBroker.Update(fsQueueSearchCriteria, fsQueueUpdateColumns);

                // Insert or update Filesystem Queue table.
                IInsertFilesystemQueue          insertFilesystemQueueBroker = updateContext.GetBroker <IInsertFilesystemQueue>();
                FilesystemQueueInsertParameters parms = new FilesystemQueueInsertParameters();
                parms.FilesystemKey           = Context.Destination.Filesystem.GetKey();
                parms.FilesystemQueueTypeEnum = FilesystemQueueTypeEnum.TierMigrate;
                parms.ScheduledTime           = Platform.Time;
                parms.StudyStorageKey         = Context.OriginalStudyLocation.GetKey();
                insertFilesystemQueueBroker.Execute(parms);

                Platform.Log(LogLevel.Info, "Database is updated.");
            }
        }
Ejemplo n.º 3
0
        protected override void OnExecute(CommandProcessor theProcessor, IUpdateContext updateContext)
        {
            // Check if the File is the same syntax as the
            TransferSyntax fileSyntax = _file.TransferSyntax;
            TransferSyntax dbSyntax   = TransferSyntax.GetTransferSyntax(_location.TransferSyntaxUid);

            // Check if the syntaxes match the location
            if ((!fileSyntax.Encapsulated && !dbSyntax.Encapsulated) ||
                (fileSyntax.LosslessCompressed && dbSyntax.LosslessCompressed) ||
                (fileSyntax.LossyCompressed && dbSyntax.LossyCompressed))
            {
                // no changes necessary, just return;
                return;
            }

            // Select the Server Transfer Syntax
            var syntaxCriteria = new ServerTransferSyntaxSelectCriteria();
            var syntaxBroker   = updateContext.GetBroker <IServerTransferSyntaxEntityBroker>();

            syntaxCriteria.Uid.EqualTo(fileSyntax.UidString);

            ServerTransferSyntax serverSyntax = syntaxBroker.FindOne(syntaxCriteria);

            if (serverSyntax == null)
            {
                Platform.Log(LogLevel.Error, "Unable to load ServerTransferSyntax for {0}.  Unable to update study status.", fileSyntax.Name);
                return;
            }

            // Get the FilesystemStudyStorage update broker ready
            var filesystemStudyStorageEntityBroker = updateContext.GetBroker <IFilesystemStudyStorageEntityBroker>();
            var filesystemStorageUpdate            = new FilesystemStudyStorageUpdateColumns();
            var filesystemStorageCritiera          = new FilesystemStudyStorageSelectCriteria();

            filesystemStorageUpdate.ServerTransferSyntaxKey = serverSyntax.Key;
            filesystemStorageCritiera.StudyStorageKey.EqualTo(_location.Key);

            // Get the StudyStorage update broker ready
            var studyStorageBroker =
                updateContext.GetBroker <IStudyStorageEntityBroker>();
            var             studyStorageUpdate = new StudyStorageUpdateColumns();
            StudyStatusEnum statusEnum         = _location.StudyStatusEnum;

            if (fileSyntax.LossyCompressed)
            {
                studyStorageUpdate.StudyStatusEnum = statusEnum = StudyStatusEnum.OnlineLossy;
            }
            else if (fileSyntax.LosslessCompressed)
            {
                studyStorageUpdate.StudyStatusEnum = statusEnum = StudyStatusEnum.OnlineLossless;
            }

            studyStorageUpdate.LastAccessedTime = Platform.Time;

            if (!filesystemStudyStorageEntityBroker.Update(filesystemStorageCritiera, filesystemStorageUpdate))
            {
                Platform.Log(LogLevel.Error, "Unable to update FilesystemQueue row: Study {0}, Server Entity {1}",
                             _location.StudyInstanceUid, _location.ServerPartitionKey);
            }
            else if (!studyStorageBroker.Update(_location.GetKey(), studyStorageUpdate))
            {
                Platform.Log(LogLevel.Error, "Unable to update StudyStorage row: Study {0}, Server Entity {1}",
                             _location.StudyInstanceUid, _location.ServerPartitionKey);
            }
            else
            {
                // Update the location, so the next time we come in here, we don't try and update the database
                // for another sop in the study.
                _location.StudyStatusEnum         = statusEnum;
                _location.TransferSyntaxUid       = fileSyntax.UidString;
                _location.ServerTransferSyntaxKey = serverSyntax.Key;
            }
        }