the Catalog manager and model into the Yavsc.Model.FrontOffice namespace * Web.config: * Catalog.xml: * MyClass.cs: * Note.cs: * Euro.cs: * Unit.cs: * Text.cs: * Link.cs: * Price.cs: * Label.cs: * Brand.cs: * Scalar.cs: * Option.cs: * Period.cs: * YavscModel.csproj: * Catalog.cs: * Service.cs: * Product.cs: * YavscClient.csproj: * CatalogManager.cs: * Currency.cs: * CheckBox.cs: * SaleForm.cs: * FormInput.cs: * CatalogProvider.cs: * TextInput.cs: * SelectItem.cs: * SalesCatalog.csproj: * FilesInput.cs: * FormElement.cs: * SelectInput.cs: * IValueProvider.cs: * StockStatus.cs: * RadioButton.cs: * Commande.cs: * ProductImage.cs: * WebCatalogExtensions.cs: * TemplateException.cs: * ProductCategory.cs: * PhysicalProduct.cs: * Note.cs: * Link.cs: * Text.cs: * Euro.cs: * Unit.cs: * WorkFlowManager.cs: * Brand.cs: * Label.cs: * Price.cs: * Scalar.cs: * FrontOfficeController.cs: * Period.cs: * Option.cs: * Product.cs: * Service.cs: * Catalog.cs: * SaleForm.cs: * Currency.cs: * CheckBox.cs: * TextInput.cs: * FrontOfficeApiController.cs: * FormInput.cs: * SelectItem.cs: * FilesInput.cs: * XmlCatalog.cs: * FormElement.cs: * SelectInput.cs: * RadioButton.cs: * StockStatus.cs: * ProductImage.cs: * CatalogHelper.cs: * CatalogManager.cs: * CatalogProvider.cs: * ProductCategory.cs: * PhysicalProduct.cs: * XmlCatalogProvider.cs: * CatalogProviderConfigurationElement.cs: * CatalogProvidersConfigurationSection.cs: * CatalogProvidersConfigurationCollection.cs: * CatalogProviderConfigurationElement.cs: * CatalogProvidersConfigurationSection.cs: * CatalogProvidersConfigurationCollection.cs: * CatalogHelper.cs:
64 lines
2.2 KiB
C#
64 lines
2.2 KiB
C#
using System;
|
|
using System.Configuration;
|
|
using System.Reflection;
|
|
using System.Collections.Specialized;
|
|
using Yavsc.Model.FrontOffice.Configuration;
|
|
|
|
namespace Yavsc.Model.FrontOffice
|
|
{
|
|
/// <summary>
|
|
/// Catalog helper.
|
|
/// Used by the catalog manager to get the catalog provider from the configuration.
|
|
/// </summary>
|
|
public static class CatalogHelper
|
|
{
|
|
|
|
public static CatalogProvidersConfigurationSection Config {get; set; }
|
|
|
|
public static void LoadConfig () {
|
|
Config = ConfigurationManager.GetSection ("system.web/catalog") as CatalogProvidersConfigurationSection;
|
|
if (Config == null)
|
|
throw new ConfigurationErrorsException("The configuration bloc for the catalog provider was not found");
|
|
/* foreach (CatalogProviderConfigurationElement e in Config.Providers) {
|
|
Providers.Add(CreateProvider (e));
|
|
} */
|
|
}
|
|
private static CatalogProvider CreateProvider(CatalogProviderConfigurationElement celt) {
|
|
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 (
|
|
string.Format("The catalog provider type ({0}) doesn't contain public constructor with empty parameter list",celt.Type));
|
|
|
|
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;
|
|
}
|
|
/// <summary>
|
|
/// Gets the default provider.
|
|
///
|
|
/// </summary>
|
|
/// <returns>The default provider.</returns>
|
|
public static CatalogProvider GetDefaultProvider ()
|
|
{
|
|
if (Config == null)
|
|
throw new Exception ("Configuration wanted, use a call to \"Load\".");
|
|
CatalogProviderConfigurationElement celt =
|
|
Config.Providers.GetElement (Config.DefaultProvider);
|
|
|
|
return CreateProvider (celt);
|
|
}
|
|
}
|
|
}
|
|
|