Ejemplo n.º 1
0
 public StreamingStudyLoader(string name) :
     base(name)
 {
     _auditSourceCurrentUser = EventSource.GetUserEventSource(Thread.CurrentPrincipal.Identity.Name);
     InitStrategy();
 }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Main Processing routine.
        /// </summary>
        public override void Process()
        {
            bool stillProcessing = ProcessUidList();

            if (CancelPending)
            {
                Proxy.Cancel();
                return;
            }

            if (StopPending)
            {
                Proxy.Idle();
                return;
            }

            if (!stillProcessing)
            {
                bool failed       = false;
                bool complete     = true;
                bool filesMissing = false;
                foreach (WorkItemUid sop in WorkQueueUidList)
                {
                    if (sop.Failed)
                    {
                        //If any items failed simply because the file doesn't exist, then fail outright.
                        if (!File.Exists(GetFilePath(sop)))
                        {
                            filesMissing = true;
                        }

                        failed = true;
                        break;
                    }

                    if (!sop.Complete)
                    {
                        complete = false;
                        break;
                    }
                }

                DateTime now = Platform.Time;

                if (failed)
                {
                    var failureType = filesMissing ? WorkItemFailureType.Fatal : WorkItemFailureType.NonFatal;
                    Proxy.Fail(failureType);

                    if (Proxy.Item.Status == WorkItemStatusEnum.Failed)
                    {
                        var auditedInstances = new AuditedInstances();

                        auditedInstances.AddInstance(Request.Patient.PatientId, Request.Patient.PatientsName, Request.Study.StudyInstanceUid);

                        AuditHelper.LogImportStudies(auditedInstances,
                                                     string.IsNullOrEmpty(Request.UserName)
                                                         ? EventSource.CurrentProcess
                                                         : EventSource.GetUserEventSource(Request.UserName),
                                                     EventResult.MajorFailure);
                    }
                }
                else if (!complete)
                {
                    Proxy.Idle();
                }
                else if (now > Proxy.Item.ExpirationTime)
                {
                    if (Study == null)
                    {
                        Study = LoadRelatedStudy();
                    }

                    var ruleOptions = new RulesEngineOptions
                    {
                        ApplyDeleteActions = true,
                        ApplyRouteActions  = true
                    };
                    RulesEngine.Create().ApplyStudyRules(Study.ToStoreEntry(), ruleOptions);

                    Proxy.Complete();

                    var auditedInstances = new AuditedInstances();

                    auditedInstances.AddInstance(Request.Patient.PatientId, Request.Patient.PatientsName,
                                                 Request.Study.StudyInstanceUid);

                    AuditHelper.LogImportStudies(auditedInstances,
                                                 string.IsNullOrEmpty(Request.UserName)
                                                     ? EventSource.CurrentProcess
                                                     : EventSource.GetUserEventSource(Request.UserName),
                                                 EventResult.Success);
                }
                else
                {
                    Proxy.Idle();
                }
            }
            else
            {
                Proxy.Idle();
            }
        }