private PartitionArchive SelectPartitionArchive(StudyItem study) { using (var ctx = PersistentStoreRegistry.GetDefaultStore().OpenReadContext()) { var partitionArchiveBroker = ctx.GetBroker <IPartitionArchiveEntityBroker>(); var partitionArchiveCriteria = new PartitionArchiveSelectCriteria(); partitionArchiveCriteria.ServerPartitionKey.EqualTo(study.StudyStorage.ServerPartitionKey); return(partitionArchiveBroker.Find(partitionArchiveCriteria).FirstOrDefault()); } }
private void Purge(StudyItem study) { Task.Factory.StartNew(() => { var archive = SelectPartitionArchive(study); if (archive == null) { MessageBox.Show("Please add an archive in the partition where this study is located"); return; } if (study.IsArchivingScheduled()) { if ( MessageBox.Show( "This study is scheduled in the Archive Queue. Do you want to remove it from the queue before purging?", "Study is scheduled for archiving", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { using (var processor = new ServerCommandProcessor("archive")) { processor.AddCommand(new DeleteAllArchiveQueueItemCommand(study.StudyStorage, archive)); processor.Execute(); } } } if (study.StudyStorageLocation.ArchiveLocations == null || !study.StudyStorageLocation.ArchiveLocations.Any()) { var i = 0; using (var processor = new ServerCommandProcessor("archive")) { var archiveCommand = new ArchiveStudyCommand(study.StudyStorageLocation, GetArchivePath(archive), @"C:\temp", archive); archiveCommand.ProgressUpdated += (s, e) => { study.OperationProgress = new OperationProgress() { Status = e.Percentage == 100 ? "Archived" : e.Status, Percentage = (int)e.Percentage }; }; processor.AddCommand(archiveCommand); if (!processor.Execute()) { MessageBox.Show(string.Format("Unable to archive study: {0}", processor.FailureException.Message)); } } } using (var processor = new ServerCommandProcessor("archive")) { processor.AddCommand(new PurgeStudyCommand(study.StudyStorage)); if (!processor.Execute()) { MessageBox.Show(string.Format("Unable to purge study: {0}", processor.FailureException.Message)); } else { MessageBox.Show("Study has been succesfully purged"); study.Status = "Nearline"; } } }); }