Files
yavsc/SalesCatalog/CatalogHelper.cs
Paul Schneider c22be7f6b5 * Estimate.aspx: from backoffice
* CatalogManager.cs: Uses GetDefaultProvider

* Catalog.cs: the Catalog object now should support a unique id in the
  system : UID, exposed as one of its properties.

* AccountController.cs: new static method te get an user profile by
  its name.

* AdminController.cs: Uses the Yavsc.Admin namespace (refactoring)

* Web.csproj:
* BlogManager.cs:
* BackOfficeController.cs: refactoring

* BlogsController.cs: Fixes the Blog title

* FrontOfficeController.cs: Changes on the go for the Command object

* AddRole.aspx: minor syntax change

* UserPosts.aspx: show the blog title

* style.css: black transparent for the background of posts

* Profile.cs: Method FromProfileBase became a constructor

* Commande.cs: nothing

* Estimate.aspx: moved to the frontoffice views

* CatalogHelper.cs: Writting GetDefaultProvider
2014-10-10 11:54:18 +02:00

61 lines
2.0 KiB
C#

using System;
using System.Configuration;
using System.Reflection;
using System.Collections.Specialized;
using SalesCatalog.Configuration;
namespace SalesCatalog
{
/// <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 Load () {
if (Config != null)
return ;
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) {
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;
}
public static CatalogProvider GetDefaultProvider ()
{
CatalogProviderConfigurationElement celt =
Config.Providers.GetElement (Config.DefaultProvider);
return CreateProvider (celt);
}
}
}