Beispiel #1
0
        /// <summary>
        /// Run the service.
        /// </summary>
        protected override void Run()
        {
            while (true)
            {
                if ((_threadPool.QueueCount + _threadPool.ActiveCount) < _threadPool.Concurrency)
                {
                    try
                    {
                        RestoreQueue queueItem = _hsmArchive.GetRestoreCandidate();

                        if (queueItem != null)
                        {
                            HsmStudyRestore archiver = new HsmStudyRestore(_hsmArchive);
                            _threadPool.Enqueue(queueItem, archiver.Run);
                        }
                        else if (CheckStop(HsmSettings.Default.PollDelayMilliseconds))
                        {
                            Platform.Log(LogLevel.Info, "Shutting down {0} restore service.", _hsmArchive.PartitionArchive.Description);
                            return;
                        }
                    }
                    catch (Exception e)
                    {
                        Platform.Log(LogLevel.Error, e, "Unexpected exception when querying for restore candidates.  Rescheduling.");
                        if (CheckStop(HsmSettings.Default.PollDelayMilliseconds))
                        {
                            Platform.Log(LogLevel.Info, "Shutting down {0} restore service.", _hsmArchive.PartitionArchive.Description);
                            return;
                        }
                    }
                }
                else
                {
                    if (CheckStop(HsmSettings.Default.PollDelayMilliseconds))
                    {
                        Platform.Log(LogLevel.Info, "Shutting down {0} restore service.", _hsmArchive.PartitionArchive.Description);
                        return;
                    }
                }
            }
        }
Beispiel #2
0
        private void ProcessStudyFolder(string folder)
        {
            try
            {
                string studyInstanceUid = Path.GetFileName(folder);
                var    location         = new StudyLocation(studyInstanceUid);

                var reprocessStudyFolder = new ReprocessStudyFolder(location);

                _threadPool.Enqueue(reprocessStudyFolder, delegate(ReprocessStudyFolder r)
                {
                    var del = new ThreadPoolStopProxy(r);
                    _threadPool.StartStopStateChangedEvent += del.ProxyDelegate;
                    // TODO (CR Jun 2012): Should check the thread pool state right after
                    // subscribing; otherwise, the folder will process to completion, rather than canceling.

                    r.Process();

                    lock (_syncLock)
                        EventsHelper.Fire(
                            r.Failed ? _studyFailedEvent
                                                                                   : _studyFolderProcessedEvent,
                            this,
                            new StudyEventArgs
                        {
                            StudyInstanceUid = r.Location.Study.StudyInstanceUid,
                            Message          = r.FailureMessage
                        });

                    _threadPool.StartStopStateChangedEvent -= del.ProxyDelegate;
                });
            }
            catch (Exception x)
            {
                // TODO (CR Jun 2012): Shouldn't this cause the work item to fail?
                Platform.Log(LogLevel.Error, x, "Unexpected exception reindexing folder: {0}", folder);
            }
        }