Beispiel #1
0
        public void Initialize()
        {
            //we want to tell examine to use a different fs lock instead of the default NativeFSFileLock which could cause problems if the AppDomain
            //terminates and in some rare cases would only allow unlocking of the file if IIS is forcefully terminated. Instead we'll rely on the simplefslock
            //which simply checks the existence of the lock file
            DirectoryFactory.DefaultLockFactory = d =>
            {
                var simpleFsLockFactory = new NoPrefixSimpleFsLockFactory(d);
                return(simpleFsLockFactory);
            };

            //let's deal with shutting down Examine with MainDom
            var examineShutdownRegistered = _mainDom.Register(() =>
            {
                using (_logger.TraceDuration <ExamineComponent>("Examine shutting down"))
                {
                    _examineManager.Dispose();
                }
            });

            if (!examineShutdownRegistered)
            {
                _logger.Debug <ExamineComponent>("Examine shutdown not registered, this AppDomain is not the MainDom, Examine will be disabled");

                //if we could not register the shutdown examine ourselves, it means we are not maindom! in this case all of examine should be disabled!
                Suspendable.ExamineEvents.SuspendIndexers(_logger);
                _disableExamineIndexing = true;
                return; //exit, do not continue
            }

            //create the indexes and register them with the manager
            foreach (var index in _indexCreator.Create())
            {
                _examineManager.AddIndex(index);
            }

            _logger.Debug <ExamineComponent>("Examine shutdown registered with MainDom");

            var registeredIndexers = _examineManager.Indexes.OfType <IUmbracoIndex>().Count(x => x.EnableDefaultEventHandler);

            _logger.Info <ExamineComponent>("Adding examine event handlers for {RegisteredIndexers} index providers.", registeredIndexers);

            // don't bind event handlers if we're not suppose to listen
            if (registeredIndexers == 0)
            {
                return;
            }

            // bind to distributed cache events - this ensures that this logic occurs on ALL servers
            // that are taking part in a load balanced environment.
            ContentCacheRefresher.CacheUpdated     += ContentCacheRefresherUpdated;
            ContentTypeCacheRefresher.CacheUpdated += ContentTypeCacheRefresherUpdated;;
            MediaCacheRefresher.CacheUpdated       += MediaCacheRefresherUpdated;
            MemberCacheRefresher.CacheUpdated      += MemberCacheRefresherUpdated;

            EnsureUnlocked(_logger, _examineManager);

            // TODO: Instead of waiting 5000 ms, we could add an event handler on to fulfilling the first request, then start?
            RebuildIndexes(_indexRebuilder, _logger, true, 5000);
        }
        /// <summary>
        /// Called during the initialize operation of the boot manager process
        /// </summary>
        public void Initialize()
        {
            //We want to manage Examine's appdomain shutdown sequence ourselves so first we'll disable Examine's default behavior
            //and then we'll use MainDom to control Examine's shutdown
            ExamineManager.DisableDefaultHostingEnvironmentRegistration();

            //we want to tell examine to use a different fs lock instead of the default NativeFSFileLock which could cause problems if the appdomain
            //terminates and in some rare cases would only allow unlocking of the file if IIS is forcefully terminated. Instead we'll rely on the simplefslock
            //which simply checks the existence of the lock file
            DirectoryTracker.DefaultLockFactory = d =>
            {
                var simpleFsLockFactory = new NoPrefixSimpleFsLockFactory(d);
                return(simpleFsLockFactory);
            };

            //This is basically a hack for this item: http://issues.umbraco.org/issue/U4-5976
            // when Examine initializes it will try to rebuild if the indexes are empty, however in many cases not all of Examine's
            // event handlers will be assigned during bootup when the rebuilding starts which is a problem. So with the examine 0.1.58.2941 build
            // it has an event we can subscribe to in order to cancel this rebuilding process, but what we'll do is cancel it and postpone the rebuilding until the
            // boot process has completed. It's a hack but it works.
            ExamineManager.Instance.BuildingEmptyIndexOnStartup += OnInstanceOnBuildingEmptyIndexOnStartup;

            //let's deal with shutting down Examine with MainDom
            var examineShutdownRegistered = _appCtx.MainDom.Register(() =>
            {
                using (_profilingLogger.TraceDuration <ExamineStartup>("Examine shutting down"))
                {
                    //Due to the way Examine's own IRegisteredObject works, we'll first run it with immediate=false and then true so that
                    //it's correct subroutines are executed (otherwise we'd have to run this logic manually ourselves)
                    ExamineManager.Instance.Stop(false);
                    ExamineManager.Instance.Stop(true);
                }
            });

            if (examineShutdownRegistered)
            {
                _profilingLogger.Logger.Debug <ExamineStartup>("Examine shutdown registered with MainDom");
            }
            else
            {
                _profilingLogger.Logger.Debug <ExamineStartup>("Examine shutdown not registered, this appdomain is not the MainDom");

                //if we could not register the shutdown examine ourselves, it means we are not maindom! in this case all of examine should be disabled
                //from indexing anything on startup!!
                _disableExamineIndexing = true;
                Suspendable.ExamineEvents.SuspendIndexers();
            }
        }