Inheritance: System.Configuration.ConfigurationElement
Example #1
0
        protected override ConfigurationElement CreateNewElement()
        {
            SourceElement se = new SourceElement();

            se.Listeners.InitializeDefaultInternal();
            return(se);
        }
Example #2
0
        protected override void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
        {
            base.Unmerge(sourceElement, parentElement, saveMode);
            SourceElement element = sourceElement as SourceElement;

            if ((element != null) && (element._attributes != null))
            {
                this._attributes = element._attributes;
            }
        }
        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;
                }
            }
        }
        protected override void Unmerge(ConfigurationElement sourceElement,
                                        ConfigurationElement parentElement,
                                        ConfigurationSaveMode saveMode)
        {
            base.Unmerge(sourceElement, parentElement, saveMode);

            // Unmerge the optional attributes cache as well
            SourceElement le = sourceElement as SourceElement;

            if ((le != null) && (le._attributes != null))
            {
                this._attributes = le._attributes;
            }
        }
 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;
             }
         }
     }
 }
        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;
                }
            }
        }
 protected override ConfigurationElement CreateNewElement() {
     SourceElement se = new SourceElement();
     se.Listeners.InitializeDefaultInternal();
     return se;
 }
 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;
             }
         }
     }
 }