2004-03-19 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / System.Web / System.Web.Configuration / TraceConfigurationHandler.cs
1 //
2 // System.Web.Configuation.TraceConfigurationHandler
3 //
4 // Author(s):
5 //  Jackson Harper (jackson@ximian.com)
6 //
7 // (C) 2004 Novell, Inc (http://www.novell.com)
8 //
9
10 using System;
11 using System.Web;
12 using System.Xml;
13 using System.Configuration;
14
15 namespace System.Web.Configuration {
16
17         internal class TraceConfigurationHandler : IConfigurationSectionHandler {
18
19                 public object Create (object parent, object context, XmlNode section)
20                 {
21                         TraceConfig config = new TraceConfig ();
22
23                         string enabled_str = AttValue ("enabled", section);
24                         if (enabled_str != null) {
25                                 try {
26                                         config.Enabled = Boolean.Parse (enabled_str);
27                                 } catch {
28                                         ThrowException ("The 'enabled' attribute is case sensitive" +
29                                                         " and must be set to 'true' or 'false'.", section);
30                                 }
31                         }
32
33                         string local_str = AttValue ("localOnly", section);
34                         if (local_str != null) {
35                                 try {
36                                         config.LocalOnly = Boolean.Parse (local_str);
37                                 } catch {
38                                         ThrowException ("The 'localOnly' attribute is case sensitive" +
39                                                         " and must be set to 'true' or 'false'.", section);
40                                 }
41                         }
42
43                         string page_str = AttValue ("pageOutput", section);
44                         if (page_str != null) {
45                                 try {
46                                         config.PageOutput = Boolean.Parse (page_str);
47                                 } catch {
48                                         ThrowException ("The 'pageOutput' attribute is case sensitive" +
49                                                         " and must be set to 'true' or 'false'.", section);
50                                 }
51                         }
52
53                         string limit_str = AttValue ("requestLimit", section);
54                         if (limit_str != null) {
55                                 try {
56                                         config.RequestLimit = Int32.Parse (limit_str);
57                                 } catch {
58                                         ThrowException ("The 'requestLimit' attribute must be an integer value.",
59                                                         section);
60                                 }
61                         }
62
63                         string trace_str = AttValue ("traceMode", section);
64                         if (trace_str != null) {
65                                 try {
66                                         config.TraceMode = (TraceMode) Enum.Parse (typeof (TraceMode), trace_str);
67                                 } catch {
68                                         ThrowException ("The 'traceMode' attribute is case sensitive and must be" +
69                                                         " one of the following values: SortByTime, SortByCategory.",
70                                                         section);
71                                 }
72                         }
73                         
74                         return config;
75                 }
76
77                 // A few methods to save some typing
78                 static string AttValue (string name, XmlNode node)
79                 {
80                         return HandlersUtil.ExtractAttributeValue (name, node, true);
81                 }
82
83                 static void ThrowException (string message, XmlNode node)
84                 {
85                         HandlersUtil.ThrowException (message, node);
86                 }
87         }
88 }
89