internal void SetAttributes(Hashtable attribs) { TraceUtils.VerifyAttributes(attribs, GetSupportedAttributes(), this); attributes = new StringDictionary(); attributes.ReplaceHashtable(attribs); }
private void Initialize() { if (!_initCalled) { lock(this) { if (_initCalled) return; SourceElementsCollection sourceElements = DiagnosticsConfiguration.Sources; if (sourceElements != null) { SourceElement sourceElement = sourceElements[sourceName]; if (sourceElement != null) { if (!String.IsNullOrEmpty(sourceElement.SwitchName)) { CreateSwitch(sourceElement.SwitchType, sourceElement.SwitchName); } else { CreateSwitch(sourceElement.SwitchType, sourceName); if (!String.IsNullOrEmpty(sourceElement.SwitchValue)) internalSwitch.Level = (SourceLevels) Enum.Parse(typeof(SourceLevels), sourceElement.SwitchValue); } listeners = sourceElement.Listeners.GetRuntimeObject(); attributes = new StringDictionary(); TraceUtils.VerifyAttributes(sourceElement.Attributes, GetSupportedAttributes(), this); attributes.ReplaceHashtable(sourceElement.Attributes); } else NoConfigInit(); } else NoConfigInit(); _initCalled = true; } } }
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 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; } } }