internal void Refresh() { if (!_initCalled) { Initialize(); return; } SourceElementsCollection sources = DiagnosticsConfiguration.Sources; if (sources != null) { SourceElement sourceElement = sources[Name]; if (sourceElement != null) { // first check if the type changed if ((String.IsNullOrEmpty(sourceElement.SwitchType) && internalSwitch.GetType() != typeof(SourceSwitch)) || (sourceElement.SwitchType != internalSwitch.GetType().AssemblyQualifiedName)) { if (!String.IsNullOrEmpty(sourceElement.SwitchName)) { CreateSwitch(sourceElement.SwitchType, sourceElement.SwitchName); } else { CreateSwitch(sourceElement.SwitchType, Name); if (!String.IsNullOrEmpty(sourceElement.SwitchValue)) { internalSwitch.Level = (SourceLevels)Enum.Parse(typeof(SourceLevels), sourceElement.SwitchValue); } } } else if (!String.IsNullOrEmpty(sourceElement.SwitchName)) { // create a new switch if the name changed, otherwise just refresh. if (sourceElement.SwitchName != internalSwitch.DisplayName) { CreateSwitch(sourceElement.SwitchType, sourceElement.SwitchName); } else { internalSwitch.Refresh(); } } else { // the switchValue changed. Just update our internalSwitch. if (!String.IsNullOrEmpty(sourceElement.SwitchValue)) { internalSwitch.Level = (SourceLevels)Enum.Parse(typeof(SourceLevels), sourceElement.SwitchValue); } else { internalSwitch.Level = SourceLevels.Off; } } TraceListenerCollection newListenerCollection = new TraceListenerCollection(); foreach (ListenerElement listenerElement in sourceElement.Listeners) { TraceListener listener = listeners[listenerElement.Name]; if (listener != null) { newListenerCollection.Add(listenerElement.RefreshRuntimeObject(listener)); } else { newListenerCollection.Add(listenerElement.GetRuntimeObject()); } } TraceUtils.VerifyAttributes(sourceElement.Attributes, GetSupportedAttributes(), this); attributes = new StringDictionary(); attributes.ReplaceHashtable(sourceElement.Attributes); listeners = newListenerCollection; } else { // there was no config, so clear whatever we have. internalSwitch.Level = switchLevel; listeners.Clear(); attributes = null; } } }
private bool InitializeWithStatus() { if (!initialized) { lock (IntializedLock) { if (initialized || initializing) { return(false); } // This method is re-entrent during intitialization, since calls to OnValueChanged() in subclasses could end up having InitializeWithStatus() // called again, we don't want to get caught in an infinite loop. initializing = true; if (switchSettings == null) { if (!InitializeConfigSettings()) { initialized = true; initializing = false; 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.ReplaceHashtable(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); }
internal void OnInitializing() { Initializing?.Invoke(null, new InitializingSwitchEventArgs(this)); TraceUtils.VerifyAttributes(Attributes, GetSupportedAttributes(), this); }
internal void Refresh() { if (!this._initCalled) { this.Initialize(); } else { SourceElementsCollection sources = DiagnosticsConfiguration.Sources; if (sources != null) { SourceElement element = sources[this.Name]; if (element != null) { if ((string.IsNullOrEmpty(element.SwitchType) && (this.internalSwitch.GetType() != typeof(SourceSwitch))) || (element.SwitchType != this.internalSwitch.GetType().AssemblyQualifiedName)) { if (!string.IsNullOrEmpty(element.SwitchName)) { this.CreateSwitch(element.SwitchType, element.SwitchName); } else { this.CreateSwitch(element.SwitchType, this.Name); if (!string.IsNullOrEmpty(element.SwitchValue)) { this.internalSwitch.Level = (SourceLevels)Enum.Parse(typeof(SourceLevels), element.SwitchValue); } } } else if (!string.IsNullOrEmpty(element.SwitchName)) { if (element.SwitchName != this.internalSwitch.DisplayName) { this.CreateSwitch(element.SwitchType, element.SwitchName); } else { this.internalSwitch.Refresh(); } } else if (!string.IsNullOrEmpty(element.SwitchValue)) { this.internalSwitch.Level = (SourceLevels)Enum.Parse(typeof(SourceLevels), element.SwitchValue); } else { this.internalSwitch.Level = SourceLevels.Off; } TraceListenerCollection listeners = new TraceListenerCollection(); foreach (ListenerElement element2 in element.Listeners) { TraceListener listener = this.listeners[element2.Name]; if (listener != null) { listeners.Add(element2.RefreshRuntimeObject(listener)); } else { listeners.Add(element2.GetRuntimeObject()); } } TraceUtils.VerifyAttributes(element.Attributes, this.GetSupportedAttributes(), this); this.attributes = new StringDictionary(); this.attributes.ReplaceHashtable(element.Attributes); this.listeners = listeners; } else { this.internalSwitch.Level = this.switchLevel; this.listeners.Clear(); this.attributes = null; } } } }
internal void SetAttributes(Hashtable attribs) { TraceUtils.VerifyAttributes(attribs, this.GetSupportedAttributes(), this); this.attributes = new StringDictionary(); this.attributes.ReplaceHashtable(attribs); }
private bool InitializeWithStatus() { if (!this.initialized) { lock (this.IntializedLock) { if (this.initialized || this.initializing) { return(false); } this.initializing = true; if ((this.switchSettings == null) && !this.InitializeConfigSettings()) { this.initialized = true; this.initializing = false; return(false); } if (this.switchSettings != null) { SwitchElement element = this.switchSettings[this.displayName]; if (element != null) { string str = element.Value; if (str != null) { this.Value = str; } else { this.Value = this.defaultValue; } try { TraceUtils.VerifyAttributes(element.Attributes, this.GetSupportedAttributes(), this); } catch (ConfigurationException) { this.initialized = false; this.initializing = false; throw; } this.attributes = new StringDictionary(); this.attributes.ReplaceHashtable(element.Attributes); } else { this.switchValueString = this.defaultValue; this.OnValueChanged(); } } else { this.switchValueString = this.defaultValue; this.OnValueChanged(); } this.initialized = true; this.initializing = false; } } return(true); }
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); }