public void Refresh()
        {
            // If there are already waiting writes/refreshes, just bail out, as there's no point in queuing another.
            if (_searcherLock.WaitingWriteCount > 0)
            {
                ADXTrace.Instance.TraceInfo(TraceCategory.Application, "There are existing waiting writes to the shared index searcher, exiting.");

                return;
            }

            if (!_searcherLock.TryEnterWriteLock(_searcherLockTimeout))
            {
                throw new TimeoutException("A write lock couldn't be acquired on the shared index searcher instance.");
            }

            var staleSearcher = _searcher;

            try
            {
                _searcher = _searcherFactory();
            }
            finally
            {
                _searcherLock.ExitWriteLock();
            }

            staleSearcher.Dispose();
        }
Exemple #2
0
        public ExtendedAttributeIndexSearcher(ICrmEntityIndexSearcher searcher, string dataContextName)
        {
            if (searcher == null)
            {
                throw new ArgumentNullException("searcher");
            }

            _searcher        = searcher;
            _dataContextName = dataContextName;
        }
        public SharedIndexSearcher(Func <ICrmEntityIndexSearcher> searcherFactory)
        {
            if (searcherFactory == null)
            {
                throw new ArgumentNullException("searcherFactory");
            }

            _searcherFactory = searcherFactory;
            _searcher        = _searcherFactory();

            double timeoutSecondsSetting;

            _searcherLockTimeout = double.TryParse(ConfigurationManager.AppSettings[LockTimeoutAppSettingName], out timeoutSecondsSetting)
                                ? TimeSpan.FromSeconds(timeoutSecondsSetting)
                                : DefaultSearcherLockTimeout;
        }