public static void Create(IDesktopWindow desktopWindow, IImageViewer viewer)
		{
			IDisplaySet selectedDisplaySet = viewer.SelectedImageBox.DisplaySet;
			string name = String.Format("{0} - Dynamic TE", selectedDisplaySet.Name);
			IDisplaySet t2DisplaySet = new DisplaySet(name, "");

			double currentSliceLocation = 0.0;

			BackgroundTask task = new BackgroundTask(
				delegate(IBackgroundTaskContext context)
				{
					int i = 0;

					foreach (IPresentationImage image in selectedDisplaySet.PresentationImages)
					{
						IImageSopProvider imageSopProvider = image as IImageSopProvider;

						if (imageSopProvider == null)
							continue;

						ImageSop imageSop = imageSopProvider.ImageSop;
						Frame frame = imageSopProvider.Frame;

						if (frame.SliceLocation != currentSliceLocation)
						{
							currentSliceLocation = frame.SliceLocation;

							try
							{
								DynamicTePresentationImage t2Image = CreateT2Image(imageSop, frame);
								t2DisplaySet.PresentationImages.Add(t2Image);
							}
							catch (Exception e)
							{
								Platform.Log(LogLevel.Error, e);
								desktopWindow.ShowMessageBox("Unable to create T2 series.  Please check the log for details.",
								                             MessageBoxActions.Ok);
								break;
							}

						}

						string message = String.Format("Processing {0} of {1} images", i, selectedDisplaySet.PresentationImages.Count);
						i++;

						BackgroundTaskProgress progress = new BackgroundTaskProgress(i, selectedDisplaySet.PresentationImages.Count, message);
						context.ReportProgress(progress);
					}
				}, false);

			ProgressDialog.Show(task, desktopWindow, true, ProgressBarStyle.Blocks);

			viewer.LogicalWorkspace.ImageSets[0].DisplaySets.Add(t2DisplaySet);
		}
        protected void RetrieveAnnotationsFromAimService(object[] searchResults)
        {
            string errorMsg = null;
            BackgroundTask task = new BackgroundTask(
                delegate(IBackgroundTaskContext context)
                {
                    try
                    {
                        int cnt = 0;
                        BackgroundTaskProgress progress;
                        List<string> tmpAnnotations = new List<string>();
                        aim_dotnet.DcmModel dcmModel = new aim_dotnet.DcmModel();
                        foreach (AIMSearchResult result in searchResults)
                        {
                            cnt++;

                            if (result.RetrievedAnnotation == null)
                                continue;

                            progress = new BackgroundTaskProgress(cnt, searchResults.Length + 1, "Saving Annotation " + cnt);
                            context.ReportProgress(progress);

                            string tmpFileName = System.IO.Path.GetTempFileName();
                            dcmModel.WriteAnnotationToFile(result.RetrievedAnnotation, tmpFileName);
                            tmpAnnotations.Add(tmpFileName);
                        }
                        dcmModel = null;

                        if (tmpAnnotations.Count > 0)
                        {
                            progress = new BackgroundTaskProgress(searchResults.Length, searchResults.Length + 1, "Importing Annotations");
                            context.ReportProgress(progress);

                            this.ImportDicomFiles(tmpAnnotations);
                        }
                    }
                    catch (Exception ex)
                    {
                        errorMsg = ex.Message;
                        Platform.Log(LogLevel.Error, ex, "Failed to import annotation(s)");
                    }

                    context.Complete(null);

                }, true);

            ProgressDialog.Show(task, this.Context.DesktopWindow, true, ProgressBarStyle.Blocks);

            if (!string.IsNullOrEmpty(errorMsg))
                this.Context.DesktopWindow.ShowMessageBox(errorMsg, MessageBoxActions.Ok);
        }
Exemple #3
0
			public void Load(string[] files, IDesktopWindow desktop, out bool cancelled)
			{
				Platform.CheckForNullReference(files, "files");

				_total = 0;
				_failed = 0;

				bool userCancelled = false;

				if (desktop != null)
				{
					BackgroundTask task = new BackgroundTask(
						delegate(IBackgroundTaskContext context)
						{
							for (int i = 0; i < files.Length; i++)
							{
								LoadSop(files[i]);

								int percentComplete = (int)(((float)(i + 1) / files.Length) * 100);
								string message = String.Format(SR.MessageFormatOpeningImages, i, files.Length);

								BackgroundTaskProgress progress = new BackgroundTaskProgress(percentComplete, message);
								context.ReportProgress(progress);

								if (context.CancelRequested)
								{
									userCancelled = true;
									break;
								}
							}

							context.Complete(null);

						}, true);

					ProgressDialog.Show(task, desktop, true, ProgressBarStyle.Blocks);
					cancelled = userCancelled;
				}
				else
				{
					foreach (string file in files)
						LoadSop(file);

					cancelled = false;
				}

				if (Failed > 0)
					throw new LoadSopsException(Total, Failed);
			}
 public void ReportProgress(BackgroundTaskProgress progress)
 {
     _owner._backgroundWorker.ReportProgress(0, progress);
 }
		/// <summary>
		/// Constructor.
		/// </summary>
        internal BackgroundTaskProgressEventArgs(object userState, BackgroundTaskProgress progress)
        {
            _userState = userState;
            _progress = progress;
        }
Exemple #6
0
		private void DoExport(IBackgroundTaskContext context)
		{
			try
			{
				int i = 0;
				int fileCount = _files.Count;

				foreach (string filename in _files)
				{
					string message = String.Format(SR.MessageFormatExportingFiles, i + 1, fileCount);
					BackgroundTaskProgress progress = new BackgroundTaskProgress(i, fileCount, message);
					context.ReportProgress(progress);

					SaveFile(filename);
					
					if (_canceled || context.CancelRequested)
					{
						_canceled = true;
						context.Cancel();
						return;
					}

					i++;
				}

				context.Complete();
			}
			catch (Exception e)
			{
				context.Error(e);
			}
		}
 public void ReportProgress(BackgroundTaskProgress progress)
 {
     _owner._backgroundWorker.ReportProgress(0, progress);
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 internal BackgroundTaskProgressEventArgs(object userState, BackgroundTaskProgress progress)
 {
     _userState = userState;
     _progress  = progress;
 }
			public void ReportProgress(BackgroundTaskProgress progress)
			{
			}