VerifyAttributes() static private method

static private VerifyAttributes ( IDictionary attributes, String supportedAttributes, object parent ) : void
attributes IDictionary
supportedAttributes String
parent object
return void
        internal void SetAttributes(Hashtable attribs)
        {
            TraceUtils.VerifyAttributes(attribs, GetSupportedAttributes(), this);

            attributes          = new StringDictionary();
            attributes.contents = 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 void Initialize()
 {
     if (!this._initCalled)
     {
         lock (this)
         {
             if (!this._initCalled)
             {
                 SourceElementsCollection sources = DiagnosticsConfiguration.Sources;
                 if (sources != null)
                 {
                     SourceElement element = sources[this.sourceName];
                     if (element != null)
                     {
                         if (!string.IsNullOrEmpty(element.SwitchName))
                         {
                             this.CreateSwitch(element.SwitchType, element.SwitchName);
                         }
                         else
                         {
                             this.CreateSwitch(element.SwitchType, this.sourceName);
                             if (!string.IsNullOrEmpty(element.SwitchValue))
                             {
                                 this.internalSwitch.Level = (SourceLevels)Enum.Parse(typeof(SourceLevels), element.SwitchValue);
                             }
                         }
                         this.listeners  = element.Listeners.GetRuntimeObject();
                         this.attributes = new StringDictionary();
                         TraceUtils.VerifyAttributes(element.Attributes, this.GetSupportedAttributes(), this);
                         this.attributes.ReplaceHashtable(element.Attributes);
                     }
                     else
                     {
                         this.NoConfigInit();
                     }
                 }
                 else
                 {
                     this.NoConfigInit();
                 }
                 this._initCalled = true;
             }
         }
     }
 }
Beispiel #4
0
        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;
                }
            }
        }
Beispiel #6
0
 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;
             }
         }
     }
 }
Beispiel #8
0
 internal void SetAttributes(Hashtable attribs)
 {
     TraceUtils.VerifyAttributes(attribs, this.GetSupportedAttributes(), this);
     this.attributes = new StringDictionary();
     this.attributes.ReplaceHashtable(attribs);
 }
Beispiel #9
0
 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);
 }
Beispiel #10
0
        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);
        }