From 8254336767121f87d75f4f30017fb757a0cbd90d Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Fri, 10 Oct 2014 14:15:52 +0200 Subject: [PATCH] * CatalogHelper.cs: Configuration loading * Web.csproj: * CatalogManager.cs: --- SalesCatalog/CatalogHelper.cs | 18 +++++++++++------- SalesCatalog/CatalogManager.cs | 10 ++++++++-- web/Web.csproj | 11 ++++++----- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/SalesCatalog/CatalogHelper.cs b/SalesCatalog/CatalogHelper.cs index de5d1327..e6b493f5 100644 --- a/SalesCatalog/CatalogHelper.cs +++ b/SalesCatalog/CatalogHelper.cs @@ -15,15 +15,13 @@ namespace SalesCatalog public static CatalogProvidersConfigurationSection Config {get; set; } - public static void Load () { - if (Config != null) - return ; + 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) { - CreateProvider (e); - } + /* foreach (CatalogProviderConfigurationElement e in Config.Providers) { + Providers.Add(CreateProvider (e)); + } */ } private static CatalogProvider CreateProvider(CatalogProviderConfigurationElement celt) { if (celt == null) @@ -47,9 +45,15 @@ namespace SalesCatalog cp.Initialize (celt.Name, c); return cp; } - + /// + /// Gets the default provider. + /// + /// + /// The default provider. public static CatalogProvider GetDefaultProvider () { + if (Config == null) + throw new Exception ("Configuration wanted, use a call to \"Load\"."); CatalogProviderConfigurationElement celt = Config.Providers.GetElement (Config.DefaultProvider); diff --git a/SalesCatalog/CatalogManager.cs b/SalesCatalog/CatalogManager.cs index 080860b2..a6f71d2c 100644 --- a/SalesCatalog/CatalogManager.cs +++ b/SalesCatalog/CatalogManager.cs @@ -9,10 +9,16 @@ namespace SalesCatalog /// public static class CatalogManager { + private static CatalogProvider defaultProvider = null; public static Catalog GetCatalog () { - CatalogProvider p = CatalogHelper.GetDefaultProvider (); - return p.GetCatalog (); + if (defaultProvider == null) { + if (CatalogHelper.Config == null) + CatalogHelper.LoadConfig (); + defaultProvider = CatalogHelper.GetDefaultProvider (); + + } + return defaultProvider.GetCatalog (); } } } diff --git a/web/Web.csproj b/web/Web.csproj index 206c6c08..39583068 100644 --- a/web/Web.csproj +++ b/web/Web.csproj @@ -72,18 +72,19 @@ - - ..\..\..\..\..\usr\lib\mono\4.5\System.Web.Http.WebHost.dll - False - - + ..\..\..\..\..\usr\lib\mono\4.5\System.Net.Http.Formatting.dll False + + ..\..\..\..\..\usr\lib\mono\4.5\System.Web.Http.WebHost.dll + False + +