use Invariant culture for string manipulations
[mono.git] / mcs / class / System.Web / System.Web / TraceManager.cs
1 //
2 // System.Web.TraceManager
3 //
4 // Author(s):
5 //  Jackson Harper (jackson@ximian.com)
6 //
7 // (C) 2004 Novell, Inc (http://www.novell.com)
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31
32 using System;
33 using System.Collections;
34 using System.Web.Configuration;
35
36 namespace System.Web {
37
38         internal class TraceManager {
39 #if !NET_2_0
40                 private static string traceConfigPath = "system.web/trace";
41 #endif
42                 private bool enabled = false;
43                 private bool local_only = true;
44                 private bool page_output = false;
45                 private TraceMode mode;
46                 private int request_limit = 10;
47
48                 private int cur_item;
49                 private TraceData[] data;
50                 
51                 public TraceManager ()
52                 {
53 #if NET_2_0
54                         TraceSection config = WebConfigurationManager.GetSection ("system.web/trace") as TraceSection;
55                         if (config == null)
56                                 config = new TraceSection ();
57 #else
58                         TraceConfig config = (TraceConfig) HttpContext.GetAppConfig (traceConfigPath);
59 #endif
60
61                         if (config == null)
62                                 return;
63                         
64                         enabled = config.Enabled;
65                         local_only = config.LocalOnly;
66                         page_output = config.PageOutput;
67 #if NET_2_0
68                         if (config.TraceMode == TraceDisplayMode.SortByTime)
69                                 mode = TraceMode.SortByTime;
70                         else
71                                 mode = TraceMode.SortByCategory;
72 #else
73                         mode = config.TraceMode;
74 #endif
75                         request_limit = config.RequestLimit;
76                 }
77
78                 public bool Enabled {
79                         get { return enabled; }
80                         set { enabled = value; }
81                 }
82
83                 public bool LocalOnly {
84                         get { return local_only; }
85                         set { local_only = value; }
86                 }
87
88                 public bool PageOutput {
89                         get { return page_output; }
90                         set { page_output = value; }
91                 }
92
93                 public int RequestLimit {
94                         get { return request_limit; }
95                         set {
96                                 if (request_limit == value)
97                                         return;
98                                 TraceData[] swap = new TraceData [value];
99                                 Array.Copy (data, swap, (cur_item > value ? value : cur_item));
100                                 if (cur_item > value)
101                                         cur_item = value;
102                                 request_limit = value;
103                         }
104                 }
105
106                 public TraceMode TraceMode {
107                         get { return mode; }
108                         set { mode = value; }
109                 }
110
111                 public TraceData[] TraceData {
112                         get { return data; }
113                 }
114                 
115                 public void AddTraceData (TraceData item)
116                 {
117                         if (data == null)
118                                 data = new TraceData [request_limit];
119                         if (cur_item == request_limit)
120                                 return;
121                         data [cur_item++] = item;
122                 }
123
124                 public void Clear ()
125                 {
126                         if (data == null)
127                                 return;
128                         
129                         Array.Clear (data, 0, data.Length);
130                         cur_item = 0;
131                 }
132                 
133                 public int ItemCount {
134                         get { return cur_item; }
135                 }
136         }
137 }
138