diff options
author | Atsushi Eno <atsushieno@gmail.com> | 2007-01-18 07:17:22 +0300 |
---|---|---|
committer | Atsushi Eno <atsushieno@gmail.com> | 2007-01-18 07:17:22 +0300 |
commit | e9156bb4b89d647f51b40777ef7f2efca3d6483b (patch) | |
tree | 265ccc0462bd6d9ea7fbc26d497667359074debc /mcs/class/System/System.Diagnostics/DiagnosticsConfigurationHandler.cs | |
parent | 153893ccb948f4e7b57e0b0718b3fc01e481e597 (diff) |
2007-01-18 Atsushi Enomoto <atsushi@ximian.com>
* System.dll.sources: added new sources:
TraceSource.cs, SourceLevels.cs, CorrelationManager.cs,
TraceEventCache.cs, TraceEventType.cs and SourceSwitch.cs.
* System_test.dll.sources: added new tests:
TraceSourceTest.cs and SourceSwitchTest.cs.
* Switch.cs : added missing .ctor(), Attributes, Value,
GetSupportedAttributes() and OnValueChanged().
* DiagnosticsConfigurationHandler.cs : added some hacky handler for
new "sources" element. Don't wrap another ConfigurationException.
* TraceListener.cs : added missing trace methods.
* TraceSource.cs, SourceLevels.cs, CorrelationManager.cs,
TraceEventCache.cs, TraceEventType.cs, SourceSwitch.cs:
added missing 2.0 stuff, mostly just stubs.
* TraceSourceTest.cs, SourceSwitchTest.cs : new tests.
* SwitchesTest.cs : added test for GetSupportedAttributes().
svn path=/trunk/mcs/; revision=71238
Diffstat (limited to 'mcs/class/System/System.Diagnostics/DiagnosticsConfigurationHandler.cs')
-rw-r--r-- | mcs/class/System/System.Diagnostics/DiagnosticsConfigurationHandler.cs | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/mcs/class/System/System.Diagnostics/DiagnosticsConfigurationHandler.cs b/mcs/class/System/System.Diagnostics/DiagnosticsConfigurationHandler.cs index 18fc781a396..8dd3ff9225e 100644 --- a/mcs/class/System/System.Diagnostics/DiagnosticsConfigurationHandler.cs +++ b/mcs/class/System/System.Diagnostics/DiagnosticsConfigurationHandler.cs @@ -33,6 +33,7 @@ // using System; using System.Collections; +using System.Collections.Specialized; using System.Configuration; using System.Threading; #if (XML_DEP) @@ -82,6 +83,9 @@ namespace System.Diagnostics elementHandlers ["assert"] = new ElementHandler (AddAssertNode); elementHandlers ["switches"] = new ElementHandler (AddSwitchesNode); elementHandlers ["trace"] = new ElementHandler (AddTraceNode); +#if NET_2_0 + elementHandlers ["sources"] = new ElementHandler (AddSourcesNode); +#endif } public virtual object Create (object parent, object configContext, XmlNode section) @@ -248,6 +252,9 @@ namespace System.Diagnostics d ["indentsize"] = n; TraceImpl.IndentSize = n; } + catch (ConfigurationException e) { + throw; + } catch (Exception e) { throw new ConfigurationException ("The `indentsize' attribute must be an integral value.", e, node); @@ -255,6 +262,82 @@ namespace System.Diagnostics } } +#if NET_2_0 + static readonly Hashtable static_sources = new Hashtable (); + + private void AddSourcesNode (IDictionary d, XmlNode node) + { + // FIXME: are there valid attributes? + ValidateInvalidAttributes (node.Attributes, node); + Hashtable sources = d ["sources"] as Hashtable; + if (sources == null) { + sources = new Hashtable (); + d ["sources"] = sources; + } + // FIXME: here I replace the table with fake static variable. + sources = static_sources; + + foreach (XmlNode child in node.ChildNodes) { + XmlNodeType t = child.NodeType; + if (t == XmlNodeType.Whitespace || t == XmlNodeType.Comment) + continue; + if (t == XmlNodeType.Element) { + if (child.Name == "source") + AddTraceSource (sources, child); + else + ThrowUnrecognizedElement (child); +// ValidateInvalidAttributes (child.Attributes, child); + } + else + ThrowUnrecognizedNode (child); + } + } + + private void AddTraceSource (Hashtable sources, XmlNode node) + { + string name = null; + SourceLevels levels = SourceLevels.Error; + StringDictionary atts = new StringDictionary (); + foreach (XmlAttribute a in node.Attributes) { + switch (a.Name) { + case "name": + name = a.Value; + break; + case "switchValue": + levels = (SourceLevels) Enum.Parse (typeof (SourceLevels), a.Value); + break; + default: + atts [a.Name] = a.Value; + break; + } + } + if (name == null) + throw new ConfigurationException ("Mandatory attribute 'name' is missing in 'source' element."); + + // FIXME: it should raise an error for duplicate name sources. + if (sources.ContainsKey (name)) + return; + + TraceSource source = new TraceSource (name, levels); + sources.Add (source.Name, source); + + foreach (XmlNode child in node.ChildNodes) { + XmlNodeType t = child.NodeType; + if (t == XmlNodeType.Whitespace || t == XmlNodeType.Comment) + continue; + if (t == XmlNodeType.Element) { + if (child.Name == "listeners") + AddTraceListeners (child); + else + ThrowUnrecognizedElement (child); + ValidateInvalidAttributes (child.Attributes, child); + } + else + ThrowUnrecognizedNode (child); + } + } +#endif + // only defines "add" and "remove", but "clear" also works // for add, "name" and "type" are required; initializeData is optional private void AddTraceListeners (XmlNode listenersNode) |