Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / CompMod / System / Diagnostics / Switch.cs / 1 / Switch.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
*/
namespace System.Diagnostics {
using System;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.Configuration;
using System.Xml.Serialization;
///
/// Provides an base class to
/// create new debugging and tracing switches.
///
public abstract class Switch {
private SwitchElementsCollection switchSettings;
private string description;
private string displayName;
private int switchSetting = 0;
private bool initialized = false;
private bool initializing = false;
private string switchValueString = String.Empty;
private StringDictionary attributes;
private string defaultValue;
private static List switches = new List();
///
/// Initializes a new instance of the
/// class.
///
protected Switch(string displayName, string description) : this(displayName, description, "0") {
}
protected Switch(string displayName, string description, string defaultSwitchValue) {
// displayName is used as a hashtable key, so it can never
// be null.
if (displayName == null) displayName = string.Empty;
this.displayName = displayName;
this.description = description;
lock (switches) {
switches.Add(new WeakReference(this));
}
defaultValue = defaultSwitchValue;
}
[XmlIgnore]
public StringDictionary Attributes {
get {
Initialize();
if (attributes == null)
attributes = new StringDictionary();
return attributes;
}
}
///
/// Gets a name used to identify the switch.
///
public string DisplayName {
get {
return displayName;
}
}
///
/// Gets a description of the switch.
///
public string Description {
get {
return (description == null) ? string.Empty : description;
}
}
///
///
/// Indicates the current setting for this switch.
///
///
protected int SwitchSetting {
get {
if (!initialized) {
if (!InitializeWithStatus())
return 0;
OnSwitchSettingChanged();
}
return switchSetting;
}
set {
initialized = true;
if (switchSetting != value) {
switchSetting = value;
OnSwitchSettingChanged();
}
}
}
protected string Value {
get {
Initialize();
return switchValueString;
}
set {
Initialize();
switchValueString = value;
try {
OnValueChanged();
}
catch (ArgumentException e) {
throw new ConfigurationErrorsException(SR.GetString(SR.BadConfigSwitchValue, DisplayName), e);
}
catch (FormatException e) {
throw new ConfigurationErrorsException(SR.GetString(SR.BadConfigSwitchValue, DisplayName), e);
}
catch (OverflowException e) {
throw new ConfigurationErrorsException(SR.GetString(SR.BadConfigSwitchValue, DisplayName), e);
}
}
}
private void Initialize() {
InitializeWithStatus();
}
private bool InitializeWithStatus() {
if (!initialized) {
if (initializing)
return false;
initializing = true;
if (switchSettings == null) {
if (!InitializeConfigSettings())
return false;
}
if (switchSettings != null) {
SwitchElement mySettings = switchSettings[displayName];
if (mySettings != null) {
string value = mySettings.Value;
if (value != null) {
this.Value = value;
}
else
this.Value = defaultValue;
try {
TraceUtils.VerifyAttributes(mySettings.Attributes, GetSupportedAttributes(), this);
}
catch (ConfigurationException) {
// if VerifyAttributes throws, clean up a little bit so we're not in a bad state.
initialized = false;
initializing = false;
throw;
}
attributes = new StringDictionary();
attributes.contents = mySettings.Attributes;
}
else {
// We don't use the property here because we don't want to catch exceptions
// and rethrow them as ConfigurationException. In this case there's no config.
switchValueString = defaultValue;
OnValueChanged();
}
}
else {
// We don't use the property here because we don't want to catch exceptions
// and rethrow them as ConfigurationException. In this case there's no config.
switchValueString = defaultValue;
OnValueChanged();
}
initialized = true;
initializing = false;
}
return true;
}
private bool InitializeConfigSettings() {
if (switchSettings != null)
return true;
if (!DiagnosticsConfiguration.CanInitialize())
return false;
// This hashtable is case-insensitive.
switchSettings = DiagnosticsConfiguration.SwitchSettings;
return true;
}
virtual protected internal string[] GetSupportedAttributes() {
return null;
}
///
/// This method is invoked when a switch setting has been changed. It will
/// be invoked the first time a switch reads its value from the registry
/// or environment, and then it will be invoked each time the switch's
/// value is changed.
///
protected virtual void OnSwitchSettingChanged() {
}
protected virtual void OnValueChanged() {
SwitchSetting = Int32.Parse(Value, CultureInfo.InvariantCulture);
}
internal static void RefreshAll() {
lock (switches) {
for (int i=0; i
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
*/
namespace System.Diagnostics {
using System;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.Configuration;
using System.Xml.Serialization;
///
/// Provides an base class to
/// create new debugging and tracing switches.
///
public abstract class Switch {
private SwitchElementsCollection switchSettings;
private string description;
private string displayName;
private int switchSetting = 0;
private bool initialized = false;
private bool initializing = false;
private string switchValueString = String.Empty;
private StringDictionary attributes;
private string defaultValue;
private static List switches = new List();
///
/// Initializes a new instance of the
/// class.
///
protected Switch(string displayName, string description) : this(displayName, description, "0") {
}
protected Switch(string displayName, string description, string defaultSwitchValue) {
// displayName is used as a hashtable key, so it can never
// be null.
if (displayName == null) displayName = string.Empty;
this.displayName = displayName;
this.description = description;
lock (switches) {
switches.Add(new WeakReference(this));
}
defaultValue = defaultSwitchValue;
}
[XmlIgnore]
public StringDictionary Attributes {
get {
Initialize();
if (attributes == null)
attributes = new StringDictionary();
return attributes;
}
}
///
/// Gets a name used to identify the switch.
///
public string DisplayName {
get {
return displayName;
}
}
///
/// Gets a description of the switch.
///
public string Description {
get {
return (description == null) ? string.Empty : description;
}
}
///
///
/// Indicates the current setting for this switch.
///
///
protected int SwitchSetting {
get {
if (!initialized) {
if (!InitializeWithStatus())
return 0;
OnSwitchSettingChanged();
}
return switchSetting;
}
set {
initialized = true;
if (switchSetting != value) {
switchSetting = value;
OnSwitchSettingChanged();
}
}
}
protected string Value {
get {
Initialize();
return switchValueString;
}
set {
Initialize();
switchValueString = value;
try {
OnValueChanged();
}
catch (ArgumentException e) {
throw new ConfigurationErrorsException(SR.GetString(SR.BadConfigSwitchValue, DisplayName), e);
}
catch (FormatException e) {
throw new ConfigurationErrorsException(SR.GetString(SR.BadConfigSwitchValue, DisplayName), e);
}
catch (OverflowException e) {
throw new ConfigurationErrorsException(SR.GetString(SR.BadConfigSwitchValue, DisplayName), e);
}
}
}
private void Initialize() {
InitializeWithStatus();
}
private bool InitializeWithStatus() {
if (!initialized) {
if (initializing)
return false;
initializing = true;
if (switchSettings == null) {
if (!InitializeConfigSettings())
return false;
}
if (switchSettings != null) {
SwitchElement mySettings = switchSettings[displayName];
if (mySettings != null) {
string value = mySettings.Value;
if (value != null) {
this.Value = value;
}
else
this.Value = defaultValue;
try {
TraceUtils.VerifyAttributes(mySettings.Attributes, GetSupportedAttributes(), this);
}
catch (ConfigurationException) {
// if VerifyAttributes throws, clean up a little bit so we're not in a bad state.
initialized = false;
initializing = false;
throw;
}
attributes = new StringDictionary();
attributes.contents = mySettings.Attributes;
}
else {
// We don't use the property here because we don't want to catch exceptions
// and rethrow them as ConfigurationException. In this case there's no config.
switchValueString = defaultValue;
OnValueChanged();
}
}
else {
// We don't use the property here because we don't want to catch exceptions
// and rethrow them as ConfigurationException. In this case there's no config.
switchValueString = defaultValue;
OnValueChanged();
}
initialized = true;
initializing = false;
}
return true;
}
private bool InitializeConfigSettings() {
if (switchSettings != null)
return true;
if (!DiagnosticsConfiguration.CanInitialize())
return false;
// This hashtable is case-insensitive.
switchSettings = DiagnosticsConfiguration.SwitchSettings;
return true;
}
virtual protected internal string[] GetSupportedAttributes() {
return null;
}
///
/// This method is invoked when a switch setting has been changed. It will
/// be invoked the first time a switch reads its value from the registry
/// or environment, and then it will be invoked each time the switch's
/// value is changed.
///
protected virtual void OnSwitchSettingChanged() {
}
protected virtual void OnValueChanged() {
SwitchSetting = Int32.Parse(Value, CultureInfo.InvariantCulture);
}
internal static void RefreshAll() {
lock (switches) {
for (int i=0; i
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- FormatConvertedBitmap.cs
- MetadataException.cs
- UserPreferenceChangedEventArgs.cs
- UnconditionalPolicy.cs
- PlanCompilerUtil.cs
- SmiConnection.cs
- externdll.cs
- MenuCommand.cs
- DataStorage.cs
- EUCJPEncoding.cs
- EntityClassGenerator.cs
- NamedPermissionSet.cs
- TypedTableBase.cs
- TimelineClockCollection.cs
- SecureEnvironment.cs
- CodeTypeParameter.cs
- MappingException.cs
- PackagePartCollection.cs
- GridViewActionList.cs
- SqlOuterApplyReducer.cs
- ShadowGlyph.cs
- DecoderExceptionFallback.cs
- TemplateBamlTreeBuilder.cs
- XmlSchemaException.cs
- ApplicationBuildProvider.cs
- FormatException.cs
- FaultPropagationRecord.cs
- SignatureToken.cs
- ReaderOutput.cs
- DataViewManager.cs
- Literal.cs
- CalloutQueueItem.cs
- BitArray.cs
- BitStack.cs
- FieldCollectionEditor.cs
- XmlSchemaObjectTable.cs
- InheritanceAttribute.cs
- PageBreakRecord.cs
- PeerNameRecord.cs
- ServiceHttpModule.cs
- CollectionsUtil.cs
- CollectionConverter.cs
- Variable.cs
- XMLUtil.cs
- CharUnicodeInfo.cs
- CharacterBufferReference.cs
- FileInfo.cs
- RuleSettingsCollection.cs
- SvcMapFileSerializer.cs
- TextParagraphView.cs
- SchemaTableColumn.cs
- TerminatorSinks.cs
- HtmlFormAdapter.cs
- StoreAnnotationsMap.cs
- WebPartMenuStyle.cs
- DoubleAnimationBase.cs
- BitStack.cs
- UxThemeWrapper.cs
- SpotLight.cs
- srgsitem.cs
- PageParser.cs
- DesignerOptionService.cs
- ProxySimple.cs
- Flattener.cs
- IpcClientChannel.cs
- WebPartConnectionsConfigureVerb.cs
- ListControlBuilder.cs
- EncodingTable.cs
- AdornedElementPlaceholder.cs
- ContainerVisual.cs
- RtfToken.cs
- CustomErrorsSectionWrapper.cs
- CodeMemberProperty.cs
- DataGridRowsPresenter.cs
- CompilerGeneratedAttribute.cs
- StylusPoint.cs
- ProfileProvider.cs
- PeerNameRecord.cs
- CollectionView.cs
- ListBoxChrome.cs
- UpdateProgress.cs
- UnionCodeGroup.cs
- ElementAction.cs
- SqlBuffer.cs
- TrustManager.cs
- PassportAuthenticationEventArgs.cs
- HwndKeyboardInputProvider.cs
- StackSpiller.cs
- Opcode.cs
- HtmlImage.cs
- Literal.cs
- EditorPart.cs
- InfoCardRSAOAEPKeyExchangeDeformatter.cs
- SqlIdentifier.cs
- EmptyEnumerator.cs
- WebResourceAttribute.cs
- ApplyTemplatesAction.cs
- TaiwanLunisolarCalendar.cs
- TreeNodeBindingDepthConverter.cs
- RequestCache.cs