Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / MIT / System / Web / UI / MobileControls / ControlsConfig.cs / 1305376 / ControlsConfig.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
using System;
using System.Xml;
using System.Diagnostics;
using System.Configuration;
using System.Globalization;
using System.Web;
using System.Web.Configuration;
using System.Collections.Specialized;
using System.Security.Permissions;
namespace System.Web.UI.MobileControls
{
// Mobile Controls Configuration class.
// Includes Mobile Web Forms-specific settings, including a set
// of device configurations, that can be used to decide what set of
// adapters to use for a given device.
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
internal class ControlsConfig
{
private readonly ControlsConfig _parent;
private readonly StringDictionary _settings = new StringDictionary();
private readonly ListDictionary _deviceConfigs = new ListDictionary();
[ConfigurationPermission(SecurityAction.Assert, Unrestricted=true)]
internal static ControlsConfig GetFromContext(HttpContext context)
{
// VSWhidbey 372365: Use MobileControlsSection if it is being returned
Object config = context.GetSection("system.web/mobileControls");
MobileControlsSection controlSection = config as MobileControlsSection;
if (controlSection != null)
{
return controlSection.GetControlsConfig();
}
return (ControlsConfig)config;
}
internal ControlsConfig(ControlsConfig parent)
{
_parent = parent;
}
// Return false if a device of the same name has already been added.
internal /*public*/ bool AddDeviceConfig(String configName, IndividualDeviceConfig deviceConfig)
{
// Note that GetDeviceConfig also walks the parents configs
if (GetDeviceConfig(configName) != null)
{
return false;
}
else
{
_deviceConfigs[configName] = deviceConfig;
return true;
}
}
internal /*public*/ IndividualDeviceConfig GetDeviceConfig(HttpContext context)
{
IndividualDeviceConfig deviceConfig = null;
#if DEBUG
if (context.Session != null)
{
String var = "AdapterOverride";
bool saveInSession = true;
String adapterOverride = (String)context.Session[var];
if (adapterOverride == null)
{
saveInSession = false;
adapterOverride = (String)context.Request.QueryString[var];
}
if (adapterOverride != null &&
(deviceConfig = GetDeviceConfig(adapterOverride)) != null)
{
if (saveInSession)
{
context.Session[var] = adapterOverride;
}
return deviceConfig;
}
}
#endif
foreach (IndividualDeviceConfig candidate in _deviceConfigs.Values)
{
if (candidate.DeviceQualifies(context))
{
deviceConfig = candidate;
break;
}
}
if (deviceConfig == null && _parent != null)
{
deviceConfig = _parent.GetDeviceConfig (context);
}
if (deviceConfig == null)
{
throw new Exception(
SR.GetString(SR.ControlsConfig_NoDeviceConfigRegistered,
context.Request.UserAgent));
}
return deviceConfig;
}
internal /*public*/ IndividualDeviceConfig GetDeviceConfig(String configName)
{
IndividualDeviceConfig deviceConfig = (IndividualDeviceConfig)_deviceConfigs[configName];
if (deviceConfig == null && _parent != null)
{
deviceConfig = _parent.GetDeviceConfig (configName);
}
return deviceConfig;
}
// Call this after all the device configs have been entered. This will
// resolve the names of the parent classes to inherit from actual
// classes, and flag an error if there isn't one. This is done as a
// second-pass because devices earlier in web.config may inherit from
// items later in the web.config. That flexibility is required to get
// the right behavior for device predicates being evaluated in the order
// they appear.
internal void FixupDeviceConfigInheritance(XmlNode configNode)
{
foreach (IndividualDeviceConfig config in _deviceConfigs.Values)
{
config.FixupInheritance(null, configNode);
}
}
internal /*public*/ String this[String key]
{
get
{
String s = _settings[key];
if (s == null && _parent != null)
{
s = _parent[key];
}
return s;
}
set
{
_settings[key] = value;
}
}
internal /*public*/ int SessionStateHistorySize
{
get
{
String sizeString = this["sessionStateHistorySize"];
int size = Constants.DefaultSessionsStateHistorySize;
if (sizeString != null)
{
// Enclose in case a numerical value wasn't provided. In
// which case just return the default.
try
{
size = Int32.Parse(sizeString, CultureInfo.InvariantCulture);
}
catch
{
}
}
return size;
}
}
internal /*public*/ Type CookielessDataDictionaryType
{
get
{
Type cookielessDataType = null;
String typeString = this["cookielessDataDictionaryType"];
if (!String.IsNullOrEmpty(typeString)) {
cookielessDataType = Type.GetType(typeString);
}
return cookielessDataType;
}
}
internal /*public*/ bool AllowCustomAttributes
{
get
{
String allow = this["allowCustomAttributes"];
return String.Compare(allow, "true", StringComparison.OrdinalIgnoreCase) == 0;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
using System;
using System.Xml;
using System.Diagnostics;
using System.Configuration;
using System.Globalization;
using System.Web;
using System.Web.Configuration;
using System.Collections.Specialized;
using System.Security.Permissions;
namespace System.Web.UI.MobileControls
{
// Mobile Controls Configuration class.
// Includes Mobile Web Forms-specific settings, including a set
// of device configurations, that can be used to decide what set of
// adapters to use for a given device.
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
internal class ControlsConfig
{
private readonly ControlsConfig _parent;
private readonly StringDictionary _settings = new StringDictionary();
private readonly ListDictionary _deviceConfigs = new ListDictionary();
[ConfigurationPermission(SecurityAction.Assert, Unrestricted=true)]
internal static ControlsConfig GetFromContext(HttpContext context)
{
// VSWhidbey 372365: Use MobileControlsSection if it is being returned
Object config = context.GetSection("system.web/mobileControls");
MobileControlsSection controlSection = config as MobileControlsSection;
if (controlSection != null)
{
return controlSection.GetControlsConfig();
}
return (ControlsConfig)config;
}
internal ControlsConfig(ControlsConfig parent)
{
_parent = parent;
}
// Return false if a device of the same name has already been added.
internal /*public*/ bool AddDeviceConfig(String configName, IndividualDeviceConfig deviceConfig)
{
// Note that GetDeviceConfig also walks the parents configs
if (GetDeviceConfig(configName) != null)
{
return false;
}
else
{
_deviceConfigs[configName] = deviceConfig;
return true;
}
}
internal /*public*/ IndividualDeviceConfig GetDeviceConfig(HttpContext context)
{
IndividualDeviceConfig deviceConfig = null;
#if DEBUG
if (context.Session != null)
{
String var = "AdapterOverride";
bool saveInSession = true;
String adapterOverride = (String)context.Session[var];
if (adapterOverride == null)
{
saveInSession = false;
adapterOverride = (String)context.Request.QueryString[var];
}
if (adapterOverride != null &&
(deviceConfig = GetDeviceConfig(adapterOverride)) != null)
{
if (saveInSession)
{
context.Session[var] = adapterOverride;
}
return deviceConfig;
}
}
#endif
foreach (IndividualDeviceConfig candidate in _deviceConfigs.Values)
{
if (candidate.DeviceQualifies(context))
{
deviceConfig = candidate;
break;
}
}
if (deviceConfig == null && _parent != null)
{
deviceConfig = _parent.GetDeviceConfig (context);
}
if (deviceConfig == null)
{
throw new Exception(
SR.GetString(SR.ControlsConfig_NoDeviceConfigRegistered,
context.Request.UserAgent));
}
return deviceConfig;
}
internal /*public*/ IndividualDeviceConfig GetDeviceConfig(String configName)
{
IndividualDeviceConfig deviceConfig = (IndividualDeviceConfig)_deviceConfigs[configName];
if (deviceConfig == null && _parent != null)
{
deviceConfig = _parent.GetDeviceConfig (configName);
}
return deviceConfig;
}
// Call this after all the device configs have been entered. This will
// resolve the names of the parent classes to inherit from actual
// classes, and flag an error if there isn't one. This is done as a
// second-pass because devices earlier in web.config may inherit from
// items later in the web.config. That flexibility is required to get
// the right behavior for device predicates being evaluated in the order
// they appear.
internal void FixupDeviceConfigInheritance(XmlNode configNode)
{
foreach (IndividualDeviceConfig config in _deviceConfigs.Values)
{
config.FixupInheritance(null, configNode);
}
}
internal /*public*/ String this[String key]
{
get
{
String s = _settings[key];
if (s == null && _parent != null)
{
s = _parent[key];
}
return s;
}
set
{
_settings[key] = value;
}
}
internal /*public*/ int SessionStateHistorySize
{
get
{
String sizeString = this["sessionStateHistorySize"];
int size = Constants.DefaultSessionsStateHistorySize;
if (sizeString != null)
{
// Enclose in case a numerical value wasn't provided. In
// which case just return the default.
try
{
size = Int32.Parse(sizeString, CultureInfo.InvariantCulture);
}
catch
{
}
}
return size;
}
}
internal /*public*/ Type CookielessDataDictionaryType
{
get
{
Type cookielessDataType = null;
String typeString = this["cookielessDataDictionaryType"];
if (!String.IsNullOrEmpty(typeString)) {
cookielessDataType = Type.GetType(typeString);
}
return cookielessDataType;
}
}
internal /*public*/ bool AllowCustomAttributes
{
get
{
String allow = this["allowCustomAttributes"];
return String.Compare(allow, "true", StringComparison.OrdinalIgnoreCase) == 0;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- dbenumerator.cs
- SchemaSetCompiler.cs
- SpanIndex.cs
- ToolStripSystemRenderer.cs
- CalloutQueueItem.cs
- DynamicVirtualDiscoSearcher.cs
- TimerElapsedEvenArgs.cs
- TrackingProfile.cs
- WizardSideBarListControlItem.cs
- WebPartConnectionsConfigureVerb.cs
- BitmapEffectrendercontext.cs
- ClientTargetSection.cs
- EntityDataSourceMemberPath.cs
- RegexInterpreter.cs
- ListViewDataItem.cs
- ToolBar.cs
- PassportPrincipal.cs
- MediaContextNotificationWindow.cs
- MissingMemberException.cs
- DataGridViewRowsRemovedEventArgs.cs
- AppModelKnownContentFactory.cs
- TableDetailsRow.cs
- PropertyInfoSet.cs
- GatewayDefinition.cs
- CustomCategoryAttribute.cs
- IndexingContentUnit.cs
- ModelItemDictionary.cs
- NullReferenceException.cs
- TreeNodeBinding.cs
- Animatable.cs
- DSASignatureFormatter.cs
- FieldBuilder.cs
- DictionaryEntry.cs
- NativeMethods.cs
- SHA1.cs
- ValidationSummaryDesigner.cs
- DrawItemEvent.cs
- SqlClientPermission.cs
- TreeNodeCollection.cs
- ToolboxComponentsCreatedEventArgs.cs
- WinEventQueueItem.cs
- ChildDocumentBlock.cs
- Tuple.cs
- Subordinate.cs
- AttributeSetAction.cs
- AutomationPatternInfo.cs
- _ChunkParse.cs
- UnsafeNativeMethods.cs
- PointLight.cs
- Quad.cs
- ContainerSelectorGlyph.cs
- ResXBuildProvider.cs
- Events.cs
- EdmValidator.cs
- IncrementalCompileAnalyzer.cs
- QilLiteral.cs
- XmlLinkedNode.cs
- MediaContext.cs
- GregorianCalendarHelper.cs
- BitStream.cs
- MouseEventArgs.cs
- SystemThemeKey.cs
- MD5HashHelper.cs
- TTSEngineProxy.cs
- __Filters.cs
- TileBrush.cs
- DBAsyncResult.cs
- CleanUpVirtualizedItemEventArgs.cs
- TextUtf8RawTextWriter.cs
- Volatile.cs
- DataColumn.cs
- FileUpload.cs
- QueryCacheKey.cs
- TraceShell.cs
- PageCatalogPartDesigner.cs
- HtmlImage.cs
- CustomAttribute.cs
- List.cs
- DockEditor.cs
- StringArrayConverter.cs
- ParameterBuilder.cs
- TypeDelegator.cs
- FloaterParagraph.cs
- CqlIdentifiers.cs
- TrackingValidationObjectDictionary.cs
- WebHttpBindingElement.cs
- HwndAppCommandInputProvider.cs
- MenuAutomationPeer.cs
- SingleObjectCollection.cs
- FrameworkTemplate.cs
- DocumentEventArgs.cs
- NotImplementedException.cs
- QueryCoreOp.cs
- IndentedTextWriter.cs
- PasswordBoxAutomationPeer.cs
- ResourceProviderFactory.cs
- ImageField.cs
- DataBoundControl.cs
- WindowsFormsSynchronizationContext.cs
- StringUtil.cs