コード例 #1
0
        /// <summary>
        /// Helper method for populating a provider collection
        /// from a Provider section handler.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static GenericProviderCollection <T> LoadProviders <T>(string sectionName, out T provider)
            where T : ProviderBase
        {
            // Get a reference to the provider section
            //ProviderSectionHandler section = (ProviderSectionHandler)WebConfigurationManager.GetSection(sectionName);

            // Load registered providers and point _provider
            // to the default provider
            GenericProviderCollection <T> providers = new GenericProviderCollection <T>();
            //ProvidersHelper.InstantiateProviders(section.Providers, providers, typeof(T));

            string      xml = "<providers><clear /><add name=\"Default\" type=\"Upac.Providers.ConcretSearchProvider, Upac.Providers\" /></providers>";
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);
            XmlNodeList nodes = doc.SelectNodes("providers/*");

            foreach (XmlNode node in nodes)
            {
                if (node.LocalName == "clear")
                {
                    providers.Clear();
                }
                else
                {
                    string type       = node.SelectSingleNode("@type").InnerText;
                    Type   targetType = System.Web.Compilation.BuildManager.GetType(type, true);
                    object obj2       = Activator.CreateInstance(targetType);
                    Type   c          = obj2.GetType();
                    Type   type2      = typeof(T);
                    T      provider2  = obj2 as T;
                    if (provider2 == null)
                    {
                        throw new InvalidOperationException("Provider definition must have a 'name' attribute. Xml: " + node.OuterXml);
                    }
                    string attribute = GetAttribute("name", node);
                    if (attribute.Length == 0)
                    {
                        throw new InvalidOperationException("Provider definition must have a 'name' attribute. Xml: " + node.OuterXml);
                    }
                    provider2.Initialize(attribute, GetAttributes(node));
                    providers.Add(provider2);
                }
            }

            provider = providers["Default"];

            return(providers);

            //provider = providers[section.DefaultProvider];

            //if (provider == null)
            //    throw new ProviderException(
            //        string.Format(
            //              "Unable to load default '{0}' provider",
            //                    sectionName));
        }
コード例 #2
0
 static SearchManager()
 {
     Collection = ProviderHelper.LoadProviders("", out Defaultprovider);
 }