public static IReaderProvider CreateReaderProvider(Configuration cfg, ISearchFactoryImplementor searchFactoryImplementor)
        {
            IDictionary<string, string> props = GetProperties(cfg);
            string impl = props.ContainsKey(Environment.ReaderStrategy) ? props[Environment.ReaderStrategy] : string.Empty;
            IReaderProvider readerProvider;
            if (string.IsNullOrEmpty(impl))
                // Put in another one
                readerProvider = new SharedReaderProvider();
            else if (impl.ToLowerInvariant() == "not-shared")
                readerProvider = new NotSharedReaderProvider();
            else if (impl.ToLowerInvariant() == "shared")
                readerProvider = new SharedReaderProvider();
            else
            {
                try
                {
                    readerProvider = (IReaderProvider) Activator.CreateInstance(ReflectHelper.ClassForName(impl));
                }
                catch (InvalidCastException)
                {
                    throw new SearchException(string.Format("Class does not implement IReaderProvider: {0}", impl));
                }
                catch (Exception)
                {
                    throw new SearchException("Failed to instantiate IReaderProvider with type " + impl);
                }

            }
            readerProvider.Initialize(props, searchFactoryImplementor);

            return readerProvider;
        }
Ejemplo n.º 2
0
        public static IReaderProvider CreateReaderProvider(Configuration cfg, ISearchFactoryImplementor searchFactoryImplementor)
        {
            IDictionary <string, string> props = GetProperties(cfg);
            string          impl = props.ContainsKey(Environment.ReaderStrategy) ? props[Environment.ReaderStrategy] : string.Empty;
            IReaderProvider readerProvider;

            if (string.IsNullOrEmpty(impl))
            {
                // Put in another one
                readerProvider = new SharedReaderProvider();
            }
            else if (impl.ToLowerInvariant() == "not-shared")
            {
                readerProvider = new NotSharedReaderProvider();
            }
            else if (impl.ToLowerInvariant() == "shared")
            {
                readerProvider = new SharedReaderProvider();
            }
            else
            {
                try
                {
                    readerProvider = (IReaderProvider)Activator.CreateInstance(ReflectHelper.ClassForName(impl));
                }
                catch (InvalidCastException)
                {
                    throw new SearchException(string.Format("Class does not implement IReaderProvider: {0}", impl));
                }
                catch (Exception)
                {
                    throw new SearchException("Failed to instantiate IReaderProvider with type " + impl);
                }
            }
            readerProvider.Initialize(props, searchFactoryImplementor);

            return(readerProvider);
        }