Ejemplo n.º 1
0
 /// <summary>
 /// Adds the provider.
 /// </summary>
 /// <param name="provider">The provider.</param>
 public static void AddProvider(RestProvider provider)
 {
     if (_provider == null)
         _provider = new RestProviderCollection();
     _provider.Add(provider);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads the providers.
        /// </summary>
        public 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)
                    {
                        //we allow for passing in a configuration section
                        //check to see if one's been passed in
                        if (section == null)
                        {
                            section = ConfigSectionSettings ?? (SubSonicSection)ConfigurationManager.GetSection(ConfigurationSectionName.SUB_SONIC_SERVICE);

                            //if it's still null, throw an exception
                            if (section == null)
                                throw new ConfigurationErrorsException("Can't find the SubSonicService section of the application config file");
                        }

                        // Load registered providers and point DefaultProvider
                        // to the default provider
                        _provider = new RestProviderCollection();
                        ProvidersHelper.InstantiateProviders(section.RESTHandlers, _provider, typeof(RestProvider));

                        defaultProvider = _provider[section.DefaultProvider];

                        if (defaultProvider == null && _provider.Count > 0)
                        {
                            IEnumerator enumer = _provider.GetEnumerator();
                            enumer.MoveNext();
                            defaultProvider = (RestProvider)enumer.Current;
                            if (defaultProvider == null)
                                throw new ProviderException("No providers could be located in the SubSonicService section of the application config file.");
                        }
                    }
                }
            }
        }