dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] pnetlib/System/Diagnostics DiagnosticsConfiguratio


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] pnetlib/System/Diagnostics DiagnosticsConfigurationHandler.cs, 1.2, 1.3
Date: Tue, 25 Nov 2003 06:22:22 +0000

Update of /cvsroot/dotgnu-pnet/pnetlib/System/Diagnostics
In directory subversions:/tmp/cvs-serv4065/System/Diagnostics

Modified Files:
        DiagnosticsConfigurationHandler.cs 
Log Message:


Signature-compatibility fixes; begin implementating the
diagnostics configuration handler.


Index: DiagnosticsConfigurationHandler.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/System/Diagnostics/DiagnosticsConfigurationHandler.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** DiagnosticsConfigurationHandler.cs  8 Oct 2003 15:29:26 -0000       1.2
--- DiagnosticsConfigurationHandler.cs  25 Nov 2003 06:22:20 -0000      1.3
***************
*** 26,29 ****
--- 26,30 ----
  
  using System;
+ using System.Collections;
  #if SECOND_PASS
  using System.Xml;
***************
*** 31,34 ****
--- 32,71 ----
  using System.Configuration;
  
+ /*
+ 
+ Structure of the diagnostics configuration section:
+ 
+       <system.diagnostics>
+               <assert [assertuienabled="FLAG"] [logfilename="FILENAME"]/>
+ 
+               <switches>
+                       <add name="NAME1" value="VALUE1"/>
+                       <add name="NAME2" value="VALUE2"/>
+                       ...
+               </switches>
+ 
+               <trace autoflush="FLAG" indentsize="VALUE">
+                       <listeners>
+                               <add [name="NAME"] type="TYPE" 
[initializeData="DATA"]/>
+                               <remove name="NAME"/>
+                               ...
+                       </listeners>
+               </trace>
+       </system.diagnostics>
+ 
+ The "assert" tag specifies where debug messages resulting from "Debug.Assert"
+ should be written.  If "assertuienabled" is "true", then a dialog box will
+ be displayed to the user.  If "logfilename" is present, then it specifies
+ the name of a log file to write to.
+ 
+ The "switches" tag specifies the values of diagnostic option switches.
+ 
+ The "trace" tag specifies whether the output trace buffer should be
+ automatically flushed (default is "false"), and the size of indent levels
+ for "Trace.Indent".  The "listeners" subtag specifies trace listeners
+ to add to the primary collection.
+ 
+ */
+ 
  public class DiagnosticsConfigurationHandler : IConfigurationSectionHandler
  {
***************
*** 38,48 ****
  #if SECOND_PASS
  
!       // Create a configuration object for a section.
!       [TODO]
!       public Object Create(Object parent, Object configContext, XmlNode 
section)
                        {
!                               // TODO
                                return null;
                        }
  
  #endif // SECOND_PASS
--- 75,220 ----
  #if SECOND_PASS
  
!       // Get an attribute value.
!       private static String GetAttribute(XmlNode node, String name)
                        {
!                               XmlAttribute attr = node.Attributes[name];
!                               if(attr != null && attr.Value != null &&
!                                  attr.Value.Length != 0)
!                               {
!                                       return attr.Value;
!                               }
                                return null;
                        }
+ 
+       // Get a boolean attribute value.
+       private static bool GetBoolAttribute(XmlNode node, String name, bool 
def)
+                       {
+                               String value = GetAttribute(node, name);
+                               if(value != null)
+                               {
+                                       return (value == "true");
+                               }
+                               return def;
+                       }
+ 
+       // Get a boolean value from an option collection.
+       private static bool GetBool(Hashtable coll, String name)
+                       {
+                               Object value = coll[name];
+                               if(value != null)
+                               {
+                                       return (bool)value;
+                               }
+                               else
+                               {
+                                       return false;
+                               }
+                       }
+ 
+       // Load a "listeners" tag from a diagnostic configuration element.
+       private static void LoadListeners(Hashtable coll, XmlNode node)
+                       {
+                               // TODO
+                       }
+ 
+       // Create a configuration object for a section.
+       public virtual Object Create
+                               (Object parent, Object configContext, XmlNode 
section)
+                       {
+                               Hashtable coll;
+ 
+                               // Create the collection that will contain the 
results.
+                               if(parent != null)
+                               {
+                                       coll = new Hashtable((Hashtable)parent);
+                               }
+                               else
+                               {
+                                       coll = new Hashtable();
+                               }
+ 
+                               // Process the child nodes.
+                               foreach(XmlNode node in section.ChildNodes)
+                               {
+                                       if(node.NodeType != XmlNodeType.Element)
+                                       {
+                                               continue;
+                                       }
+                                       switch(node.Name)
+                                       {
+                                               case "assert":
+                                               {
+                                                       // Process the 
"assertuienabled" flag.
+                                                       coll["assertuienabled"] 
= GetBoolAttribute
+                                                               (node, 
"assertuienabled",
+                                                                GetBool(coll, 
"assertuienabled"));
+ 
+                                                       // Process the 
"logfilename" value.
+                                                       String filename = 
GetAttribute(node, "logfilename");
+                                                       if(filename != null)
+                                                       {
+                                                               
coll["logfilename"] = filename;
+                                                       }
+                                               }
+                                               break;
+ 
+                                               case "switches":
+                                               {
+                                                       // Load the switches 
and merge them with the
+                                                       // current switch 
settings.
+                                                       coll["switches"] =
+                                                               (new 
SwitchesDictionarySectionHandler()).Create
+                                                                       
(coll["switches"], configContext, node);
+                                               }
+                                               break;
+ 
+                                               case "trace":
+                                               {
+                                                       // Process the 
"autoflush" flag.
+                                                       coll["autoflush"] = 
GetBoolAttribute
+                                                               (node, 
"autoflush",
+                                                                GetBool(coll, 
"autoflush"));
+ 
+                                                       // Process the 
"indentsize" attribute.
+                                                       String newValue = 
GetAttribute(node, "indentsize");
+                                                       if(newValue != null)
+                                                       {
+                                                               
coll["indentsize"] = Int32.Parse(newValue);
+                                                       }
+ 
+                                                       // Load the trace 
listeners.
+                                                       foreach(XmlNode node2 
in node.ChildNodes)
+                                                       {
+                                                               
if(node2.NodeType == XmlNodeType.Element &&
+                                                                  node2.Name 
== "listeners")
+                                                               {
+                                                                       
LoadListeners(coll, node2);
+                                                               }
+                                                       }
+                                               }
+                                               break;
+                                       }
+                               }
+ 
+                               // Return the loaded settings to the caller.
+                               return coll;
+                       }
+ 
+       // Special dictionary section handler for switch values.
+       private class SwitchesDictionarySectionHandler : 
DictionarySectionHandler
+       {
+               // Constructor.
+               public SwitchesDictionarySectionHandler() {}
+ 
+               // Get the name of the key attribute tag.
+               protected override String KeyAttributeName
+                               {
+                                       get
+                                       {
+                                               return "name";
+                                       }
+                               }
+ 
+       }; // class SwitchesDictionarySectionHandler
  
  #endif // SECOND_PASS





reply via email to

[Prev in Thread] Current Thread [Next in Thread]