Ejemplo n.º 1
0
		public bool Export()
		{
			if (!Initialize())
				return false;

			EventResult result = EventResult.Success;

			try
			{
				BackgroundTask task = new BackgroundTask(DoExport, true);
				ProgressDialog.Show(task, DesktopWindow, true, ProgressBarStyle.Continuous);
				
				if (_canceled)
					result = EventResult.MinorFailure;

				return !_canceled;
			}
			catch
			{
				result = EventResult.MinorFailure;
				throw;
			}
			finally
			{
				AuditHelper.LogExportStudies(_exportedInstances, EventSource.CurrentUser, result);
			}
		}
Ejemplo n.º 2
0
		public void AnonymizeStudy()
		{
			_component = new AnonymizeStudyComponent(Context.SelectedStudy);
			if (ApplicationComponentExitCode.Accepted == 
				ApplicationComponent.LaunchAsDialog(Context.DesktopWindow, _component, SR.TitleAnonymizeStudy))
			{
                if (LocalStorageMonitor.IsMaxUsedSpaceExceeded)
                {
                    Context.DesktopWindow.ShowMessageBox(SR.MessageCannotAnonymizeMaxDiskUsageExceeded, MessageBoxActions.Ok);
                    return;
                }

				BackgroundTask task = null;
				try
				{
					task = new BackgroundTask(Anonymize, false, Context.SelectedStudy);
					ProgressDialog.Show(task, Context.DesktopWindow, true);
				}
				catch(Exception e)
				{
					Platform.Log(LogLevel.Error, e);
					Context.DesktopWindow.ShowMessageBox(SR.MessageAnonymizeStudyFailed, MessageBoxActions.Ok);
				}
				finally
				{					
					if (task != null)
						task.Dispose();
				}
			}
		}
Ejemplo n.º 3
0
 public ImageServerDbGenerator(ServerPartition partition, DateTime startDate, int totalStudies, int studiesPerDay, int percentWeekend)
 {
     _startDate = startDate;
     _totalStudies = totalStudies;
     _studiesPerDay = studiesPerDay;
     _percentWeekend = percentWeekend;
     _partition = partition;
     _backroundTask = new BackgroundTask(Run, true);
 }
			public static bool Load(StudyFilterComponent component, IDesktopWindow desktopWindow, bool allowCancel, IEnumerable<string> paths, bool recursive)
			{
				bool success = false;

				BackgroundTask task = new BackgroundTask(LoadWorker, allowCancel, new State(component, paths, recursive));
				task.Terminated += delegate(object sender, BackgroundTaskTerminatedEventArgs e) { success = e.Reason == BackgroundTaskTerminatedReason.Completed; };
				ProgressDialog.Show(task, desktopWindow, true, ProgressBarStyle.Continuous);

				return success;
			}
		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);
		}
Ejemplo n.º 6
0
 public ImageServerDbGenerator(string aeTitle, string host, int port, DateTime startDate, int totalStudies, int studiesPerDay, int percentWeekend)
 {
     _startDate = startDate;
     _totalStudies = totalStudies;
     _studiesPerDay = studiesPerDay;
     _percentWeekend = percentWeekend;
     _partition = null;
     _aeTitle = aeTitle;
     _host = host;
     _port = port;
     _backroundTask = new BackgroundTask(Run, true);
 }
        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);
        }
Ejemplo n.º 8
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 Open()
		{
		    var studyLoaders = new List<IStudyLoader>();
			int sopCount = 0;
			foreach (var studyItem in base.Context.SelectedStudies)
			{
                if (!studyItem.Server.IsSupported<IStudyLoader>())
                    return;

			    var loader = studyItem.Server.GetService<IStudyLoader>();
                studyLoaders.Add(loader);
			    sopCount += loader.Start(new StudyLoaderArgs(studyItem.StudyInstanceUid, studyItem.Server));
			}

			bool success = false;
		    var component = new StudyFilterComponent {BulkOperationsMode = true};
		    var task = new BackgroundTask(c =>
			                                         	{
			                                         		c.ReportProgress(new BackgroundTaskProgress(0, sopCount, SR.MessageLoading));
			                                         		if (c.CancelRequested)
			                                         			c.Cancel();

			                                         		int progress = 0;
			                                         		foreach (IStudyLoader localStudyLoader in studyLoaders)
			                                         		{
			                                         			Sop sop;
			                                         			while ((sop = localStudyLoader.LoadNextSop()) != null)
			                                         			{
			                                         				component.Items.Add(new SopDataSourceStudyItem(sop));
																	c.ReportProgress(new BackgroundTaskProgress(Math.Min(sopCount, ++progress) - 1, sopCount, SR.MessageLoading));
			                                         				if (c.CancelRequested)
			                                         					c.Cancel();
			                                         				sop.Dispose();
			                                         			}
			                                         		}

			                                         		success = true;
			                                         		component.Refresh(true);
			                                         		c.Complete();
			                                         	}, true);
			ProgressDialog.Show(task, this.Context.DesktopWindow, true, ProgressBarStyle.Continuous);

			if (success)
			{
				component.BulkOperationsMode = false;
				base.Context.DesktopWindow.Workspaces.AddNew(component, SR.TitleStudyFilters);
			}
		}
Ejemplo n.º 10
0
		/// <summary>
		/// Releases all resources used by this <see cref="ProgressGraphic"/>.
		/// </summary>
		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				_progressProvider = null;
				_synchronizationContext = null;

				if (_updateTask != null)
				{
					_updateTask.RequestCancel();
					_updateTask = null;
				}
			}

			base.Dispose(disposing);
		}
Ejemplo n.º 11
0
        /// <summary>
        /// Creates and executes a new <see cref="BackgroundTask"/> based on the specified arguments.
        /// </summary>
        /// <param name="method">The method to run in the background.</param>
        /// <param name="supportsCancel">Indicates whether the task supports cancellation or not.</param>
        /// <param name="terminateHandler">Method that will be called when the task terminates.</param>
        /// <param name="progressHandler">Optional method to handle progress updates, may be null.</param>
        /// <param name="userState">Optional state to be passed to the background task, may be null.</param>
        /// <returns>A running <see cref="BackgroundTask"/> object.</returns>
        public static BackgroundTask CreateAndRun(
            BackgroundTaskMethod method,
            bool supportsCancel,
            EventHandler <BackgroundTaskTerminatedEventArgs> terminateHandler,
            EventHandler <BackgroundTaskProgressEventArgs> progressHandler,
            object userState)
        {
            Platform.CheckForNullReference(method, "method");
            Platform.CheckForNullReference(terminateHandler, "terminateHandler");

            BackgroundTask task = new BackgroundTask(method, supportsCancel, userState);

            task.Terminated += terminateHandler;
            if (progressHandler != null)
            {
                task.ProgressUpdated += progressHandler;
            }
            task.Run();
            return(task);
        }
			public static bool Load(StudyFilterComponent component, IDesktopWindow desktopWindow, bool allowCancel, IEnumerable<string> paths, bool recursive)
			{
				BackgroundTaskTerminatedEventArgs evArgs = null;

				try
				{
					using (var task = new BackgroundTask(LoadWorker, allowCancel, new State(component, paths, recursive)))
					{
						task.Terminated += (s, e) => evArgs = e;
						ProgressDialog.Show(task, desktopWindow, true, ProgressBarStyle.Continuous);
					}
				}
				catch (Exception ex)
				{
					ExceptionHandler.Report(ex, desktopWindow);
					return false;
				}

				if (evArgs.Reason == BackgroundTaskTerminatedReason.Exception && evArgs.Exception != null)
					ExceptionHandler.Report(evArgs.Exception, desktopWindow);
				return evArgs.Reason == BackgroundTaskTerminatedReason.Completed;
			}
Ejemplo n.º 13
0
		public void ChangeToSyntax(TransferSyntax syntax)
		{
			_syntax = syntax;

			BackgroundTask task = null;
			try
			{
				task = new BackgroundTask(ChangeToSyntax, false, Context.SelectedStudy);
				ProgressDialog.Show(task, this.Context.DesktopWindow, true);
			}
			catch(Exception e)
			{
				Platform.Log(LogLevel.Error, e);
				string message = String.Format("An error occurred while compressing; folder must be deleted manually: {0}", _tempPath);
				this.Context.DesktopWindow.ShowMessageBox(message, MessageBoxActions.Ok);
			}
			finally
			{
				_tempPath = null;

				if (task != null)
					task.Dispose();
			}
		}
 public void SendAnnotations(List<string> annotations)
 {
     if (annotations != null && annotations.Count > 0)
     {
         try
         {
             SynchronizationContext.Post((delegate
             {
                 if (!AimDataServiceLoginTool.CredentialsValid)
                     AimDataServiceLoginTool.RequestLogin();
                 if (AimDataServiceLoginTool.CredentialsValid)
                 {
                     var task = new BackgroundTask(delegate
                     {
                         foreach (string annotation in annotations)
                         {
                             if (annotation != null)
                             {
                                 var result = AimeWebService.Submit(
                                     AimDataServiceLoginTool.Credentials.ApiKey,
                                     annotation);
                                 if (result.Contains("fail"))
                                 {
                                     throw new Exception(result);
                                 }
                             }
                         }
                     },
                     false);
                     task.Run();
                 }
             }), null);
         }
         catch (Exception ex)
         {
             // TODO: Smarter handling of invalid credentials/expiring credentials
             if (ex.Message.Contains("401"))
                 AimDataServiceLoginTool.Credentials = null;
             // AimAnnotationComponents handles the exception from here.
             throw (ex);
         }
     }
 }
Ejemplo n.º 15
0
		/// <summary>
		/// Creates and displays <see cref="ProgressGraphic"/>.
		/// </summary>
		/// <remarks>
		/// This method will invoke each graphic's <see cref="IDrawable.Draw"/> method, so do not call it from a draw routine in the same scene graph!
		/// </remarks>
		/// <param name="task">The <see cref="BackgroundTask"/> to execute. The task is automatically started if it is not already running.</param>
		/// <param name="parentCollections">The graphics collections on which the progress graphic should be shown.</param>
		/// <param name="autoClose">A value indicating whether or not the progress graphic should be automatically removed when the task is terminated.</param>
		/// <param name="progressBarStyle">The style of the progress bar.</param>
		public static void Show(BackgroundTask task, IEnumerable<GraphicCollection> parentCollections, bool autoClose = _defaultAutoClose, ProgressBarGraphicStyle progressBarStyle = _defaultStyle)
		{
			if (!task.IsRunning)
				task.Run();
			var provider = new BackgroundTaskProgressAdapter(task);
			foreach (var parentCollection in parentCollections)
				Show(provider, parentCollection, autoClose, progressBarStyle);
		}
Ejemplo n.º 16
0
        private void Dump()
        {
            if (this.ContextBase is IImageViewerToolContext)
            {
                IImageViewerToolContext context = this.ContextBase as IImageViewerToolContext;
                _desktopWindow = context.DesktopWindow;
                IImageSopProvider image = context.Viewer.SelectedPresentationImage as IImageSopProvider;
                if (image == null)
                {                    
                    _desktopWindow.ShowMessageBox(SR.MessagePleaseSelectAnImage, MessageBoxActions.Ok);
                    return;
                }

            	IDicomMessageSopDataSource dataSource = image.ImageSop.DataSource as IDicomMessageSopDataSource;
				if (dataSource == null || dataSource.SourceMessage ==  null)
				{
					 _desktopWindow.ShowMessageBox(SR.MessageUnknownDataSource, MessageBoxActions.Ok);
					return;
				}

                //Fix for Ticket #623 - HH - It turns out that for memory usage optimization the pixel data tag is stripped from the in memory dataset.  
                //So while there are probably many better ways to address the missing pixel data tag a small hack was introduced because this entire utility will 
                //be completely refactored in the very near future to make use of the methods the pacs uses to parse the tags.
                //Addendum to Comment above - HH 07/27/07 - Turns out that our implementation continues to remove the pixel data for optimization at this time so 
                //the workaround is still needed.
				//Addendum to Comment above - JY 09/16/08 - Somewhere along the line, things were changed that made this line redundant - the only reference to
				//it after this point is at +11 lines or so, and all it does is get file.Filename. Therefore, I am commenting this line out.
                //file = new DicomFile(file.Filename);

                if (_component == null)
                {
                    _component = new DicomEditorComponent();
                }
                else
                {
                    _component.Clear();
                }

                _component.Load(dataSource.SourceMessage);
            }
            else if (this.ContextBase is ILocalImageExplorerToolContext)
            {
                ILocalImageExplorerToolContext context = this.ContextBase as ILocalImageExplorerToolContext;
                _desktopWindow = context.DesktopWindow;
                List<string> files = new List<string>();

                if (context.SelectedPaths.Count == 0)
                    return;

                foreach (string rawPath in context.SelectedPaths)
                {
                	if (string.IsNullOrEmpty(rawPath))
                		continue;

                    FileProcessor.Process(rawPath, "*.*", files.Add, true);
                }

                if (files.Count == 0)
                {
                    context.DesktopWindow.ShowMessageBox(SR.MessageNoFilesSelected, MessageBoxActions.Ok);
                    return;
                }

                if (_component == null)
                {
                    _component = new DicomEditorComponent();
                }
                else
                {
                    _component.Clear();
                }

                bool userCancelled = false;

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

                    foreach (string file in files)
                    {
                        if (backgroundcontext.CancelRequested)
                        {
                            backgroundcontext.Cancel();
                            userCancelled = true;
                            return;
                        }
                        try
                        {
                            _component.Load(file);
                        }
                        catch (DicomException e)
                        {
                            backgroundcontext.Error(e);
                            return;
                        }
                        backgroundcontext.ReportProgress(new BackgroundTaskProgress((int)(((double)(i + 1) / (double)files.Count) * 100.0), SR.MessageDumpProgressBar));
                        i++;
                    }

                    backgroundcontext.Complete(null);
                }, true);

                try
                {
                    ProgressDialog.Show(task, _desktopWindow, true);
                }
                catch (Exception e)
                {
                    ExceptionHandler.Report(e, SR.MessageFailedDump, _desktopWindow);
                    return;
                }

                if (userCancelled == true)
                    return;
            }

            //common to both contexts
            if (_shelf != null)
            {
                _shelf.Activate();
            }
            else
            {
                _shelf = ApplicationComponent.LaunchAsShelf(
                    _desktopWindow,
                    _component,
                    SR.TitleDicomEditor,
                    "Dicom Editor",
                    ShelfDisplayHint.DockRight | ShelfDisplayHint.DockAutoHide);
                _shelf.Closed += OnShelfClosed;
            }
  
            _component.UpdateComponent();

        }
Ejemplo n.º 17
0
 public BackgroundTaskContext(BackgroundTask owner, DoWorkEventArgs doWorkArgs)
 {
     _owner      = owner;
     _doWorkArgs = doWorkArgs;
 }
Ejemplo n.º 18
0
		private void OnVolumeLoaderTaskTerminated(object sender, BackgroundTaskTerminatedEventArgs e)
		{
			BackgroundTask volumeLoaderTask = sender as BackgroundTask;
			if (volumeLoaderTask != null)
			{
				volumeLoaderTask.Terminated -= OnVolumeLoaderTaskTerminated;
				volumeLoaderTask.Dispose();
			}
			_volumeLoaderTask = null;
		}
Ejemplo n.º 19
0
		//TODO (CR Sept 2010): same comment as with the ProgressGraphic stuff; the API is unclear
		//as to what it is doing (return value) because it's trying to account for the async loading.

		/// <summary>
		/// Attempts to start loading the overlay data asynchronously, if not already loaded.
		/// </summary>
		/// <param name="progress">A value between 0 and 1 indicating the progress of the asynchronous loading operation.</param>
		/// <param name="message">A string message detailing the progress of the asynchronous loading operation.</param>
		/// <returns></returns>
		public bool BeginLoad(out float progress, out string message)
		{
			// update the last access time
			_largeObjectData.UpdateLastAccessTime();

			// if the data is already available without blocking, return success immediately

			//TODO (CR Sept 2010): because unloading the volume involves disposing it, if every operation that uses it
			//isn't in the same lock (e.g. lock(_syncVolumeDataLock)) you could be getting a disposed/null volume here.
			VolumeData volume = _volume;
			if (volume != null)
			{
				message = SR.MessageFusionComplete;
				progress = 1f;
				return true;
			}

			lock (_syncLoaderLock)
			{
				message = SR.MessageFusionInProgress;
				progress = 0;
				if (_volumeLoaderTask == null)
				{
					// if the data is available now, return success
					volume = _volume;
					if (volume != null)
					{
						message = SR.MessageFusionComplete;
						progress = 1f;
						return true;
					}

					_volumeLoaderTask = new BackgroundTask(c => this.LoadVolume(c), false, null) {ThreadUICulture = Application.CurrentUICulture};
					_volumeLoaderTask.Run();
					_volumeLoaderTask.Terminated += OnVolumeLoaderTaskTerminated;
				}
				else
				{
					if (_volumeLoaderTask.LastBackgroundTaskProgress != null)
					{
						message = _volumeLoaderTask.LastBackgroundTaskProgress.Progress.Message;
						progress = _volumeLoaderTask.LastBackgroundTaskProgress.Progress.Percent/100f;
					}
				}
			}
			return false;
		}
Ejemplo n.º 20
0
		public void Export(string path) {
			BackgroundTask task = new BackgroundTask(
				delegate {
					_studyBuilder.Publish(path);
				}, false);

			ProgressDialog.Show(task, base.Host.DesktopWindow, true, ProgressBarStyle.Marquee);
		}
Ejemplo n.º 21
0
 public BackgroundTaskContext(BackgroundTask owner, DoWorkEventArgs doWorkArgs)
 {
     _owner = owner;
     _doWorkArgs = doWorkArgs;
 }
Ejemplo n.º 22
0
        private void MoveFolders(SortableResultList<ScanResultEntry> list)
        {
            progressBar1.Minimum = 0;
            progressBar1.Maximum = 100;
            progressBar1.Value = 0;
            _moveFolderBackgroundTask = new BackgroundTask(DoMoveFolderAsync, true, list);
            _moveFolderBackgroundTask.ProgressUpdated += delegate(object sender, BackgroundTaskProgressEventArgs ev)
                                                             {
                                                                 progressBar1.Value = ev.Progress.Percent;
                                                             };

            _moveFolderBackgroundTask.Terminated += delegate
                                                        {
                                                            progressBar1.Value = 0;
                                                            MoveFolderButton.Text = "Move Folders";
                                                            MoveFolderButton.Enabled = true;
                                                        };

            MoveFolderButton.Text = "Stop";
            _moveFolderBackgroundTask.Run();
        }
			public void Run()
			{
				CreateBaseDataSet();
				
				_tempFileDirectory = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "ClearCanvas");
				_tempFileDirectory = System.IO.Path.Combine(_tempFileDirectory, "BitmapImport");
				DeleteEmptyFolders(_tempFileDirectory);

				_tempFileDirectory = System.IO.Path.Combine(_tempFileDirectory, System.IO.Path.GetRandomFileName());
				Directory.CreateDirectory(_tempFileDirectory);

				BackgroundTask task = new BackgroundTask(Process, true);
				task.Terminated += delegate
									{
										OnComplete();
										task.Dispose();
									};

				lock (_waitShowProgressLock)
				{
					task.Run();

					Monitor.Wait(_waitShowProgressLock);
					if (_showProgress)
					{
						ProgressDialogComponent progressComponent = new ProgressDialogComponent(task, true, ProgressBarStyle.Blocks);
						LaunchAsShelf(DesktopWindow, progressComponent, SR.TitleImportingImages, ShelfDisplayHint.DockFloat);
					}

					Monitor.Pulse(_waitShowProgressLock);
				}
			}
Ejemplo n.º 24
0
		/// <summary>
		/// Creates and displays a <see cref="ProgressGraphic"/>.
		/// </summary>
		/// <remarks>
		/// This method will invoke the graphic's <see cref="IDrawable.Draw"/> method, so do not call it from a draw routine in the same scene graph!
		/// </remarks>
		/// <param name="task">The <see cref="BackgroundTask"/> to execute. The task is automatically started if it is not already running.</param>
		/// <param name="parentCollection">The graphics collection on which the progress graphic should be shown.</param>
		/// <param name="autoClose">A value indicating whether or not the progress graphic should be automatically removed when the task is terminated.</param>
		/// <param name="progressBarStyle">The style of the progress bar.</param>
		public static void Show(BackgroundTask task, GraphicCollection parentCollection, bool autoClose = _defaultAutoClose, ProgressBarGraphicStyle progressBarStyle = _defaultStyle)
		{
			if (!task.IsRunning)
				task.Run();
			Show(new BackgroundTaskProgressAdapter(task), parentCollection, autoClose, progressBarStyle);
		}
Ejemplo n.º 25
0
		public void PublishToServer()
		{
			AENavigatorComponent aeNavigator = new AENavigatorComponent();
			aeNavigator.IsReadOnly = true;
			aeNavigator.ShowCheckBoxes = false;
			aeNavigator.ShowLocalDataStoreNode = false;
			aeNavigator.ShowTitlebar = false;
			aeNavigator.ShowTools = false;

			SimpleComponentContainer dialogContainer = new SimpleComponentContainer(aeNavigator);
			DialogBoxAction code = this.Host.DesktopWindow.ShowDialogBox(dialogContainer, SR.SelectDestination );

			if (code != DialogBoxAction.Ok)
				return;

			if (aeNavigator.SelectedServers == null || aeNavigator.SelectedServers.Servers == null || aeNavigator.SelectedServers.Servers.Count == 0) {
				return;
			}

			if (aeNavigator.SelectedServers.Servers.Count < 1) {
				return;
			}

			BackgroundTask task = new BackgroundTask(
				delegate {
					foreach (Server destinationAE in aeNavigator.SelectedServers.Servers) {
						_studyBuilder.Publish(ServerTree.GetClientAETitle(), destinationAE.AETitle, destinationAE.Host, destinationAE.Port);
					}
				}, false);

			ProgressDialog.Show(task, base.Host.DesktopWindow, true, ProgressBarStyle.Marquee);
		}
Ejemplo n.º 26
0
		public void PublishToLocalDataStore()
		{
			try {
				DicomServerConfigurationHelper.Refresh(true);
				string aeTitle = DicomServerConfigurationHelper.AETitle;
				int port = DicomServerConfigurationHelper.Port;

				BackgroundTask task = new BackgroundTask(
					delegate {
						_studyBuilder.Publish(aeTitle, aeTitle, IPAddress.Loopback.ToString(), port);
						}, false);

				ProgressDialog.Show(task, base.Host.DesktopWindow, true, ProgressBarStyle.Marquee);
			} catch (Exception e) {
				ExceptionHandler.Report(e, SR.ExceptionLocalDataStoreNotFound , base.Host.DesktopWindow);
			}
		}
Ejemplo n.º 27
0
			public void Run()
			{
				if (NumberOfImagesToExport <= 5)
				{
					BlockingOperation.Run(delegate { Export(null); });
					Complete();
				}
				else
				{
					ItemsToExport.ForEach(delegate(IClipboardItem item) { item.Lock(); });

					BackgroundTask task = new BackgroundTask(Export, true) {ThreadUICulture = Application.CurrentUICulture};

					ProgressDialogComponent progressComponent = new ProgressDialogComponent(task, true, ProgressBarStyle.Blocks);

					_progressComponentShelf = LaunchAsShelf(DesktopWindow, progressComponent,
																SR.TitleExportingImages, "ExportingImages",
																ShelfDisplayHint.DockFloat);

					_progressComponentShelf.Closed += delegate
														{
															Complete();
															task.Dispose();
														};
				}
			}
        void send_series(string studyUid, string seriesUid)
        {
            AEInformation destination = get_server();
            if (destination != null)
            {

                BackgroundTask task = new BackgroundTask(
                    delegate(IBackgroundTaskContext context)
                    {
                        DicomSendServiceClient sender = new DicomSendServiceClient();
                        sender.Open();
                        SendSeriesRequest series_request = new SendSeriesRequest();
                        series_request.DestinationAEInformation = destination;
                        series_request.StudyInstanceUid = studyUid;
                        List<string> seriesUids = new List<string>();
                        seriesUids.Add(seriesUid);
                        series_request.SeriesInstanceUids = seriesUids;
                        sender.SendSeries(series_request);
                        sender.Close();
                    }, true);

                task.Run();

                LocalDataStoreActivityMonitorComponentManager.ShowSendReceiveActivityComponent(this.Context.DesktopWindow);

            }
        }
Ejemplo n.º 29
0
		public void LaunchMpr()
		{
			Exception exception = null;

			IPresentationImage currentImage = this.Context.Viewer.SelectedPresentationImage;
			if (currentImage == null)
				return;

			// gather the source frames which MPR will operate on. exceptions are reported.
			BackgroundTaskParams @params;
			try
			{
				@params = new BackgroundTaskParams(FilterSourceFrames(currentImage.ParentDisplaySet, currentImage));
			}
			catch (Exception ex)
			{
				ExceptionHandler.Report(ex, SR.ExceptionMprLoadFailure, base.Context.DesktopWindow);
				return;
			}

			// execute the task to create an MPR component. exceptions (either thrown or passed via task) are reported, but any created component must be disposed
			BackgroundTask task = new BackgroundTask(LoadVolume, true, @params);
			task.Terminated += (sender, e) => exception = e.Exception;
			try
			{
				ProgressDialog.Show(task, base.Context.DesktopWindow, true, ProgressBarStyle.Blocks);
			}
			catch (Exception ex)
			{
				exception = ex;
				if (_viewer != null)
				{
					_viewer.Dispose();
					_viewer = null;
				}
			}
			finally
			{
				task.Dispose();
			}

			if (exception != null)
			{
				ExceptionHandler.Report(exception, SR.ExceptionMprLoadFailure, base.Context.DesktopWindow);
				return;
			}

			// launch the created MPR component as a workspace. any exceptions here are just reported.
			try
			{
				LaunchImageViewerArgs args = new LaunchImageViewerArgs(ViewerLaunchSettings.WindowBehaviour);
				args.Title = _viewer.Title;
				MprViewerComponent.Launch(_viewer, args);
			}
			catch (Exception ex)
			{
				ExceptionHandler.Report(ex, SR.ExceptionMprLoadFailure, base.Context.DesktopWindow);
			}
			finally
			{
				_viewer = null;
			}
		}
Ejemplo n.º 30
0
        public void StartAsync()
        {
            ScanResultSet = new ScanResultSet();
            LoadDeletedStudies();
            LoadSIQEntries(); 
            
            _worker = new BackgroundTask(StartScaning, true, this);
            _worker.ProgressUpdated += WorkerProgressUpdated;
            _worker.Terminated += WorkerTerminated;
            _worker.Run();

        }
Ejemplo n.º 31
0
        /// <summary>
        /// Creates and executes a new <see cref="BackgroundTask"/> based on the specified arguments.
        /// </summary>
        /// <param name="method">The method to run in the background.</param>
        /// <param name="supportsCancel">Indicates whether the task supports cancellation or not.</param>
        /// <param name="terminateHandler">Method that will be called when the task terminates.</param>
        /// <param name="progressHandler">Optional method to handle progress updates, may be null.</param>
        /// <param name="userState">Optional state to be passed to the background task, may be null.</param>
        /// <returns>A running <see cref="BackgroundTask"/> object.</returns>
        public static BackgroundTask CreateAndRun(
            BackgroundTaskMethod method,
            bool supportsCancel,
            EventHandler<BackgroundTaskTerminatedEventArgs> terminateHandler,
            EventHandler<BackgroundTaskProgressEventArgs> progressHandler,
            object userState)
        {
            Platform.CheckForNullReference(method, "method");
            Platform.CheckForNullReference(terminateHandler, "terminateHandler");

            BackgroundTask task = new BackgroundTask(method, supportsCancel, userState);
            task.Terminated += terminateHandler;
            if (progressHandler != null)
            {
                task.ProgressUpdated += progressHandler;
            }
            task.Run();
            return task;
        }
Ejemplo n.º 32
0
			public BackgroundTaskProgressAdapter(BackgroundTask backgroundTask)
			{
				_backgroundTask = backgroundTask;
			}