Example #1
0
        static Membership()
        {
            MembershipSection section = (MembershipSection)WebConfigurationManager.GetSection("system.web/membership");

            providers = new MembershipProviderCollection();

            ProvidersHelper.InstantiateProviders(section.Providers, providers, typeof(MembershipProvider));

            provider = providers[section.DefaultProvider];

            onlineTimeWindow  = (int)section.UserIsOnlineTimeWindow.TotalMinutes;
            hashAlgorithmType = section.HashAlgorithmType;
            if (String.IsNullOrEmpty(hashAlgorithmType))
            {
                MachineKeySection             mks = WebConfigurationManager.GetSection("system.web/machineKey") as MachineKeySection;
                MachineKeyValidationConverter cvt = new MachineKeyValidationConverter();
                hashAlgorithmType = cvt.ConvertTo(null, null, mks.Validation, typeof(string)) as string;
            }

            if (String.IsNullOrEmpty(hashAlgorithmType))
            {
                hashAlgorithmType = "SHA1";
            }
        }
        private static void Initialize()
        {
            ProviderConfiguration configuration = (ProviderConfiguration)ConfigurationManager.GetSection("navigation-providers");

            if (configuration == null)
            {
                throw new ConfigurationErrorsException
                          ("The navigation-providers configuration section is not set correctly.");
            }

            providers = new NavigationProviderCollection();

            ProvidersHelper.InstantiateProviders(configuration.Providers
                                                 , providers, typeof(NavigationProviderBase));

            providers.SetReadOnly();

            defaultProvider = providers[configuration.Default];

            if (defaultProvider == null)
            {
                throw new Exception("No default navigation provider is defined for the navigation-providers section.");
            }
        }
Example #3
0
        static RoleManager()
        {
            //Get the feature's configuration info
            var ac =
                (RoleProviderConfiguration)ConfigurationManager.GetSection("roleManager");

            if (ac == null || ac.DefaultProvider == null || ac.Providers == null || ac.Providers.Count < 1)
            {
                throw new ProviderException("You must specify a valid default provider for roleManager.");
            }

            //Instantiate the providers
            providerCollection = new RoleProviderCollection();
            ProvidersHelper.InstantiateProviders(ac.Providers, providerCollection, typeof(RoleProvider));
            providerCollection.SetReadOnly();
            defaultProvider = providerCollection[ac.DefaultProvider];
            if (defaultProvider == null)
            {
                throw new ConfigurationErrorsException(
                          "You must specify a default provider for the roleManager.",
                          ac.ElementInformation.Properties["defaultProvider"].Source,
                          ac.ElementInformation.Properties["defaultProvider"].LineNumber);
            }
        }
Example #4
0
        private static void Initialize()
        {
            //try
            //{
            EditorConfiguration editorConfig = EditorConfiguration.GetConfig();

            if (
                (editorConfig.DefaultProvider == null) ||
                (editorConfig.Providers == null) ||
                (editorConfig.Providers.Count < 1)
                )
            {
                throw new ProviderException("You must specify a valid default provider.");
            }


            providerCollection = new EditorProviderCollection();

            ProvidersHelper.InstantiateProviders(
                editorConfig.Providers,
                providerCollection,
                typeof(EditorProvider));

            providerCollection.SetReadOnly();
            defaultProvider = providerCollection[editorConfig.DefaultProvider];

            //}
            //catch (Exception ex)
            //{
            //    initializationException = ex;
            //    isInitialized = true;
            //    throw ex;
            //}

            //isInitialized = true;
        }
Example #5
0
        private static void Initialize()
        {
            FileSystemConfiguration config = FileSystemConfiguration.GetConfig();

            if (
                (config.DefaultProvider == null) ||
                (config.Providers == null) ||
                (config.Providers.Count < 1)
                )
            {
                throw new ProviderException("You must specify a valid default provider.");
            }


            providerCollection = new FileSystemProviderCollection();

            ProvidersHelper.InstantiateProviders(
                config.Providers,
                providerCollection,
                typeof(FileSystemProvider));

            providerCollection.SetReadOnly();
            defaultProvider = providerCollection[config.DefaultProvider];
        }
Example #6
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        private static void Initialize()
        {
            //Get the feature's configuration info
            var qc = ConfigurationManager.GetSection("HtmlEditorProvider") as HtmlEditorConfiguration;

            if (qc != null && (qc.DefaultProvider == null || qc.Providers == null || qc.Providers.Count < 1))
            {
                throw new ProviderException("You must specify a valid default provider.");
            }

            //Instantiate the providers
            providerCollection = new HtmlEditorProviderCollection();
            ProvidersHelper.InstantiateProviders(qc.Providers, providerCollection, typeof(HtmlEditorProvider));
            providerCollection.SetReadOnly();
            defaultProvider = providerCollection[qc.DefaultProvider];

            if (defaultProvider == null)
            {
                throw new ConfigurationErrorsException(
                          "You must specify a default provider for the feature.",
                          qc.ElementInformation.Properties["defaultProvider"].Source,
                          qc.ElementInformation.Properties["defaultProvider"].LineNumber);
            }
        }
Example #7
0
        ///<summary>
        /// Configuration based provider loading, will load the providers on first call.
        ///</summary>
        private static void LoadProviders()
        {
            // Avoid claiming lock if providers are already loaded
            if (_provider == null)
            {
                lock (SyncRoot)
                {
                    // Do this again to make sure _provider is still null
                    if (_provider == null)
                    {
                        // Load registered providers and point _provider to the default provider
                        _providers = new NetTiersProviderCollection();

                        ProvidersHelper.InstantiateProviders(NetTiersSection.Providers, _providers, typeof(NetTiersProvider));
                        _provider = _providers[NetTiersSection.DefaultProvider];

                        if (_provider == null)
                        {
                            throw new ProviderException("Unable to load default NetTiersProvider");
                        }
                    }
                }
            }
        }
Example #8
0
        private static void LoadProviders()
        {
            // Avoid claiming lock if providers are already loaded
            if (_defaultProvider == null)
            {
                lock (_lock)
                {
                    // Do this again to make sure _defaultProvider is still null
                    if (_defaultProvider == null)
                    {
                        PhotoAlbumSection section = (PhotoAlbumSection)
                                                    WebConfigurationManager.GetSection
                                                        ("photoAlbumService");

                        // Only want one provider here
                        //_defaultProvider = (PhotoAlbumProvider)
                        //    ProvidersHelper.InstantiateProvider
                        //    (section.Providers[0], typeof(PhotoAlbumProvider));

                        _providers = new PhotoAlbumProviderCollection();

                        ProvidersHelper.InstantiateProviders(
                            section.Providers, _providers,
                            typeof(PhotoAlbumProvider));

                        _defaultProvider = _providers[section.DefaultProvider];

                        if (_defaultProvider == null)
                        {
                            throw new ProviderException
                                      ("Unable to load default PhotoAlbumProvider");
                        }
                    }
                }
            }
        }
 private static void Initialize()
 {
     if (s_Initialized)
     {
         if (s_InitializeException != null)
         {
             throw s_InitializeException;
         }
     }
     else
     {
         if (s_InitializeException != null)
         {
             throw s_InitializeException;
         }
         lock (s_lock)
         {
             if (s_Initialized)
             {
                 if (s_InitializeException != null)
                 {
                     throw s_InitializeException;
                 }
             }
             else
             {
                 try
                 {
                     DBProviderSection section = GetSection <T>();
                     if (((section.DefaultProvider == null) || (section.Providers == null) || (section.Providers.Count < 1)))
                     {
                         throw new ProviderException("Default provider not specified");
                     }
                     s_Providers = new DBProviderCollection <T>();
                     if (HostingEnvironment.IsHosted)
                     {
                         ProvidersHelper.InstantiateProviders(section.Providers, s_Providers, typeof(T));
                     }
                     else
                     {
                         foreach (ProviderSettings settings in section.Providers)
                         {
                             Type c = Type.GetType(settings.Type, true, true);
                             if (!typeof(T).IsAssignableFrom(c))
                             {
                                 throw new ArgumentException(string.Format("Provider must implement {0} type",
                                                                           new object[] { typeof(T).ToString() }));
                             }
                             T provider = (T)Activator.CreateInstance(c);
                             NameValueCollection parameters = settings.Parameters;
                             NameValueCollection config     = new NameValueCollection(parameters.Count, StringComparer.Ordinal);
                             foreach (string str2 in parameters)
                             {
                                 config[str2] = parameters[str2];
                             }
                             provider.Initialize(settings.Name, config);
                             s_Providers.Add(provider);
                         }
                     }
                     s_Provider = (T)s_Providers[section.DefaultProvider];
                     if (s_Provider == null)
                     {
                         throw new ConfigurationErrorsException(string.Format("Default provider not found. {0}. Line number: {1}",
                                                                              section.ElementInformation.Properties["defaultProvider"].Source,
                                                                              section.ElementInformation.Properties["defaultProvider"].LineNumber));
                     }
                     s_Providers.SetReadOnly();
                 }
                 catch (Exception exception)
                 {
                     s_InitializeException = exception;
                     throw;
                 }
                 s_Initialized = true;
             }
         }
     }
 }
Example #10
0
        //============================================================
        //	PRIVATE METHODS
        //============================================================
        #region Initialize()
        /// <summary>
        /// Initializes the <see cref="SyndicationManager"/> using the declaratively configured application settings.
        /// </summary>
        /// <seealso cref="SyndicationResourceSection"/>
        private static void Initialize()
        {
            //------------------------------------------------------------
            //	Verify manager has not already been initialized previously
            //------------------------------------------------------------
            if (syndicationManagerInitialized)
            {
                //------------------------------------------------------------
                //	Throw stored exception if initialization raised an exception
                //------------------------------------------------------------
                if (syndicationManagerInitializationException != null)
                {
                    throw syndicationManagerInitializationException;
                }
            }
            else
            {
                //------------------------------------------------------------
                //	Throw stored exception if initialization raised an exception
                //------------------------------------------------------------
                if (syndicationManagerInitializationException != null)
                {
                    throw syndicationManagerInitializationException;
                }

                lock (syndicationManagerLock)
                {
                    try
                    {
                        //------------------------------------------------------------
                        //	Extract configuration section from application configuration
                        //------------------------------------------------------------
                        SyndicationResourceSection section = PrivilegedConfigurationManager.GetSyndicationResourceSection();

                        if (section != null)
                        {
                            //------------------------------------------------------------
                            //	Raise exception if no providers were specified
                            //------------------------------------------------------------
                            if (((section.DefaultProvider == null) || (section.Providers == null)) || (section.Providers.Count < 1))
                            {
                                throw new ProviderException(String.Format(null, "The syndication resource providers were not specified. Source configuration file was {0}", section.ElementInformation.Source));
                            }

                            //------------------------------------------------------------
                            //	Fill providers collection
                            //------------------------------------------------------------
                            syndicationManagerProviders = new SyndicationResourceProviderCollection();

                            if (HostingEnvironment.IsHosted)
                            {
                                ProvidersHelper.InstantiateProviders(section.Providers, syndicationManagerProviders, typeof(SyndicationResourceProvider));
                            }
                            else
                            {
                                foreach (ProviderSettings settings in section.Providers)
                                {
                                    Type settingsType = Type.GetType(settings.Type, true, true);
                                    if (!typeof(SyndicationResourceProvider).IsAssignableFrom(settingsType))
                                    {
                                        throw new ArgumentException(String.Format(null, "The provider must implement type of {0}. Source configuration file was {1}", typeof(SyndicationResourceProvider).FullName, section.ElementInformation.Source));
                                    }

                                    SyndicationResourceProvider provider      = (SyndicationResourceProvider)Activator.CreateInstance(settingsType);
                                    NameValueCollection         parameters    = settings.Parameters;
                                    NameValueCollection         configuration = new NameValueCollection(parameters.Count, StringComparer.Ordinal);

                                    foreach (string parameter in parameters)
                                    {
                                        configuration[parameter] = parameters[parameter];
                                    }

                                    provider.Initialize(settings.Name, configuration);
                                    syndicationManagerProviders.Add(provider);
                                }
                            }

                            //------------------------------------------------------------
                            //	Set and validate default provider
                            //------------------------------------------------------------
                            syndicationManagerDefaultProvider = syndicationManagerProviders[section.DefaultProvider];

                            if (syndicationManagerDefaultProvider == null)
                            {
                                throw new ConfigurationErrorsException(String.Format(null, "The default syndication resource provider was not found. Source configuration file was {0}", section.ElementInformation.Source), section.ElementInformation.Properties["defaultProvider"].Source, section.ElementInformation.Properties["defaultProvider"].LineNumber);
                            }

                            //------------------------------------------------------------
                            //	Prevent collection from being modified further
                            //------------------------------------------------------------
                            syndicationManagerProviders.SetReadOnly();
                        }
                    }
                    catch (Exception exception)
                    {
                        //------------------------------------------------------------
                        //	Store exception locally and then throw
                        //------------------------------------------------------------
                        syndicationManagerInitializationException = exception;
                        throw;
                    }

                    //------------------------------------------------------------
                    //	Set initialization indicator flag
                    //------------------------------------------------------------
                    syndicationManagerInitialized = true;
                }
            }
        }
Example #11
0
        /// <summary>
        /// Loads the providers.
        /// </summary>
        protected virtual void LoadProviders(
            bool throwErrorIfUnableToLoadSection)
        {
            // Avoid claiming lock if providers are already loaded
            if (_providers == null)
            {
                lock (_syncRoot)
                {
                    // Do this again to make sure provider is still null
                    if (_providers == null)
                    {
                        // Get the providers
                        _providers = new ProviderCollection <T>();

                        // Get a reference to the section
                        ProvidersSection section = null;
                        try
                        {
                            section =
                                ConfigurationManager.GetSection(_sectionName) as ProvidersSection;
                        }
                        catch (Exception)
                        {
                            section = null;
                        }

                        if (section == null)
                        {
                            if (throwErrorIfUnableToLoadSection)
                            {
                                throw new ProviderException(
                                          String.Format("Unable to load configuration section: '{0}'.",
                                                        _sectionName));
                            }
                        }
                        else
                        {
                            ProvidersHelper.InstantiateProviders(section.Providers, _providers, typeof(T));

                            if (_providers.Count > 0)
                            {
                                // If there is a default provider specified, then grab it,
                                // else grab the first provider in the collection
                                if (!String.IsNullOrEmpty(section.DefaultProvider))
                                {
                                    _provider = (T)_providers[section.DefaultProvider];
                                }
                                else
                                {
                                    _provider = _providers[0];
                                }
                            }

                            if (throwErrorIfUnableToLoadSection)
                            {
                                // If we have no provider, then throw an exception
                                if (_provider == null)
                                {
                                    throw new ProviderException(
                                              String.Format("Unable to load default provider for section: '{0}'.",
                                                            _sectionName));
                                }
                            }
                        }
                    }
                }
            }
        }
Example #12
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();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Example #13
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        private static void Initialize()
        {
            //Check if we have been initialized before.
            if (_isInitialized && _initializedDefaultProvider)
            {
                return;
            }

            //If we did initialize and there was an exception,
            //rethrow the exception
            if (_initializationException != null)
            {
                throw _initializationException;
            }

            lock (_initializationLock)
            {
                //Check if we have been initialized before.
                if (_isInitialized && _initializedDefaultProvider)
                {
                    return;
                }

                //If we did initialize and there was an exception,
                //rethrow the exception
                if (_initializationException != null)
                {
                    throw _initializationException;
                }



                //Now actually do the initialization
                try
                {
                    //Get the feature's configuration info
                    SiteWideSearchConfiguration searchProviderConfig =
                        (SiteWideSearchConfiguration)ConfigurationManager.GetSection("SiteWideSearch");

                    if (searchProviderConfig == null)
                    {
                        throw new ProviderException("SiteWideSearchProviders section cannot be found in configuration file.");
                    }

                    //Instantiate the providers
                    _providerCollection = new SiteWideSearchProviderCollection();

                    //"InitializeSettings"
                    ProvidersHelper.InstantiateProviders(
                        searchProviderConfig.Providers,
                        _providerCollection,
                        typeof(SiteWideSearchProviderBase)
                        );

                    //Don't Allow this to be written to anymore now that it is loaded
                    _providerCollection.SetReadOnly();

                    if (searchProviderConfig.DefaultProvider == null || _providerCollection.Count < 1)
                    {
                        throw new ProviderException("Default SiteWideSearchProvider could not be found");
                    }

                    _defaultProvider = _providerCollection[searchProviderConfig.DefaultProvider];

                    if (_defaultProvider == null)
                    {
                        throw new ConfigurationErrorsException(
                                  "SiteWideSearch Providers: Default provider could not be found.",
                                  searchProviderConfig.ElementInformation.Properties["defaultProvider"].Source,
                                  searchProviderConfig.ElementInformation.Properties["defaultProvider"].LineNumber);
                    }
                }
                catch (Exception ex)
                {
                    _initializationException = ex;
                    throw;
                }

                //Set it as initialized
                _isInitialized = true;
                _initializedDefaultProvider = true;
            }
        }