65 lines
2.2 KiB
C#
65 lines
2.2 KiB
C#
10 years ago
|
using System;
|
||
|
using System.Configuration;
|
||
|
using System.Reflection;
|
||
|
using System.Collections.Specialized;
|
||
10 years ago
|
using Yavsc.Model.FrontOffice.Configuration;
|
||
10 years ago
|
|
||
10 years ago
|
namespace Yavsc.Model.FrontOffice
|
||
10 years ago
|
{
|
||
|
/// <summary>
|
||
|
/// Catalog helper.
|
||
|
/// Used by the catalog manager to get the catalog provider from the configuration.
|
||
|
/// </summary>
|
||
|
public static class CatalogHelper
|
||
|
{
|
||
10 years ago
|
|
||
|
public static CatalogProvidersConfigurationSection Config {get; set; }
|
||
|
|
||
10 years ago
|
public static void LoadConfig () {
|
||
10 years ago
|
Config = ConfigurationManager.GetSection ("system.web/catalog") as CatalogProvidersConfigurationSection;
|
||
|
if (Config == null)
|
||
10 years ago
|
throw new ConfigurationErrorsException("The configuration bloc for the catalog provider was not found");
|
||
10 years ago
|
/* foreach (CatalogProviderConfigurationElement e in Config.Providers) {
|
||
|
Providers.Add(CreateProvider (e));
|
||
|
} */
|
||
10 years ago
|
}
|
||
|
private static CatalogProvider CreateProvider(CatalogProviderConfigurationElement celt) {
|
||
10 years ago
|
if (celt == null)
|
||
|
throw new ConfigurationErrorsException("The default catalog provider was not found");
|
||
|
Type catprtype = Type.GetType (celt.Type);
|
||
|
if (catprtype == null)
|
||
|
throw new Exception (
|
||
|
string.Format("The catalog provider type ({0}) could not be found",celt.Type));
|
||
|
ConstructorInfo ci = catprtype.GetConstructor (Type.EmptyTypes);
|
||
|
if (ci==null)
|
||
|
throw new Exception (
|
||
10 years ago
|
string.Format("The catalog provider type ({0}) doesn't contain public constructor with empty parameter list",celt.Type));
|
||
10 years ago
|
|
||
|
CatalogProvider cp = ci.Invoke (Type.EmptyTypes) as CatalogProvider;
|
||
|
NameValueCollection c = new NameValueCollection ();
|
||
|
c.Add ("name", celt.Name);
|
||
|
c.Add ("type", celt.Type);
|
||
|
c.Add ("connection", celt.Connection);
|
||
|
c.Add ("description", celt.Description);
|
||
|
c.Add ("applicationName", celt.ApplicationName);
|
||
|
cp.Initialize (celt.Name, c);
|
||
|
return cp;
|
||
|
}
|
||
10 years ago
|
/// <summary>
|
||
|
/// Gets the default provider.
|
||
|
///
|
||
|
/// </summary>
|
||
|
/// <returns>The default provider.</returns>
|
||
10 years ago
|
public static CatalogProvider GetDefaultProvider ()
|
||
|
{
|
||
10 years ago
|
if (Config == null)
|
||
|
throw new Exception ("Configuration wanted, use a call to \"Load\".");
|
||
10 years ago
|
CatalogProviderConfigurationElement celt =
|
||
|
Config.Providers.GetElement (Config.DefaultProvider);
|
||
|
|
||
|
return CreateProvider (celt);
|
||
|
}
|
||
10 years ago
|
}
|
||
|
}
|
||
|
|