Example #1
0
        private void ImportFile(string file, ImportStudyContext context)
        {
            // Note, we're not doing impersonation of the user's identity, so we may have failures here
            // which would be new in Marmot.
            try
            {
                EnsureMaxUsedSpaceNotExceeded();

                var dicomFile = new DicomFile(file);

                DicomReadOptions readOptions = Request.FileImportBehaviour == FileImportBehaviourEnum.Save
                                                   ? DicomReadOptions.Default
                                                   : DicomReadOptions.Default | DicomReadOptions.StorePixelDataReferences;

                dicomFile.Load(readOptions);

                var importer = new ImportFilesUtility(context);

                DicomProcessingResult result = importer.Import(dicomFile, Request.BadFileBehaviour, Request.FileImportBehaviour);

                if (result.DicomStatus == DicomStatuses.Success)
                {
                    Progress.NumberOfFilesImported++;
                }
                else
                {
                    Progress.NumberOfImportFailures++;
                    Progress.StatusDetails = result.ErrorMessage;
                }
            }
            catch (NotEnoughStorageException)
            {
                Progress.NumberOfImportFailures++;
                Progress.StatusDetails = SR.ExceptionNotEnoughStorage;
                context.FatalError     = true;
            }
            catch (Exception e)
            {
                Platform.Log(LogLevel.Warn, "Unable to import DICOM File ({0}): {1}", file, e.Message);
                Progress.NumberOfImportFailures++;
                Progress.StatusDetails = string.Format("{0}: {1}", file, e.Message);
            }
        }
        // Essentially this is a copy of ClearCanvas.ImageViewer.StudyManagement.Core.DicomFilePublisher that allows us to move files
        // instead of leaving them orphaned in the original folder.
        // TODO: revisit this when ClearCanvas.ImageViewer.StudyManagement.Core.DicomFilePublisher gets an option for moving files
        public static void PublishLocal(ICollection <DicomFile> files)
        {
            if (files == null || files.Count == 0)
            {
                return;
            }

            var configuration = ClearCanvas.ImageViewer.Common.DicomServer.DicomServer.GetConfiguration();
            var context       = new ImportStudyContext(configuration.AETitle, StudyStore.GetConfiguration(), EventSource.CurrentUser);

            var utility = new ImportFilesUtility(context);

            try
            {
                DicomProcessingResult failureResult = null;

                foreach (var file in files)
                {
                    var importResult = utility.Import(file, BadFileBehaviourEnum.Move, FileImportBehaviourEnum.Move);                     // THIS IS THE CHANGE
                    if (importResult.DicomStatus != DicomStatuses.Success)
                    {
                        Platform.Log(LogLevel.Warn, "Unable to import published file: {0}", importResult.ErrorMessage);
                        failureResult = importResult;
                    }
                }

                if (failureResult != null)
                {
                    throw new ApplicationException(failureResult.ErrorMessage);
                }
            }
            catch (Exception ex)
            {
                var message = String.Format("Failed to import files");
                throw new Exception(message, ex);
            }
        }
Example #3
0
        private bool ImportFiles(IList <string> filePaths,
                                 IEnumerable <string> fileExtensions,
                                 bool recursive)
        {
            var configuration = GetServerConfiguration();

            var context = new ImportStudyContext(configuration.AETitle, StudyStore.GetConfiguration(), string.IsNullOrEmpty(Request.UserName) ? EventSource.CurrentProcess : EventSource.GetUserEventSource(Request.UserName));

            // Publish the creation of the StudyImport WorkItems
            lock (context.StudyWorkItemsSyncLock)
            {
                context.StudyWorkItems.ItemAdded += (sender, args) => Platform.GetService(
                    (IWorkItemActivityMonitorService service) =>
                    service.Publish(new WorkItemPublishRequest {
                    Item = WorkItemDataHelper.FromWorkItem(args.Item)
                }));
                context.StudyWorkItems.ItemChanged += (sender, args) => Platform.GetService(
                    (IWorkItemActivityMonitorService service) =>
                    service.Publish(new WorkItemPublishRequest {
                    Item = WorkItemDataHelper.FromWorkItem(args.Item)
                }));
            }

            var extensions = new List <string>();

            if (fileExtensions != null)
            {
                foreach (string extension in fileExtensions)
                {
                    if (String.IsNullOrEmpty(extension))
                    {
                        continue;
                    }

                    extensions.Add(extension);
                }
            }

            Progress.PathsToImport = filePaths.Count;

            bool completedEnumeration = true;

            foreach (string path in filePaths)
            {
                FileProcessor.Process(path, string.Empty,
                                      delegate(string file, out bool cancel)
                {
                    cancel = false;

                    if (CancelPending || StopPending || context.FatalError)
                    {
                        cancel = true;
                        return;
                    }

                    bool enqueue = false;
                    foreach (string extension in extensions)
                    {
                        if (file.EndsWith(extension))
                        {
                            enqueue = true;
                            break;
                        }
                    }

                    enqueue = enqueue || extensions.Count == 0;

                    if (enqueue)
                    {
                        ++Progress.TotalFilesToImport;

                        Proxy.UpdateProgress();

                        ImportFile(file, context);
                    }
                }, recursive);

                Progress.PathsImported++;
                Proxy.UpdateProgress();

                if (CancelPending || StopPending || context.FatalError)
                {
                    completedEnumeration = false;
                }
            }

            Progress.CompletedEnumeration = completedEnumeration;

            return(context.FatalError);
        }