Files
yavsc/yavscModel/FrontOffice/Catalog/CatalogHelper.cs
Paul Schneider b505ad90e7 * YavscModel.csproj:
* NewProjectModel.cs:
* ITContentProvider.csproj: refactoring

* WebApiConfig.cs: Web Api Config

* IModule.cs:
* RssFeeds.cs:
* IRenderer.cs:
* Blog.cs:
* ITagHandler.cs:
* ViewRenderer.cs:
* Comment.cs:
* IViewRenderer.cs:
* People.cs:
* SignIn.cs:
* BlogEntry.cs:
* AuthToken.cs:
* BlogHelper.cs:
* DataAccess.cs:
* Estimate.cs:
* BlogManager.cs:
* Writting.cs:
* AskForADate.cs:
* RestoreQuery.cs:
* Basket.cs:
* BlogProvider.cs:
* CalendarList.cs:
* Commande.cs:
* StatusChange.cs:
* WebFileInfo.cs:
* WorkFlowManager.cs:
* Euro.cs:
* Unit.cs:
* Text.cs:
* Profile.cs:
* Note.cs:
* Link.cs:
* BlogEditEntryModel.cs:
* FindBlogEntryFlags.cs:
* NewProjectModel.cs:
* CalendarListEntry.cs:
* CalendarEntryList.cs:
* IContentProvider.cs:
* CommandStatus.cs:
* Label.cs:
* Price.cs:
* BlogEntryCollection.cs:
* Period.cs:
* Scalar.cs:
* BlogEditCommentModel.cs:
* Option.cs:
* NpgsqlContentProvider.cs:
* Product.cs:
* LoginModel.cs:
* Service.cs:
* Catalog.cs:
* Currency.cs:
* NewEstimateEvenArgs.cs:
* CheckBox.cs:
* SaleForm.cs:
* FileSystemManager.cs:
* FormInput.cs:
* TextInput.cs:
* NewRoleModel.cs:
* FileInfoCollection.cs:
* FilesInput.cs:
* NewAdminModel.cs:
* SelectItem.cs:
* SelectInput.cs:
* RadioButton.cs:
* StockStatus.cs:
* Provider.cs:
* DirNotFoundException.cs:
* FormElement.cs:
* ProductImage.cs:
* WebFileInfoCollection.cs:
* CatalogHelper.cs:
* CatalogManager.cs:
* RegisterViewModel.cs:
* InvalidDirNameException.cs:
* PhysicalProduct.cs:
* CatalogProvider.cs:
* ProductCategory.cs:
* OrderStatusChangedEventArgs.cs:
* ProviderCollection.cs:
* WorkflowConfiguration.cs:
* BlogProviderConfigurationElement.cs:
* BlogProvidersConfigurationSection.cs:
* BlogProvidersConfigurationCollection.cs:
* CatalogProviderConfigurationElement.cs:
* CatalogProvidersConfigurationSection.cs:
* CatalogProvidersConfigurationCollection.cs: 
xml doc

* SalesCatalog.csproj:
* XmlCatalogProvider.cs: Maps the catalog using System.Web

* BasketController.cs:
* FrontOfficeController.cs: a Basket controller

* Global.asax.cs: Session in Web Api

* App.master: WebApi bas url as Javascript var 'apiBaseUrl'

* Index.aspx: !!not sure of this change.

* Web.csproj: compiles now includes WebApiConfig.cs

* style.css: link background color

* FileSystemController.cs: a file system controller
2015-02-17 13:57:39 +01:00

71 lines
2.4 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
{
/// <summary>
/// Gets or sets the config.
/// </summary>
/// <value>The config.</value>
public static CatalogProvidersConfigurationSection Config {get; set; }
/// <summary>
/// Loads the config.
/// </summary>
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);
}
}
}