private void ChangeToSyntax(IBackgroundTaskContext context) { var study = (StudyTableItem)context.UserState; try { _tempPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "ClearCanvas"); _tempPath = System.IO.Path.Combine(_tempPath, "Compression"); _tempPath = System.IO.Path.Combine(_tempPath, Path.GetRandomFileName()); string message = String.Format("Changing transfer syntax to: {0}", _syntax); context.ReportProgress(new BackgroundTaskProgress(0, message)); var loader = study.Server.GetService <IStudyLoader>(); int numberOfSops = loader.Start(new StudyLoaderArgs(study.StudyInstanceUid, null)); if (numberOfSops <= 0) { return; } for (int i = 0; i < numberOfSops; ++i) { Sop sop = loader.LoadNextSop(); if (sop != null) { if (sop.DataSource is ILocalSopDataSource) { string filename = Path.Combine(_tempPath, string.Format("{0}.dcm", i)); DicomFile file = ((ILocalSopDataSource)sop.DataSource).File; file.ChangeTransferSyntax(_syntax); file.Save(filename); } } int progressPercent = (int)Math.Floor((i + 1) / (float)numberOfSops * 100); context.ReportProgress(new BackgroundTaskProgress(progressPercent, message)); } //trigger an import of the anonymized files. var client = new DicomFileImportBridge(); client.ImportFileList(new List <string> { _tempPath }, BadFileBehaviourEnum.Move, FileImportBehaviourEnum.Move); context.Complete(); } catch (Exception e) { context.Error(e); } }
public void Import() { var filePaths = new List <string>(); foreach (string path in this.Context.SelectedPaths) { if (string.IsNullOrEmpty(path)) { continue; } filePaths.Add(path); } if (filePaths.Count == 0) { return; } try { string linkText = SR.LinkOpenActivityMonitor; var importClient = new DicomFileImportBridge(); importClient.ImportFileList(filePaths, BadFileBehaviourEnum.Ignore, FileImportBehaviourEnum.Copy); Context.DesktopWindow.ShowAlert(AlertLevel.Info, string.Format(filePaths.Count > 1 ? SR.MessageFormatImportingFilesPlural : SR.MessageFormatImportingFiles, filePaths.Count), linkText, ActivityMonitorManager.Show, true); } catch (EndpointNotFoundException) { var message = String.Format(SR.FormatMessageImportWorkItemServiceNotRunning, LocalServiceProcess.Name); Context.DesktopWindow.ShowMessageBox(message, MessageBoxActions.Ok); } catch (Exception e) { ExceptionHandler.Report(e, SR.MessageFailedToImportSelection, this.Context.DesktopWindow); } }