Exemplo n.º 1
0
        /// <summary>
        /// Requests a registered object to unregister on app domain unload in a web project
        /// </summary>
        /// <param name="immediate">true to indicate the registered object should unregister from the hosting environment before returning; otherwise, false.</param>
        public void Stop(bool immediate)
        {
            if (immediate)
            {
                //This is sort of a hack at the moment. We are disposing the searchers at the last possible point in time because there might
                // still be pages executing when 'immediate' == false. In which case, when we close the readers, exceptions will occur
                // if the search results are still being enumerated.
                // I've tried using DecRef and IncRef to keep track of searchers using readers, however there is no guarantee that DecRef can
                // be called when a search is finished and since search results are lazy, we don't know when they end unless people dispose them
                // or always use a foreach loop which can't really be forced. The only alternative to using DecRef and IncRef would be to make the results
                // not lazy which isn't good.

                foreach (var searcher in SearchProviderCollection.OfType <IDisposable>())
                {
                    searcher.Dispose();
                }

                OpenReaderTracker.Current.CloseAllReaders();

                HostingEnvironment.UnregisterObject(this);
            }
            else
            {
                foreach (var indexer in IndexProviderCollection.OfType <IDisposable>())
                {
                    indexer.Dispose();
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Requests a registered object to unregister on app domain unload in a web project
 /// </summary>
 /// <param name="immediate">true to indicate the registered object should unregister from the hosting environment before returning; otherwise, false.</param>
 public void Stop(bool immediate)
 {
     foreach (var searcher in SearchProviderCollection.OfType <IDisposable>())
     {
         searcher.Dispose();
     }
     foreach (var indexer in IndexProviderCollection.OfType <IDisposable>())
     {
         indexer.Dispose();
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Before any of the index/search collections are accessed, the providers need to be loaded
        /// </summary>
        private void EnsureProviders()
        {
            if (!_providersInit)
            {
                lock (_lock)
                {
                    // Do this again to make sure _provider is still null
                    if (!_providersInit)
                    {
                        // Load registered providers and point _provider to the default provider

                        _indexProviderCollection = new IndexProviderCollection();
                        ProvidersHelper.InstantiateProviders(ExamineSettings.Instance.IndexProviders.Providers, _indexProviderCollection, typeof(BaseIndexProvider));

                        _searchProviderCollection = new SearchProviderCollection();
                        ProvidersHelper.InstantiateProviders(ExamineSettings.Instance.SearchProviders.Providers, _searchProviderCollection, typeof(BaseSearchProvider));

                        //set the default
                        if (!string.IsNullOrEmpty(ExamineSettings.Instance.SearchProviders.DefaultProvider))
                        {
                            _defaultSearchProvider = _searchProviderCollection[ExamineSettings.Instance.SearchProviders.DefaultProvider];
                        }

                        if (_defaultSearchProvider == null)
                        {
                            throw new ProviderException("Unable to load default search provider");
                        }

                        _providersInit = true;


                        //check if we need to rebuild on startup
                        if (ExamineSettings.Instance.RebuildOnAppStart)
                        {
                            foreach (var index in _indexProviderCollection.Cast <IIndexer>())
                            {
                                if (!index.IndexExists())
                                {
                                    var args = new BuildingEmptyIndexOnStartupEventArgs(index);
                                    OnBuildingEmptyIndexOnStartup(args);
                                    if (!args.Cancel)
                                    {
                                        index.RebuildIndex();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Before any of the index/search collections are accessed, the providers need to be loaded
        /// </summary>
        private void EnsureProviders()
        {
            if (!_providersInit)
            {
                lock (_lock)
                {
                    // Do this again to make sure _provider is still null
                    if (!_providersInit)
                    {
                        // Load registered providers and point _provider to the default provider

                        _indexProviderCollection = new IndexProviderCollection();
                        ProvidersHelper.InstantiateProviders(ExamineSettings.Instance.IndexProviders.Providers, _indexProviderCollection, typeof(BaseIndexProvider));

                        _searchProviderCollection = new SearchProviderCollection();
                        ProvidersHelper.InstantiateProviders(ExamineSettings.Instance.SearchProviders.Providers, _searchProviderCollection, typeof(BaseSearchProvider));

                        //set the default
                        if (!string.IsNullOrEmpty(ExamineSettings.Instance.SearchProviders.DefaultProvider))
                        {
                            _defaultSearchProvider = _searchProviderCollection[ExamineSettings.Instance.SearchProviders.DefaultProvider];
                        }

                        if (_defaultSearchProvider == null)
                        {
                            throw new ProviderException("Unable to load default search provider");
                        }

                        _providersInit = true;


                        //check if we need to rebuild on startup
                        if (ExamineSettings.Instance.RebuildOnAppStart)
                        {
                            foreach (IIndexer index in _indexProviderCollection)
                            {
                                var       rebuild     = false;
                                var       healthy     = true;
                                Exception unhealthyEx = null;
                                var       exists      = index.IndexExists();
                                if (!exists)
                                {
                                    rebuild = true;
                                }
                                if (!rebuild)
                                {
                                    healthy = IsIndexHealthy(index, out unhealthyEx);
                                    if (!healthy)
                                    {
                                        rebuild = true;
                                    }
                                }
                                //if it doesn't exist ... or if it's unhealthy/corrupt

                                if (rebuild)
                                {
                                    var args = new BuildingEmptyIndexOnStartupEventArgs(index, healthy, unhealthyEx);
                                    OnBuildingEmptyIndexOnStartup(args);
                                    if (!args.Cancel)
                                    {
                                        index.RebuildIndex();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }