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.3, 1.4 Trace.cs, 1.3, 1.4
Date: Tue, 25 Nov 2003 23:53:31 +0000

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

Modified Files:
        DiagnosticsConfigurationHandler.cs Trace.cs 
Log Message:


Put some configuration infrastructure in place for the "Debug" and
"Trace" classes.


Index: Trace.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System/Diagnostics/Trace.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Trace.cs    8 Oct 2003 15:29:26 -0000       1.3
--- Trace.cs    25 Nov 2003 23:53:29 -0000      1.4
***************
*** 27,41 ****
--- 27,104 ----
  #if !ECMA_COMPAT
  
+ using System.Configuration;
+ using System.Collections;
+ 
  public sealed class Trace
  {
        // Internal state.
+       private static bool initialized = false;
        private static bool autoFlush;
        private static int indentLevel;
        private static int indentSize = 4;
        private static TraceListenerCollection listeners;
+       private static Hashtable switches;
  
        // This class cannot be instantiated.
        private Trace() {}
  
+       // Make sure that the trace configuration is loaded.
+       private static void Initialize()
+                       {
+                               Object value;
+ 
+                               // Bail out if already initialized, or called 
recursively.
+                               if(initialized)
+                               {
+                                       return;
+                               }
+                               initialized = true;
+ 
+                               // Create the default trace listener.
+                               DefaultTraceListener defListener =
+                                       new DefaultTraceListener();
+ 
+                               // Create the initial listeners collection.
+                               listeners = new TraceListenerCollection();
+                               listeners.Add(defListener);
+ 
+ #if false
+                               // Get the diagnostics configuration options.
+                               Hashtable options = (Hashtable)
+                                       ConfigurationSettings.GetConfig
+                                               ("system.diagnostics",
+                                                new 
DiagnosticsConfigurationHandler());
+                               if(options == null)
+                               {
+                                       options = new Hashtable();
+                               }
+ 
+                               // Process the options for the default trace 
listener.
+                               value = options["assertuienabled"];
+                               if(value != null)
+                               {
+                                       defListener.AssertUiEnabled = 
(bool)value;
+                               }
+                               value = options["logfilename"];
+                               if(value != null)
+                               {
+                                       defListener.LogFileName = (String)value;
+                               }
+ 
+                               // Process the trace options.
+                               value = options["autoflush"];
+                               if(value != null)
+                               {
+                                       autoFlush = (bool)value;
+                               }
+                               value = options["indentsize"];
+                               if(value != null)
+                               {
+                                       indentSize = (int)value;
+                               }
+                               switches = (Hashtable)(options["switches"]);
+ #endif
+                       }
+ 
        // Global trace properties.
        public static bool AutoFlush
***************
*** 45,48 ****
--- 108,112 ----
                                        lock(typeof(Trace))
                                        {
+                                               Initialize();
                                                return autoFlush;
                                        }
***************
*** 52,55 ****
--- 116,120 ----
                                        lock(typeof(Trace))
                                        {
+                                               Initialize();
                                                autoFlush = value;
                                        }
***************
*** 62,65 ****
--- 127,131 ----
                                        lock(typeof(Trace))
                                        {
+                                               Initialize();
                                                return indentLevel;
                                        }
***************
*** 69,72 ****
--- 135,139 ----
                                        lock(typeof(Trace))
                                        {
+                                               Initialize();
                                                if(value < 0)
                                                {
***************
*** 87,90 ****
--- 154,158 ----
                                        lock(typeof(Trace))
                                        {
+                                               Initialize();
                                                return indentSize;
                                        }
***************
*** 94,97 ****
--- 162,166 ----
                                        lock(typeof(Trace))
                                        {
+                                               Initialize();
                                                if(value < 0)
                                                {
***************
*** 112,120 ****
                                        lock(typeof(Trace))
                                        {
!                                               if(listeners == null)
!                                               {
!                                                       listeners = new 
TraceListenerCollection();
!                                                       listeners.Add(new 
DefaultTraceListener());
!                                               }
                                                return listeners;
                                        }
--- 181,185 ----
                                        lock(typeof(Trace))
                                        {
!                                               Initialize();
                                                return listeners;
                                        }

Index: DiagnosticsConfigurationHandler.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/System/Diagnostics/DiagnosticsConfigurationHandler.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** DiagnosticsConfigurationHandler.cs  25 Nov 2003 06:22:20 -0000      1.3
--- DiagnosticsConfigurationHandler.cs  25 Nov 2003 23:53:29 -0000      1.4
***************
*** 23,27 ****
  {
  
! #if CONFIG_EXTENDED_DIAGNOSTICS
  
  using System;
--- 23,27 ----
  {
  
! #if !ECMA_COMPAT
  
  using System;
***************
*** 49,52 ****
--- 49,53 ----
                                <add [name="NAME"] type="TYPE" 
[initializeData="DATA"]/>
                                <remove name="NAME"/>
+                               <clear/>
                                ...
                        </listeners>
***************
*** 113,119 ****
  
        // Load a "listeners" tag from a diagnostic configuration element.
!       private static void LoadListeners(Hashtable coll, XmlNode node)
                        {
!                               // TODO
                        }
  
--- 114,178 ----
  
        // Load a "listeners" tag from a diagnostic configuration element.
!       // This is the odd one out in that it does not return the settings via
!       // the return collection, but instead side-effects "Trace" directly.
!       private static void LoadListeners(XmlNode node)
                        {
!                               String name, type, data;
!                               Type resolvedType;
!                               TraceListener listener;
!                               foreach(XmlNode child in node.ChildNodes)
!                               {
!                                       if(child.NodeType != 
XmlNodeType.Element)
!                                       {
!                                               continue;
!                                       }
!                                       switch(child.Name)
!                                       {
!                                               case "add":
!                                               {
!                                                       name = 
GetAttribute(child, "name");
!                                                       type = 
GetAttribute(child, "type");
!                                                       data = 
GetAttribute(child, "initializeData");
!                                                       if(type == null ||
!                                                          (resolvedType = 
Type.GetType(type)) == null)
!                                                       {
!                                                               break;
!                                                       }
!                                                       if(data != null)
!                                                       {
!                                                               listener = 
(TraceListener)
!                                                                       
Activator.CreateInstance
!                                                                               
(resolvedType, new Object [] {data});
!                                                       }
!                                                       else
!                                                       {
!                                                               listener = 
(TraceListener)
!                                                                       
Activator.CreateInstance(resolvedType);
!                                                       }
!                                                       if(name != null)
!                                                       {
!                                                               listener.Name = 
name;
!                                                       }
!                                                       
Trace.Listeners.Add(listener);
!                                               }
!                                               break;
! 
!                                               case "remove":
!                                               {
!                                                       name = 
GetAttribute(child, "name");
!                                                       if(name != null)
!                                                       {
!                                                               
Trace.Listeners.Remove(name);
!                                                       }
!                                               }
!                                               break;
! 
!                                               case "clear":
!                                               {
!                                                       Trace.Listeners.Clear();
!                                               }
!                                               break;
!                                       }
!                               }
                        }
  
***************
*** 189,193 ****
                                                                   node2.Name 
== "listeners")
                                                                {
!                                                                       
LoadListeners(coll, node2);
                                                                }
                                                        }
--- 248,252 ----
                                                                   node2.Name 
== "listeners")
                                                                {
!                                                                       
LoadListeners(node2);
                                                                }
                                                        }
***************
*** 222,226 ****
  }; // class DiagnosticsConfigurationHandler
  
! #endif // CONFIG_EXTENDED_DIAGNOSTICS
  
  }; // namespace System.Diagnostics
--- 281,285 ----
  }; // class DiagnosticsConfigurationHandler
  
! #endif // !ECMA_COMPAT
  
  }; // namespace System.Diagnostics





reply via email to

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