* CatalogHelper.cs: Configuration loading

* Web.csproj:
* CatalogManager.cs:
vnext
Paul Schneider 10 years ago
parent c22be7f6b5
commit 8254336767
3 changed files with 25 additions and 14 deletions

@ -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;
}
/// <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);

@ -9,10 +9,16 @@ namespace SalesCatalog
/// </summary>
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 ();
}
}
}

@ -72,18 +72,19 @@
<Reference Include="System.ServiceModel.Routing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Web.Http.WebHost">
<HintPath>..\..\..\..\..\usr\lib\mono\4.5\System.Web.Http.WebHost.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Web.Services" />
<Reference Include="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<Reference Include="System.Web.WebPages.Deployment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<Reference Include="System.Net.Http.Formatting">
<Reference Include="System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<HintPath>..\..\..\..\..\usr\lib\mono\4.5\System.Net.Http.Formatting.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<HintPath>..\..\..\..\..\usr\lib\mono\4.5\System.Web.Http.WebHost.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="nunit.framework, Version=2.6.0.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" />
</ItemGroup>
<ItemGroup>
<Folder Include="Models\" />

Loading…