public void OnStudyDeleting() { if (!Enabled) { return; } StudyStorageLocation storage = _context.StorageLocation; IList <ArchiveStudyStorage> archives = StudyStorageLocation.GetArchiveLocations(storage.GetKey()); if (archives != null && archives.Count > 0) { _archives = new DeletedStudyArchiveInfoCollection(); foreach (ArchiveStudyStorage archive in archives) { DeletedStudyArchiveInfo archiveInfo = new DeletedStudyArchiveInfo(); archiveInfo.ArchiveTime = archive.ArchiveTime; archiveInfo.ArchiveXml = archive.ArchiveXml; archiveInfo.PartitionArchiveRef = PartitionArchive.Load(archive.PartitionArchiveKey).GetKey().Key; archiveInfo.TransferSyntaxUid = archive.ServerTransferSyntax.Uid; _archives.Add(archiveInfo); } } // only backup if study is manually deleted if (_context.WorkQueueItem.WorkQueueTypeEnum == WorkQueueTypeEnum.WebDeleteStudy) { using (var processor = new ServerCommandProcessor("Backup deleted study")) { string path = _context.Filesystem.ResolveAbsolutePath(BackupSubPath); Platform.Log(LogLevel.Info, "Saving a copy of the study to {0}...", path); var mkdir = new CreateDirectoryCommand(path); processor.AddCommand(mkdir); var zip = new ZipStudyFolderCommand(storage.GetStudyPath(), BackupFullPath); processor.AddCommand(zip); if (!processor.Execute()) { throw new ApplicationException(String.Format("Unable to backup study: {0}", processor.FailureReason)); } } } }
/// <summary> /// Check the currently configured archives and plugins to see if any have been disabled. /// </summary> private void CheckConfiguredArchives() { IList <ServerPartition> partitionList = LoadPartitions(); lock (_syncLock) { IList <PartitionArchiveService> partitionsToDelete = new List <PartitionArchiveService>(); foreach (PartitionArchiveService archiveService in _archiveServiceList) { archiveService.PartitionArchive = PartitionArchive.Load(archiveService.PartitionArchive.GetKey()); if (!archiveService.PartitionArchive.Enabled) { Platform.Log(LogLevel.Info, "PartitionArchive {0} has been disabled, stopping plugin.", archiveService.PartitionArchive.Description); archiveService.ArchivePlugin.Stop(); partitionsToDelete.Add(archiveService); } else { bool bFound = false; foreach (ServerPartition serverPartition in partitionList) { if (serverPartition.GetKey().Equals(archiveService.ServerPartition.GetKey()) && serverPartition.Enabled) { bFound = true; break; } } if (!bFound) { Platform.Log(LogLevel.Info, "Partition was deleted or disabled, shutting down archive server {0}", archiveService.ServerPartition.Description); archiveService.ArchivePlugin.Stop(); partitionsToDelete.Add(archiveService); } } } // Remove the services from our internal list. foreach (PartitionArchiveService archivePlugin in partitionsToDelete) { _archiveServiceList.Remove(archivePlugin); } // Load the current extension list ImageServerArchiveExtensionPoint ep = new ImageServerArchiveExtensionPoint(); ExtensionInfo[] extensionInfoList = ep.ListExtensions(); // Scan the current list of enabled partition archives to see if any // new archives have been added foreach (PartitionArchive partitionArchive in LoadEnabledPartitionArchives()) { ServerPartition newPartition = ServerPartition.Load(partitionArchive.ServerPartitionKey); if (!newPartition.Enabled) { continue; } bool bFound = false; foreach (PartitionArchiveService service in _archiveServiceList) { if (!partitionArchive.GetKey().Equals(service.PartitionArchive.GetKey())) { continue; } // Reset the context partition, incase its changed. service.PartitionArchive = partitionArchive; bFound = true; break; } if (!bFound) { // No match, scan the current extensions for a matching extension // to run the service foreach (ExtensionInfo extensionInfo in extensionInfoList) { IImageServerArchivePlugin archive = (IImageServerArchivePlugin)ep.CreateExtension(new ClassNameExtensionFilter(extensionInfo.FormalName)); if (archive.ArchiveType.Equals(partitionArchive.ArchiveTypeEnum)) { PartitionArchiveService service = new PartitionArchiveService(archive, partitionArchive, newPartition); Platform.Log(LogLevel.Info, "Detected PartitionArchive was added, starting archive {0}", partitionArchive.Description); service.ArchivePlugin.Start(partitionArchive); _archiveServiceList.Add(service); break; } } } } } }