Class to expose public and private config elements?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
Im converting a web.config file from having multiple <section /> tags within a <sectionGroup /> to only having one <section /> tag that implements my own class. I hope in this way to make future maintenance of my config file simpler
but in the mean time it makes my life harder. Another reason for swapping architecture is that if I implement my own class I can add groups of rules more simply that I could with my original design.
Heres a sample of the web.config with both sets of <section /> tags in:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; "<span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; configuration<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; configSections<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; section <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Companies<span style="color:Black; " <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; path.Config.CompanySection, Stock<span style="color:Black; " <span style="color:Red; allowDefinition<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Everywhere<span style="color:Black; " <span style="color:Red; allowExeDefinition<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; MachineToApplication<span style="color:Black; " <span style="color:Red; allowLocation<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; true<span style="color:Black; " <span style="color:Red; restartOnExternalChanges<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; true<span style="color:Black; " <span style="color:Red; requirePermission<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; false<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; sectionGroup <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; CompanyData<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; section <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; co1Public<span style="color:Black; " <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; System.Configuration.NameValueSectionHandler,System,Version=1.0.5000.0, Culture=neutral,PublicKeyToken=b77a5c561934e089<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; section <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; co1Private<span style="color:Black; " <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; System.Configuration.NameValueSectionHandler,System,Version=1.0.5000.0, Culture=neutral,PublicKeyToken=b77a5c561934e089<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; section <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; co2Public<span style="color:Black; " <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; System.Configuration.NameValueSectionHandler,System,Version=1.0.5000.0, Culture=neutral,PublicKeyToken=b77a5c561934e089<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; section <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; co2Private<span style="color:Black; " <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; System.Configuration.NameValueSectionHandler,System,Version=1.0.5000.0, Culture=neutral,PublicKeyToken=b77a5c561934e089<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; sectionGroup<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; configSections<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; connectionStrings<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; path.Properties.Settings.AzManADAMServer<span style="color:Black; "
<span style="color:Red; connectionString<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; msldap://server:port/CN=AzManADAMStore, OU=SecNetPartition,O=SecNet,C=US<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; connectionStrings<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; appSettings<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; system.web<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; compilation <span style="color:Red; debug<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; false<span style="color:Black; " <span style="color:Red; targetFramework<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 4.0<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; authentication <span style="color:Red; mode<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Windows<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; identity <span style="color:Red; impersonate<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; false<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; roleManager <span style="color:Red; enabled<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; true<span style="color:Black; " <span style="color:Red; cacheRolesInCookie<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; true<span style="color:Black; " <span style="color:Red; defaultProvider<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; RoleManagerAzManADAMProvider<span style="color:Black; " <span style="color:Red; cookieName<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; .ASPXROLES<span style="color:Black; " <span style="color:Red; cookiePath<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; /<span style="color:Black; " <span style="color:Red; cookieTimeout<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 30<span style="color:Black; " <span style="color:Red; cookieRequireSSL<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; true<span style="color:Black; " <span style="color:Red; cookieSlidingExpiration<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; true<span style="color:Black; " <span style="color:Red; createPersistentCookie<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; false<span style="color:Black; " <span style="color:Red; cookieProtection<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; All<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; providers<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; RoleManagerAzManADAMProvider<span style="color:Black; " <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; System.Web.Security.AuthorizationStoreRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, publicKeyToken=b03f5f7f11d50a3a<span style="color:Black; " <span style="color:Red; connectionStringName<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; path.Properties.Settings.AzManADAMServer<span style="color:Black; " <span style="color:Red; applicationName<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Stock<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; providers<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; roleManager<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; pages <span style="color:Red; controlRenderingCompatibilityVersion<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 4.0<span style="color:Black; " <span style="color:Red; clientIDMode<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; AutoID<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; system.web<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Companies<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Company <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; co1<span style="color:Black; "
<span style="color:Red; historyTypeSale<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; SALE<span style="color:Black; "
<span style="color:Red; serialBillWarehouse<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; zz<span style="color:Black; "
<span style="color:Red; databaseCollation<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; LATIN1_GENERAL_BIN<span style="color:Black; "
<span style="color:Red; freeStockCalc<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; P-A<span style="color:Black; "
<span style="color:Red; availableStockCalc<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; P-A-B-F<span style="color:Black; "
<span style="color:Red; forecastShippingFactor<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; "
<span style="color:Red; useRollup<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; true<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; Company <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; co2<span style="color:Black; "
<span style="color:Red; historyTypeSale<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; SALE<span style="color:Black; "
<span style="color:Red; serialBillWarehouse<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; zz<span style="color:Black; "
<span style="color:Red; databaseCollation<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; LATIN1_GENERAL_BIN<span style="color:Black; "
<span style="color:Red; freeStockCalc<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; P-A<span style="color:Black; "
<span style="color:Red; availableStockCalc<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; P-A-B-F<span style="color:Black; "
<span style="color:Red; forecastShippingFactor<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; "
<span style="color:Red; useRollup<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; true<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; Companies<span style="color:Blue; >

<span style="color:Blue; <<span style="color:#A31515; CompanyData<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; co1Public<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; key<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; HistoryTypeSale<span style="color:Black; " <span style="color:Red; value<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; SALE<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; key<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; SerialBillWarehouse<span style="color:Black; " <span style="color:Red; value<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; zz<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; co1Public<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; co1Private<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; key<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; DatabaseCollation<span style="color:Black; " <span style="color:Red; value<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; LATIN1_GENERAL_BIN<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; key<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; FreeStockCalc<span style="color:Black; " <span style="color:Red; value<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; P-A<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; key<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; ForecastShippingFactor<span style="color:Black; " <span style="color:Red; value<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; key<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; AvailableStockCalc<span style="color:Black; " <span style="color:Red; value<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; P-A-B-F<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; key<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; useRollup<span style="color:Black; " <span style="color:Red; value<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; True<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; co1Private<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; co2Public<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; key<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; HistoryTypeSale<span style="color:Black; " <span style="color:Red; value<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; SALE<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; key<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; SerialBillWarehouse<span style="color:Black; " <span style="color:Red; value<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; zz<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; co2Public<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; co2Private<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; key<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; DatabaseCollation<span style="color:Black; " <span style="color:Red; value<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; LATIN1_GENERAL_BIN<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; key<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; FreeStockCalc<span style="color:Black; " <span style="color:Red; value<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; P-A<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; key<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; ForecastShippingFactor<span style="color:Black; " <span style="color:Red; value<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; key<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; AvailableStockCalc<span style="color:Black; " <span style="color:Red; value<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; P-A-B-F<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; add <span style="color:Red; key<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; useRollup<span style="color:Black; " <span style="color:Red; value<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; True<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; co2Private<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; CompanyData<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; configuration<span style="color:Blue; >
[/code]
I hope to be able to remove the <CompanyData> group but im having difficulty in exposing the elements in the new <Companies> section according to their scope (Public/Private). What I have done is create a class named CompanyElement.cs that
acquires these properties and exposes them all. But I only realy want it to expose the Private ones if its called internally e.g. not public. To try to do this I have overloaded the constructor to accept an argument of public or private (Enum) with the hope
that since CompanyElement.cs is internal then I can only create this class from within one of my own projects and so I should know what I can expose. But, the public elements are public for a reason and so I need some way of obtaining them and exposing them
to the wider world. I have attempted to do this via yet another class/web service ive named ConfigMethods.cs (see what I mean about it being tricky to set up!).
Heres a copy of each of the classes:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; namespace path.Config
{
<span style="color:Blue; using System;
<span style="color:Blue; using System.Configuration;

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Class controls the list of servers
<span style="color:Gray; /// <span style="color:Gray; </summary>
[ConfigurationCollection(<span style="color:Blue; typeof(ProviderSettings))]
<span style="color:Blue; internal <span style="color:Blue; class CompanyElement : ConfigurationElement
{
<span style="color:Blue; #region Public Enums
<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Describe the permissible web config security section names.
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Blue; public <span style="color:Blue; enum ConfigSection
{
<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; The private web config security elements.
<span style="color:Gray; /// <span style="color:Gray; </summary>
Private,

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; The public web config security elements.
<span style="color:Gray; /// <span style="color:Gray; </summary>
Public
}
<span style="color:Blue; #endregion

<span style="color:Blue; #region Private member variables
<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; The formula used to calculate available stock.
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Blue; private ConfigurationProperty m_availableStockCalc;

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; The database collation used by this company.
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Blue; private ConfigurationProperty m_databaseCollation;

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; The formula used to calculate free stock.
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Blue; private ConfigurationProperty m_freeStockCalc;

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; The number of days to add to an orders required date to allow for shipping.
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Blue; private ConfigurationProperty m_forecastShippingFactor;

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; The string used to identify sale types in history records.
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Blue; private ConfigurationProperty m_historyTypeSale;

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; The name of the company.
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Blue; private ConfigurationProperty m_name;

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; The string used to denote the serial bill warehouse.
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Blue; private ConfigurationProperty m_serialBillWarehouse;

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Should bundles be rolled up?
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Blue; private ConfigurationProperty m_useRollup;
<span style="color:Blue; #endregion Private member variables

<span style="color:Blue; #region Constructors
<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Initializes a new instance of the CompanyElement class.
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Blue; public CompanyElement()
{
<span style="color:Blue; this.m_availableStockCalc = <span style="color:Blue; new ConfigurationProperty(<span style="color:#A31515; "availableStockCalc", <span style="color:Blue; typeof(String), String.Empty, ConfigurationPropertyOptions.IsRequired);
<span style="color:Blue; this.m_databaseCollation = <span style="color:Blue; new ConfigurationProperty(<span style="color:#A31515; "databaseCollation", <span style="color:Blue; typeof(String), String.Empty, ConfigurationPropertyOptions.IsRequired);
<span style="color:Blue; this.m_freeStockCalc = <span style="color:Blue; new ConfigurationProperty(<span style="color:#A31515; "freeStockCalc", <span style="color:Blue; typeof(String), String.Empty, ConfigurationPropertyOptions.IsRequired);
<span style="color:Blue; this.m_forecastShippingFactor = <span style="color:Blue; new ConfigurationProperty(<span style="color:#A31515; "forecastShippingFactor", <span style="color:Blue; typeof(Int32), 0, ConfigurationPropertyOptions.IsRequired);
<span style="color:Blue; this.m_historyTypeSale = <span style="color:Blue; new ConfigurationProperty(<span style="color:#A31515; "historyTypeSale", <span style="color:Blue; typeof(String), String.Empty, ConfigurationPropertyOptions.IsRequired);
<span style="color:Blue; this.m_name = <span style="color:Blue; new ConfigurationProperty(<span style="color:#A31515; "name", <span style="color:Blue; typeof(String), String.Empty, ConfigurationPropertyOptions.IsKey);
<span style="color:Blue; this.m_serialBillWarehouse = <span style="color:Blue; new ConfigurationProperty(<span style="color:#A31515; "serialBillWarehouse", <span style="color:Blue; typeof(String), String.Empty, ConfigurationPropertyOptions.IsRequired);
<span style="color:Blue; this.m_useRollup = <span style="color:Blue; new ConfigurationProperty(<span style="color:#A31515; "useRollup", <span style="color:Blue; typeof(Boolean), <span style="color:Blue; true, ConfigurationPropertyOptions.IsRequired);
}

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Initializes a new instance of the CompanyElement class permitting selection of element scope.
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Blue; public CompanyElement(ConfigSection scope)
{
<span style="color:Blue; this.m_historyTypeSale = <span style="color:Blue; new ConfigurationProperty(<span style="color:#A31515; "historyTypeSale", <span style="color:Blue; typeof(String), String.Empty, ConfigurationPropertyOptions.IsRequired);
<span style="color:Blue; this.m_name = <span style="color:Blue; new ConfigurationProperty(<span style="color:#A31515; "name", <span style="color:Blue; typeof(String), String.Empty, ConfigurationPropertyOptions.IsKey);
<span style="color:Blue; this.m_serialBillWarehouse = <span style="color:Blue; new ConfigurationProperty(<span style="color:#A31515; "serialBillWarehouse", <span style="color:Blue; typeof(String), String.Empty, ConfigurationPropertyOptions.IsRequired);

<span style="color:Blue; if (scope == ConfigSection.Private)
{
<span style="color:Blue; this.m_availableStockCalc = <span style="color:Blue; new ConfigurationProperty(<span style="color:#A31515; "availableStockCalc", <span style="color:Blue; typeof(String), String.Empty, ConfigurationPropertyOptions.IsRequired);
<span style="color:Blue; this.m_databaseCollation = <span style="color:Blue; new ConfigurationProperty(<span style="color:#A31515; "databaseCollation", <span style="color:Blue; typeof(String), String.Empty, ConfigurationPropertyOptions.IsRequired);
<span style="color:Blue; this.m_freeStockCalc = <span style="color:Blue; new ConfigurationProperty(<span style="color:#A31515; "freeStockCalc", <span style="color:Blue; typeof(String), String.Empty, ConfigurationPropertyOptions.IsRequired);
<span style="color:Blue; this.m_forecastShippingFactor = <span style="color:Blue; new ConfigurationProperty(<span style="color:#A31515; "forecastShippingFactor", <span style="color:Blue; typeof(Int32), 0, ConfigurationPropertyOptions.IsRequired);
<span style="color:Blue; this.m_useRollup = <span style="color:Blue; new ConfigurationProperty(<span style="color:#A31515; "useRollup", <span style="color:Blue; typeof(Boolean), <span style="color:Blue; true, ConfigurationPropertyOptions.IsRequired);
}
}
<span style="color:Blue; #endregion Constructors

<span style="color:Blue; #region Internal methods
<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Gets or sets the calculation used to calculate available stock.
<span style="color:Gray; /// <span style="color:Gray; </summary>
[ConfigurationProperty(<span style="color:#A31515; "availableStockCalc", IsRequired = <span style="color:Blue; true, DefaultValue = <span style="color:#A31515; "P-A-B-F")]
<span style="color:Blue; internal String AvailableStockCalc
{
<span style="color:Blue; get { <span style="color:Blue; return (String)<span style="color:Blue; base[<span style="color:Blue; this.m_availableStockCalc]; }
<span style="color:Blue; set { <span style="color:Blue; base[<span style="color:Blue; this.m_availableStockCalc] = value; }
}

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Gets or sets the string used to identify the companies database colation.
<span style="color:Gray; /// <span style="color:Gray; </summary>
[ConfigurationProperty(<span style="color:#A31515; "databaseCollation", IsRequired = <span style="color:Blue; true, DefaultValue = <span style="color:#A31515; "")]
<span style="color:Blue; internal String DatabaseCollation
{
<span style="color:Blue; get { <span style="color:Blue; return (String)<span style="color:Blue; base[<span style="color:Blue; this.m_databaseCollation]; }
<span style="color:Blue; set { <span style="color:Blue; base[<span style="color:Blue; this.m_databaseCollation] = value; }
}

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Gets or sets the calculation used to calculate free stock.
<span style="color:Gray; /// <span style="color:Gray; </summary>
[ConfigurationProperty(<span style="color:#A31515; "freeStockCalc", IsRequired = <span style="color:Blue; true, DefaultValue = <span style="color:#A31515; "P-A")]
<span style="color:Blue; internal String FreeStockCalc
{
<span style="color:Blue; get { <span style="color:Blue; return (String)<span style="color:Blue; base[<span style="color:Blue; this.m_freeStockCalc]; }
<span style="color:Blue; set { <span style="color:Blue; base[<span style="color:Blue; this.m_freeStockCalc] = value; }
}

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Gets or sets the value to add to a required date to allow for shipping time.
<span style="color:Gray; /// <span style="color:Gray; </summary>
[ConfigurationProperty(<span style="color:#A31515; "forecastShippingFactor", IsRequired = <span style="color:Blue; true, DefaultValue = 0)]
<span style="color:Blue; internal Int32 ForecastShippingFactor
{
<span style="color:Blue; get { <span style="color:Blue; return (Int32)<span style="color:Blue; base[<span style="color:Blue; this.m_forecastShippingFactor]; }
<span style="color:Blue; set { <span style="color:Blue; base[<span style="color:Blue; this.m_forecastShippingFactor] = value; }
}

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Gets or sets the string used to identify sales in history.
<span style="color:Gray; /// <span style="color:Gray; </summary>
[ConfigurationProperty(<span style="color:#A31515; "historyTypeSale", IsRequired = <span style="color:Blue; true, DefaultValue = <span style="color:#A31515; "SALE")]
<span style="color:Blue; internal String HistoryTypeSale
{
<span style="color:Blue; get { <span style="color:Blue; return (String)<span style="color:Blue; base[<span style="color:Blue; this.m_historyTypeSale]; }
<span style="color:Blue; set { <span style="color:Blue; base[<span style="color:Blue; this.m_historyTypeSale] = value; }
}

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Gets or sets the name of the company
<span style="color:Gray; /// <span style="color:Gray; </summary>
[ConfigurationProperty(<span style="color:#A31515; "name", IsRequired = <span style="color:Blue; true, DefaultValue = <span style="color:#A31515; "")]
<span style="color:Blue; internal String Name
{
<span style="color:Blue; get { <span style="color:Blue; return (String)<span style="color:Blue; base[<span style="color:Blue; this.m_name]; }
<span style="color:Blue; set { <span style="color:Blue; base[<span style="color:Blue; this.m_name] = value; }
}

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Gets or sets the string used to identify the serial bill warehouse.
<span style="color:Gray; /// <span style="color:Gray; </summary>
[ConfigurationProperty(<span style="color:#A31515; "serialBillWarehouse", IsRequired = <span style="color:Blue; true, DefaultValue = <span style="color:#A31515; "zz")]
<span style="color:Blue; internal String SerialBillWarehouse
{
<span style="color:Blue; get { <span style="color:Blue; return (String)<span style="color:Blue; base[<span style="color:Blue; this.m_serialBillWarehouse]; }
<span style="color:Blue; set { <span style="color:Blue; base[<span style="color:Blue; this.m_serialBillWarehouse] = value; }
}

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Gets or sets the printer the advice note is sent to
<span style="color:Gray; /// <span style="color:Gray; </summary>
[ConfigurationProperty(<span style="color:#A31515; "useRollup", IsRequired = <span style="color:Blue; true, DefaultValue = <span style="color:Blue; true)]
<span style="color:Blue; internal Boolean UseRollup
{
<span style="color:Blue; get { <span style="color:Blue; return (Boolean)<span style="color:Blue; base[<span style="color:Blue; this.m_useRollup]; }
<span style="color:Blue; set { <span style="color:Blue; base[<span style="color:Blue; this.m_useRollup] = value; }
}
<span style="color:Blue; #endregion Internal methods
}
}

[/code]
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; namespace path.Stock
{
<span style="color:Blue; using System;
<span style="color:Blue; using System.Collections.Generic;
<span style="color:Blue; using System.Collections.Specialized;
<span style="color:Blue; using System.Configuration;
<span style="color:Blue; using System.Web.Services;
<span style="color:Blue; using System.Xml.Serialization;

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; The ConfigMethods web service.
<span style="color:Gray; /// <span style="color:Gray; </summary>
[WebService(Namespace = <span style="color:#A31515; "http://path.Stock")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
<span style="color:Blue; public <span style="color:Blue; class ConfigMethods : System.Web.Services.WebService
{
<span style="color:Blue; #region Public Methods

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Return a list of Extented Property objects.
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Gray; /// <span style="color:Gray; <param name="company <span style="color:Green; The company.</param>
<span style="color:Gray; /// <span style="color:Gray; <returns><span style="color:Green; A list of Extented Property objects.</returns>
[WebMethod]
[XmlInclude(<span style="color:Blue; typeof(ExtendedPropertiesFull))]
<span style="color:Blue; public List<ExtendedPropertiesFull> GetCompanyConfigData(String company)
{
List<ExtendedPropertiesFull> extendedProperties = GetCompanyConfigData(company, Config.CompanyElement.ConfigSection.Public);
<span style="color:Blue; return extendedProperties;
}

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Find if a public key is set to true in the web config file.
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Gray; /// <span style="color:Gray; <param name="company <span style="color:Green; The company name.</param>
<span style="color:Gray; /// <span style="color:Gray; <param name="key <span style="color:Green; The key name you wish to find a value for.</param>
<span style="color:Gray; /// <span style="color:Gray; <returns><span style="color:Green; A true or false value for the key.</returns>
[WebMethod]
[XmlInclude(<span style="color:Blue; typeof(Boolean))]
<span style="color:Blue; public Boolean CompanySettingIsTrue(String company, String key)
{
List<ExtendedPropertiesFull> extendedProperties = <span style="color:Blue; new List<ExtendedPropertiesFull>(GetCompanyConfigData(company, Config.CompanyElement.ConfigSection.Public));

<span style="color:Blue; foreach (ExtendedPropertiesFull setting <span style="color:Blue; in extendedProperties)
{
<span style="color:Blue; if (setting.Property.ToUpper() == key.ToUpper())
{
<span style="color:Blue; if (setting.Value.ToUpper() == <span style="color:#A31515; "TRUE")
{
<span style="color:Blue; return <span style="color:Blue; true;
}
<span style="color:Blue; else
{
<span style="color:Blue; return <span style="color:Blue; false;
}
}
}

<span style="color:Blue; return <span style="color:Blue; false;
}
<span style="color:Blue; #endregion

<span style="color:Blue; #region Internal Methods
<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Return a list of all values the web config for a specified company and section.
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Gray; /// <span style="color:Gray; <param name="company <span style="color:Green; The company to look in.</param>
<span style="color:Gray; /// <span style="color:Gray; <param name="section <span style="color:Green; The security section to look in.</param>
<span style="color:Gray; /// <span style="color:Gray; <returns><span style="color:Green; A list of key value pairs.</returns>
<span style="color:Blue; internal <span style="color:Blue; static List<ExtendedPropertiesFull> GetCompanyConfigData(String company, Config.CompanyElement.ConfigSection scope)
{
Config.CompanyElement companyElements = Config.CompanySection.GetCompanySection(company, scope);
List<ExtendedPropertiesFull> extendedProperties = <span style="color:Blue; new List<ExtendedPropertiesFull>();
<span style="color:Blue; foreach (String key <span style="color:Blue; in companyElements)
{
extendedProperties.Add(<span style="color:Blue; new ExtendedPropertiesFull(key.ToString(), companyWebConfigData.Get(key)));
}

<span style="color:Blue; return extendedProperties;
}

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Return the value of a single web config key from a specific company and section.
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Gray; /// <span style="color:Gray; <param name="company <span style="color:Green; The company to look at.</param>
<span style="color:Gray; /// <span style="color:Gray; <param name="key <span style="color:Green; The key to look for.</param>
<span style="color:Gray; /// <span style="color:Gray; <param name="section <span style="color:Green; The security section to look in.</param>
<span style="color:Gray; /// <span style="color:Gray; <returns><span style="color:Green; The value if found or null if not.</returns>
<span style="color:Blue; internal <span style="color:Blue; static String CompanySettingValue(String company, String key, Config.CompanyElement.ConfigSection scope)
{
NameValueCollection companyWebConfigData = (NameValueCollection)ConfigurationManager.GetSection(<span style="color:#A31515; "CompanyData/" + company.ToLower() + scope);
String configValue = companyWebConfigData[key];
<span style="color:Blue; return configValue;
}

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Return the value of a single web config key from a specific company and section.
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Gray; /// <span style="color:Gray; <param name="company <span style="color:Green; The company to look at.</param>
<span style="color:Gray; /// <span style="color:Gray; <param name="key <span style="color:Green; The key to look for.</param>
<span style="color:Gray; /// <span style="color:Gray; <returns><span style="color:Green; The value if found or null if not.</returns>
<span style="color:Blue; internal <span style="color:Blue; static String CompanySettingValue(String company, String key)
{
Config.CompanyElement companyConfigSection = Config.CompanySection.GetCompanySection(company.ToLower());
String configValue = companyConfigSection[key];
<span style="color:Blue; return configValue;
}
<span style="color:Blue; #endregion
}
}

[/code]
I appologise for the state of the code as its part way through conversion, but I hope it will be sufficient to give an idea of what im trying to do.<br/>
In short, ive got myself into a bit of a mess and would appreciate someone guiding me in the right direction. I believe that what I would ideally like is a way of exposing public elements from the web.config to anyone who wants them and restricting private
ones for internal use only.
Cheers,
Mike


View the full article
 
Back
Top