Example #1
0
        /// <summary>
        /// Used to lazily check if Examine Index handling is enabled
        /// </summary>
        /// <returns></returns>
        private bool IsEnabled()
        {
            //let's deal with shutting down Examine with MainDom
            var examineShutdownRegistered = _mainDom.Register(release: () =>
            {
                using (_profilingLogger.TraceDuration <ExamineUmbracoIndexingHandler>("Examine shutting down"))
                {
                    _examineManager.Dispose();
                }
            });

            if (!examineShutdownRegistered)
            {
                _logger.LogInformation("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);
                return(false); //exit, do not continue
            }

            _logger.LogDebug("Examine shutdown registered with MainDom");

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

            _logger.LogInformation("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(false);
            }

            return(true);
        }