Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
0
        private void DoImport(IBackgroundTaskContext context)
        {
            int lineCount = 0;
            int batch     = 0;

            try
            {
                lineCount = PrescanFile();

                using (StreamReader reader = File.OpenText(_filename))
                {
                    // treat as csv
                    List <string> lines = null;
                    while ((lines = ReadLines(reader, _batchSize)).Count > 0)
                    {
                        if (context.CancelRequested)
                        {
                            break;
                        }

                        try
                        {
                            Platform.GetService <IImportService>(
                                delegate(IImportService service)
                            {
                                service.ImportCsv(new ImportCsvRequest(_importType, lines));
                            });
                        }
                        catch (FaultException <ImportException> e)
                        {
                            // unwrap the fault exception
                            throw e.Detail;
                        }

                        UpdateProgress(context, "Importing", batch++, lineCount);
                    }
                }

                if (context.CancelRequested)
                {
                    UpdateProgress(context, "Cancelled", batch, lineCount);
                    context.Cancel();
                }
                else
                {
                    UpdateProgress(context, "Completed", batch, lineCount);
                    context.Complete(null);
                }
            }
            catch (Exception e)
            {
                UpdateProgress(context, "Error", batch, lineCount);
                context.Error(e);
            }
        }
Ejemplo n.º 3
0
        private void Go(IBackgroundTaskContext context)
        {
            string studyUid  = DicomUid.GenerateUid().UID;
            string seriesUid = DicomUid.GenerateUid().UID;

            PixelAspectRatioChanger changer =
                new PixelAspectRatioChanger
            {
                IncreasePixelDimensions = _component.IncreasePixelDimensions,
                NewAspectRatio          = new PixelAspectRatio(_component.AspectRatioRow, _component.AspectRatioColumn),
                RemoveCalibration       = _component.RemoveCalibration
            };

            int i = 0;

            context.ReportProgress(new BackgroundTaskProgress(i, _dicomFileNames.Count, "Exporting ..."));

            try
            {
                foreach (string originalFile in _dicomFileNames)
                {
                    var file = new DicomFile(originalFile);
                    file.Load(DicomReadOptions.None);

                    string sopInstanceUid = DicomUid.GenerateUid().UID;

                    file.DataSet[DicomTags.StudyInstanceUid].SetStringValue(studyUid);
                    file.DataSet[DicomTags.SeriesInstanceUid].SetStringValue(seriesUid);
                    file.DataSet[DicomTags.SopInstanceUid].SetStringValue(sopInstanceUid);

                    changer.ChangeAspectRatio(file);

                    string outputFileName = Path.Combine(_outputDirectory, String.Format("{0}.dcm", sopInstanceUid));
                    file.Save(outputFileName);

                    if (context.CancelRequested)
                    {
                        context.Cancel();
                        return;
                    }

                    context.ReportProgress(new BackgroundTaskProgress(++i, _dicomFileNames.Count + 1, "Exporting ..."));
                }
            }
            catch (Exception e)
            {
                context.Error(e);
                return;
            }

            context.Complete();
        }
Ejemplo n.º 4
0
        private void LoadVolume(IBackgroundTaskContext context)
        {
            try
            {
                ProgressTask mainTask = new ProgressTask();
                mainTask.AddSubTask("BUILD", 90);
                mainTask.AddSubTask("LAYOUT", 10);

                context.ReportProgress(new BackgroundTaskProgress(mainTask.IntPercent, string.Format(SR.MessageInitializingMpr, mainTask.Progress)));

                BackgroundTaskParams @params = (BackgroundTaskParams)context.UserState;
                Volume volume = Volume.Create(@params.Frames,
                                              delegate(int i, int count)
                {
                    if (context.CancelRequested)
                    {
                        throw new BackgroundTaskCancelledException();
                    }
                    if (i == 0)
                    {
                        mainTask["BUILD"].AddSubTask("", count);
                    }
                    mainTask["BUILD"][""].Increment();
                    string message = string.Format(SR.MessageBuildingMprVolumeProgress, mainTask.Progress, i + 1, count, mainTask["BUILD"].Progress);
                    context.ReportProgress(new BackgroundTaskProgress(mainTask.IntPercent, message));
                });

                mainTask["BUILD"].MarkComplete();
                context.ReportProgress(new BackgroundTaskProgress(mainTask.IntPercent, string.Format(SR.MessagePerformingMprWorkspaceLayout, mainTask.Progress)));

                //call layout here b/c it could take a while
                @params.SynchronizationContext.Send(delegate
                {
                    _viewer = new MprViewerComponent(volume);
                    _viewer.Layout();
                }, null);

                mainTask["LAYOUT"].MarkComplete();
                context.ReportProgress(new BackgroundTaskProgress(mainTask.IntPercent, string.Format(SR.MessageDone, mainTask.Progress)));

                context.Complete();
            }
            catch (BackgroundTaskCancelledException)
            {
                context.Cancel();
            }
            catch (Exception ex)
            {
                context.Error(ex);
            }
        }
Ejemplo n.º 5
0
            private static void LoadWorker(IBackgroundTaskContext context)
            {
                State state = context.UserState as State;

                if (state == null)
                {
                    context.Cancel();
                    return;
                }

                context.ReportProgress(new BackgroundTaskProgress(0, 1000, SR.MessageLoading));
                if (context.CancelRequested)
                {
                    context.Cancel();
                    return;
                }

                List <string> fileList = new List <string>();

                try
                {
                    foreach (string path in state.Paths)
                    {
                        fileList.AddRange(EnumerateFiles(path, state.Recursive));
                    }
                }
                catch (Exception ex)
                {
                    context.Error(ex);
                    return;
                }

                for (int n = 0; n < fileList.Count; n++)
                {
                    context.ReportProgress(new BackgroundTaskProgress(n, fileList.Count, SR.MessageLoading));
                    if (context.CancelRequested)
                    {
                        context.Cancel();
                        return;
                    }
                    state.SynchronizationContext.Send(i => state.Component.Load(fileList[(int)i]), n);
                }

                if (context.CancelRequested)
                {
                    context.Cancel();
                    return;
                }

                context.Complete();
            }
        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);
            }
        }
        private void BackgroundSendAnnotationsToAimService(IBackgroundTaskContext context)
        {
            var xmlAnnotations = context.UserState as Dictionary <string, string>;

            try
            {
                if (xmlAnnotations != null && xmlAnnotations.Count > 0)
                {
                    var progress = new BackgroundTaskProgress(20, string.Format("Sending {0} annotation(s) to AIM data service.", xmlAnnotations.Count));
                    context.ReportProgress(progress);
                    AIMTCGAService.AIMTCGASubmit.sendAIMTCGAAnnotation(new List <string>(xmlAnnotations.Values).ToArray());
                }
                context.Complete();
            }
            catch (Exception ex)
            {
                SaveAnnotationsToQueue(xmlAnnotations, AIMTCGAService.AIMTCGASubmit.ServiceUrl);
                context.Error(ex);
            }
        }
Ejemplo n.º 8
0
        private void Anonymize(IBackgroundTaskContext context)
        {
            //TODO (Marmot) This probably should be its own WorkItem type and have it done in the background there.
            var study = (StudyTableItem)context.UserState;
            var anonymizedInstances = new AuditedInstances();

            try
            {
                context.ReportProgress(new BackgroundTaskProgress(0, SR.MessageAnonymizingStudy));

                var loader       = study.Server.GetService <IStudyLoader>();
                int numberOfSops = loader.Start(new StudyLoaderArgs(study.StudyInstanceUid, null));
                if (numberOfSops <= 0)
                {
                    return;
                }

                var anonymizer = new DicomAnonymizer {
                    StudyDataPrototype = _component.AnonymizedData
                };

                if (_component.PreserveSeriesData)
                {
                    //The default anonymizer removes the series data, so we just clone the original.
                    anonymizer.AnonymizeSeriesDataDelegate = original => original.Clone();
                }

                // Setup the ImportFilesUtility to perform the import
                var configuration = DicomServer.GetConfiguration();

                // setup auditing information
                var result = EventResult.Success;

                string patientsSex = null;

                for (int i = 0; i < numberOfSops; ++i)
                {
                    using (var sop = loader.LoadNextSop())
                    {
                        if (sop != null &&
                            (_component.KeepReportsAndAttachments || !IsReportOrAttachmentSopClass(sop.SopClassUid)))
                        {
                            //preserve the patient sex.
                            if (patientsSex == null)
                            {
                                anonymizer.StudyDataPrototype.PatientsSex = patientsSex = sop.PatientsSex ?? "";
                            }

                            var localSopDataSource = sop.DataSource as ILocalSopDataSource;
                            if (localSopDataSource != null)
                            {
                                string    filename = string.Format("{0}.dcm", i);
                                DicomFile file     = (localSopDataSource).File;

                                // make sure we anonymize a new instance, not the same instance that the Sop cache holds!!
                                file = new DicomFile(filename, file.MetaInfo.Copy(), file.DataSet.Copy());
                                anonymizer.Anonymize(file);

                                // TODO (CR Jun 2012): Importing each file separately?
                                Platform.GetService((IPublishFiles w) => w.PublishLocal(new List <DicomFile> {
                                    file
                                }));

                                string studyInstanceUid = file.DataSet[DicomTags.StudyInstanceUid].ToString();
                                string patientId        = file.DataSet[DicomTags.PatientId].ToString();
                                string patientsName     = file.DataSet[DicomTags.PatientsName].ToString();
                                anonymizedInstances.AddInstance(patientId, patientsName, studyInstanceUid);

                                var progressPercent = (int)Math.Floor((i + 1) / (float)numberOfSops * 100);
                                var progressMessage = String.Format(SR.MessageAnonymizingStudy, file.MediaStorageSopInstanceUid);
                                context.ReportProgress(new BackgroundTaskProgress(progressPercent, progressMessage));
                            }
                        }
                    }
                }

                AuditHelper.LogCreateInstances(new[] { configuration.AETitle }, anonymizedInstances, EventSource.CurrentUser, result);

                context.Complete();
            }
            catch (Exception e)
            {
                AuditHelper.LogCreateInstances(new[] { string.Empty }, anonymizedInstances, EventSource.CurrentUser, EventResult.MajorFailure);
                context.Error(e);
            }
        }
Ejemplo n.º 9
0
        private void Anonymize(IBackgroundTaskContext context)
        {
            //TODO (Marmot) This probably should be its own WorkItem type and have it done in the background there.
            var study = (StudyTableItem) context.UserState;
            var anonymizedInstances = new AuditedInstances();

            try
            {

                context.ReportProgress(new BackgroundTaskProgress(0, SR.MessageAnonymizingStudy));

                var loader = study.Server.GetService<IStudyLoader>();
                int numberOfSops = loader.Start(new StudyLoaderArgs(study.StudyInstanceUid, null));
                if (numberOfSops <= 0)
                    return;

                var anonymizer = new DicomAnonymizer {StudyDataPrototype = _component.AnonymizedData};

                if (_component.PreserveSeriesData)
                {
                    //The default anonymizer removes the series data, so we just clone the original.
                    anonymizer.AnonymizeSeriesDataDelegate = original => original.Clone();
                }

                // Setup the ImportFilesUtility to perform the import
                var configuration = DicomServer.GetConfiguration();

                // setup auditing information
                var result = EventResult.Success;

                string patientsSex = null;

                for (int i = 0; i < numberOfSops; ++i)
                {
                    using (var sop = loader.LoadNextSop())
                    {
                        if (sop != null &&
                            (_component.KeepReportsAndAttachments || !IsReportOrAttachmentSopClass(sop.SopClassUid)))
                        {
                            //preserve the patient sex.
                            if (patientsSex == null)
                                anonymizer.StudyDataPrototype.PatientsSex = patientsSex = sop.PatientsSex ?? "";

                            var localSopDataSource = sop.DataSource as ILocalSopDataSource;
                            if (localSopDataSource != null)
                            {
                                string filename = string.Format("{0}.dcm", i);
                                DicomFile file = (localSopDataSource).File;

                                // make sure we anonymize a new instance, not the same instance that the Sop cache holds!!
                                file = new DicomFile(filename, file.MetaInfo.Copy(), file.DataSet.Copy());
                                anonymizer.Anonymize(file);

                                // TODO (CR Jun 2012): Importing each file separately?
                                Platform.GetService((IPublishFiles w) => w.PublishLocal(new List<DicomFile> {file}));

                                string studyInstanceUid = file.DataSet[DicomTags.StudyInstanceUid].ToString();
                                string patientId = file.DataSet[DicomTags.PatientId].ToString();
                                string patientsName = file.DataSet[DicomTags.PatientsName].ToString();
                                anonymizedInstances.AddInstance(patientId, patientsName, studyInstanceUid);

                                var progressPercent = (int)Math.Floor((i + 1) / (float)numberOfSops * 100);
                                var progressMessage = String.Format(SR.MessageAnonymizingStudy, file.MediaStorageSopInstanceUid);
                                context.ReportProgress(new BackgroundTaskProgress(progressPercent, progressMessage));
                            }
                        }
                    }                 
                }

                AuditHelper.LogCreateInstances(new[]{configuration.AETitle}, anonymizedInstances, EventSource.CurrentUser, result);

                context.Complete();
            }
            catch (Exception e)
            {
                AuditHelper.LogCreateInstances(new[] { string.Empty }, anonymizedInstances, EventSource.CurrentUser, EventResult.MajorFailure);
                context.Error(e);
            }
        }
Ejemplo n.º 10
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);
			}
		}
Ejemplo n.º 11
0
		private void LoadVolume(IBackgroundTaskContext context)
		{
			try
			{
				ProgressTask mainTask = new ProgressTask();
				mainTask.AddSubTask("BUILD", 90);
				mainTask.AddSubTask("LAYOUT", 10);

				context.ReportProgress(new BackgroundTaskProgress(mainTask.IntPercent, string.Format(SR.MessageInitializingMpr, mainTask.Progress)));

				BackgroundTaskParams @params = (BackgroundTaskParams) context.UserState;
				Volume volume = Volume.Create(@params.Frames,
				                                    delegate(int i, int count)
				                                    	{
				                                    		if (context.CancelRequested)
				                                    			throw new BackgroundTaskCancelledException();
				                                    		if (i == 0)
				                                    			mainTask["BUILD"].AddSubTask("", count);
				                                    		mainTask["BUILD"][""].Increment();
				                                    		string message = string.Format(SR.MessageBuildingMprVolumeProgress, mainTask.Progress, i + 1, count, mainTask["BUILD"].Progress);
				                                    		context.ReportProgress(new BackgroundTaskProgress(mainTask.IntPercent, message));
				                                    	});

				mainTask["BUILD"].MarkComplete();
				context.ReportProgress(new BackgroundTaskProgress(mainTask.IntPercent, string.Format(SR.MessagePerformingMprWorkspaceLayout, mainTask.Progress)));

				//call layout here b/c it could take a while
				@params.SynchronizationContext.Send(delegate
				                                    	{
															_viewer = new MprViewerComponent(volume);
															_viewer.Layout();
				                                    	}, null);

				mainTask["LAYOUT"].MarkComplete();
				context.ReportProgress(new BackgroundTaskProgress(mainTask.IntPercent, string.Format(SR.MessageDone, mainTask.Progress)));

				context.Complete();
			}
			catch (BackgroundTaskCancelledException)
			{
				context.Cancel();
			}
			catch (Exception ex)
			{
				context.Error(ex);
			}
		}
		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, StudyLoaderOptions.Default));
				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);
			}
		}
Ejemplo n.º 13
0
        private void Rename(IBackgroundTaskContext context)
        {
            try
            {
                _tempPath = String.Format(".\\temp\\{0}", Path.GetRandomFileName());
                Directory.CreateDirectory(_tempPath);
                _tempPath = Path.GetFullPath(_tempPath);

                context.ReportProgress(new BackgroundTaskProgress(0, "Renaming Study"));

                int numberOfSops = LocalStudyLoader.Start(new StudyLoaderArgs(this.Context.SelectedStudy.StudyInstanceUid, null));
                if (numberOfSops <= 0)
                {
                    return;
                }

                for (int i = 0; i < numberOfSops; ++i)
                {
                    string message = String.Format("{0} of {1}", i.ToString(), numberOfSops.ToString());
                    Platform.Log(LogLevel.Info, message);

                    Sop sop = LocalStudyLoader.LoadNextSop();
                    ILocalSopDataSource localsource = (ILocalSopDataSource)sop.DataSource;
                    string    progressMessage       = localsource.Filename.ToString();
                    DicomFile file = ((ILocalSopDataSource)sop.DataSource).File;

                    //renamer.Anonymize(file);

                    StudyData originalData = new StudyData();
                    file.DataSet.LoadDicomFields(originalData);

                    originalData.PatientId         = _component.PatientId;
                    originalData.PatientsBirthDate = _component.PatientsBirthDate;
                    originalData.PatientsNameRaw   = _component.PatientsName;
                    originalData.AccessionNumber   = _component.AccessionNumber;
                    originalData.StudyDate         = _component.StudyDate;
                    originalData.StudyDescription  = _component.StudyDescription;

                    file.DataSet.SaveDicomFields(originalData);

                    file.Save(String.Format("{0}\\{1}.dcm", _tempPath, i));

                    int progressPercent = (int)Math.Floor((i + 1) / (float)numberOfSops * 100);
                    //string progressMessage = String.Format(SR.MessageAnonymizingStudy, _tempPath);

                    context.ReportProgress(new BackgroundTaskProgress(progressPercent, progressMessage));

                    // This code deletes the study from the database, so that when it is re-imported the changed fields
                    // will appear
                }


                using (IDataStoreStudyRemover studyRemover = DataAccessLayer.GetIDataStoreStudyRemover())
                {
                    studyRemover.RemoveStudy(this.Context.SelectedStudy.StudyInstanceUid);
                }

                //trigger an import of the Renamed files.
                LocalDataStoreServiceClient client = new LocalDataStoreServiceClient();
                client.Open();
                try
                {
                    FileImportRequest request = new FileImportRequest();
                    request.BadFileBehaviour    = BadFileBehaviour.Move;
                    request.FileImportBehaviour = FileImportBehaviour.Move;
                    List <string> filePaths = new List <string>();
                    filePaths.Add(_tempPath);
                    request.FilePaths = filePaths;
                    request.Recursive = true;
                    client.Import(request);
                    client.Close();

                    //  Need to refresh study list in order for changed values to appear
                    //  This method doesn't work.  Need to manually click 'Search' again
                    //this.Context.RefreshStudyList();
                }
                catch
                {
                    client.Abort();
                    throw;
                }
                //this.Context.RefreshStudyList();
                context.Complete();
            }
            catch (Exception e)
            {
                context.Error(e);
            }
        }
		private void Go(IBackgroundTaskContext context)
		{
			string studyUid = DicomUid.GenerateUid().UID;
			string seriesUid = DicomUid.GenerateUid().UID;

			PixelAspectRatioChanger changer = 
				new PixelAspectRatioChanger
              	{
              		IncreasePixelDimensions = _component.IncreasePixelDimensions,
              		NewAspectRatio = new PixelAspectRatio(_component.AspectRatioRow, _component.AspectRatioColumn),
              		RemoveCalibration = _component.RemoveCalibration
              	};

			int i = 0;
			context.ReportProgress(new BackgroundTaskProgress(i, _dicomFileNames.Count, "Exporting ..."));

			try
			{
				foreach (string originalFile in _dicomFileNames)
				{
					var file = new DicomFile(originalFile);
					file.Load(DicomReadOptions.None);

					string sopInstanceUid = DicomUid.GenerateUid().UID;

					file.DataSet[DicomTags.StudyInstanceUid].SetStringValue(studyUid);
					file.DataSet[DicomTags.SeriesInstanceUid].SetStringValue(seriesUid);
					file.DataSet[DicomTags.SopInstanceUid].SetStringValue(sopInstanceUid);

					changer.ChangeAspectRatio(file);

					string outputFileName = Path.Combine(_outputDirectory, String.Format("{0}.dcm", sopInstanceUid));
					file.Save(outputFileName);

					if (context.CancelRequested)
					{
						context.Cancel();
						return;
					}

					context.ReportProgress(new BackgroundTaskProgress(++i, _dicomFileNames.Count + 1, "Exporting ..."));
				}
			}
			catch (Exception e)
			{
				context.Error(e);
				return;
			}

			context.Complete();
		}
			private static void LoadWorker(IBackgroundTaskContext context)
			{
				State state = context.UserState as State;
				if (state == null)
				{
					context.Cancel();
					return;
				}

				context.ReportProgress(new BackgroundTaskProgress(0, 1000, SR.MessageLoading));
				if (context.CancelRequested)
				{
					context.Cancel();
					return;
				}

				List<string> fileList = new List<string>();
				try
				{
					foreach (string path in state.Paths)
						fileList.AddRange(EnumerateFiles(path, state.Recursive));
				}
				catch (Exception ex)
				{
					context.Error(ex);
					return;
				}

				for (int n = 0; n < fileList.Count; n++)
				{
					context.ReportProgress(new BackgroundTaskProgress(n, fileList.Count, SR.MessageLoading));
					if (context.CancelRequested)
					{
						context.Cancel();
						return;
					}
					state.SynchronizationContext.Send(i => state.Component.Load(fileList[(int) i]), n);
				}

				if (context.CancelRequested)
				{
					context.Cancel();
					return;
				}

				context.Complete();
			}