protected override void OnExecute(CommandProcessor theProcessor, IUpdateContext updateContext) { // Update StudyStatusEnum in the StudyStorageTable IStudyStorageEntityBroker studyStorageUpdate = updateContext.GetBroker<IStudyStorageEntityBroker>(); StudyStorageUpdateColumns studyStorageUpdateColumns = new StudyStorageUpdateColumns(); studyStorageUpdateColumns.StudyStatusEnum = _newStatus; studyStorageUpdate.Update(_location.Key, studyStorageUpdateColumns); // Update ServerTransferSyntaxGUID in FilesystemStudyStorage IFilesystemStudyStorageEntityBroker filesystemUpdate = updateContext.GetBroker<IFilesystemStudyStorageEntityBroker>(); FilesystemStudyStorageUpdateColumns filesystemUpdateColumns = new FilesystemStudyStorageUpdateColumns(); filesystemUpdateColumns.ServerTransferSyntaxKey = _newSyntax.Key; filesystemUpdate.Update(_location.FilesystemStudyStorageKey, filesystemUpdateColumns); }
/// <summary> /// Updates the status of a study to a new status /// </summary> protected virtual void UpdateStudyStatus(StudyStorageLocation theStudyStorage, StudyStatusEnum theStatus, TransferSyntax theSyntax) { DBUpdateTime.Add( delegate { using ( IUpdateContext updateContext = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush)) { // Select the Server Transfer Syntax ServerTransferSyntaxSelectCriteria syntaxCriteria = new ServerTransferSyntaxSelectCriteria(); IServerTransferSyntaxEntityBroker syntaxBroker = updateContext.GetBroker<IServerTransferSyntaxEntityBroker>(); syntaxCriteria.Uid.EqualTo(theSyntax.UidString); ServerTransferSyntax serverSyntax = syntaxBroker.FindOne(syntaxCriteria); if (serverSyntax == null) { Platform.Log(LogLevel.Error, "Unable to load ServerTransferSyntax for {0}. Unable to update study status.", theSyntax.Name); return; } // Get the FilesystemStudyStorage update broker ready IFilesystemStudyStorageEntityBroker filesystemQueueBroker = updateContext.GetBroker<IFilesystemStudyStorageEntityBroker>(); FilesystemStudyStorageUpdateColumns filesystemQueueUpdate = new FilesystemStudyStorageUpdateColumns { ServerTransferSyntaxKey = serverSyntax.GetKey() }; FilesystemStudyStorageSelectCriteria filesystemQueueCriteria = new FilesystemStudyStorageSelectCriteria(); filesystemQueueCriteria.StudyStorageKey.EqualTo(theStudyStorage.GetKey()); // Get the StudyStorage update broker ready IStudyStorageEntityBroker studyStorageBroker = updateContext.GetBroker<IStudyStorageEntityBroker>(); StudyStorageUpdateColumns studyStorageUpdate = new StudyStorageUpdateColumns { StudyStatusEnum = theStatus, LastAccessedTime = Platform.Time }; if (!filesystemQueueBroker.Update(filesystemQueueCriteria,filesystemQueueUpdate)) { Platform.Log(LogLevel.Error, "Unable to update FilesystemQueue row: Study {0}, Server Entity {1}", theStudyStorage.StudyInstanceUid, theStudyStorage.ServerPartitionKey); } else if (!studyStorageBroker.Update(theStudyStorage.GetKey(),studyStorageUpdate)) { Platform.Log(LogLevel.Error, "Unable to update StudyStorage row: Study {0}, Server Entity {1}", theStudyStorage.StudyInstanceUid, theStudyStorage.ServerPartitionKey); } else updateContext.Commit(); } } ); }
static public StudyStorage Insert(IUpdateContext update, StudyStorage entity) { var broker = update.GetBroker<IStudyStorageEntityBroker>(); var updateColumns = new StudyStorageUpdateColumns(); updateColumns.ServerPartitionKey = entity.ServerPartitionKey; updateColumns.StudyInstanceUid = entity.StudyInstanceUid; updateColumns.InsertTime = entity.InsertTime; updateColumns.LastAccessedTime = entity.LastAccessedTime; updateColumns.WriteLock = entity.WriteLock; updateColumns.ReadLock = entity.ReadLock; updateColumns.StudyStatusEnum = entity.StudyStatusEnum; updateColumns.QueueStudyStateEnum = entity.QueueStudyStateEnum; StudyStorage newEntity = broker.Insert(updateColumns); return newEntity; }
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); // Save a StudyHistory record for the compression that occurred. StudyHistoryHelper.CreateStudyHistoryRecord(updateContext, _location, _location, StudyHistoryTypeEnum.SopCompress, null, new CompressionStudyHistory { TimeStamp = Platform.Time, OriginalTransferSyntaxUid = dbSyntax.UidString, FinalTransferSyntaxUid = fileSyntax.UidString }); // 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; } }