* CatalogHelper.cs: Configuration loading
* Web.csproj: * CatalogManager.cs:
This commit is contained in:
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 CatalogProvidersConfigurationSection Config {get; set; }
|
||||||
|
|
||||||
public static void Load () {
|
public static void LoadConfig () {
|
||||||
if (Config != null)
|
|
||||||
return ;
|
|
||||||
Config = ConfigurationManager.GetSection ("system.web/catalog") as CatalogProvidersConfigurationSection;
|
Config = ConfigurationManager.GetSection ("system.web/catalog") as CatalogProvidersConfigurationSection;
|
||||||
if (Config == null)
|
if (Config == null)
|
||||||
throw new ConfigurationErrorsException("The configuration bloc for the catalog provider was not found");
|
throw new ConfigurationErrorsException("The configuration bloc for the catalog provider was not found");
|
||||||
foreach (CatalogProviderConfigurationElement e in Config.Providers) {
|
/* foreach (CatalogProviderConfigurationElement e in Config.Providers) {
|
||||||
CreateProvider (e);
|
Providers.Add(CreateProvider (e));
|
||||||
}
|
} */
|
||||||
}
|
}
|
||||||
private static CatalogProvider CreateProvider(CatalogProviderConfigurationElement celt) {
|
private static CatalogProvider CreateProvider(CatalogProviderConfigurationElement celt) {
|
||||||
if (celt == null)
|
if (celt == null)
|
||||||
|
|
@ -47,9 +45,15 @@ namespace SalesCatalog
|
||||||
cp.Initialize (celt.Name, c);
|
cp.Initialize (celt.Name, c);
|
||||||
return cp;
|
return cp;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the default provider.
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The default provider.</returns>
|
||||||
public static CatalogProvider GetDefaultProvider ()
|
public static CatalogProvider GetDefaultProvider ()
|
||||||
{
|
{
|
||||||
|
if (Config == null)
|
||||||
|
throw new Exception ("Configuration wanted, use a call to \"Load\".");
|
||||||
CatalogProviderConfigurationElement celt =
|
CatalogProviderConfigurationElement celt =
|
||||||
Config.Providers.GetElement (Config.DefaultProvider);
|
Config.Providers.GetElement (Config.DefaultProvider);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,16 @@ namespace SalesCatalog
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class CatalogManager
|
public static class CatalogManager
|
||||||
{
|
{
|
||||||
|
private static CatalogProvider defaultProvider = null;
|
||||||
public static Catalog GetCatalog ()
|
public static Catalog GetCatalog ()
|
||||||
{
|
{
|
||||||
CatalogProvider p = CatalogHelper.GetDefaultProvider ();
|
if (defaultProvider == null) {
|
||||||
return p.GetCatalog ();
|
if (CatalogHelper.Config == null)
|
||||||
|
CatalogHelper.LoadConfig ();
|
||||||
|
defaultProvider = CatalogHelper.GetDefaultProvider ();
|
||||||
|
|
||||||
|
}
|
||||||
|
return defaultProvider.GetCatalog ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,18 +72,19 @@
|
||||||
<Reference Include="System.ServiceModel.Routing" />
|
<Reference Include="System.ServiceModel.Routing" />
|
||||||
<Reference Include="System.Net.Http" />
|
<Reference Include="System.Net.Http" />
|
||||||
<Reference Include="System.Net.Http.WebRequest" />
|
<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.Configuration.Install" />
|
||||||
<Reference Include="System.Web.Services" />
|
<Reference Include="System.Web.Services" />
|
||||||
<Reference Include="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
|
<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.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>
|
<HintPath>..\..\..\..\..\usr\lib\mono\4.5\System.Net.Http.Formatting.dll</HintPath>
|
||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
</Reference>
|
</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>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Models\" />
|
<Folder Include="Models\" />
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue