2005-11-02 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[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
40                 private static string traceConfigPath = "system.web/trace";
41                 private bool enabled = false;
42                 private bool local_only = true;
43                 private bool page_output = false;
44                 private TraceMode mode;
45                 private int request_limit = 10;
46
47                 private int cur_item;
48                 private TraceData[] data;
49                 
50                 public TraceManager ()
51                 {
52                         TraceConfig config = (TraceConfig) HttpContext.GetAppConfig (traceConfigPath);
53
54                         if (config == null)
55                                 return;
56                         
57                         enabled = config.Enabled;
58                         local_only = config.LocalOnly;
59                         page_output = config.PageOutput;
60                         mode = config.TraceMode;
61                         request_limit = config.RequestLimit;
62                 }
63
64                 public bool Enabled {
65                         get { return enabled; }
66                         set { enabled = value; }
67                 }
68
69                 public bool LocalOnly {
70                         get { return local_only; }
71                         set { local_only = value; }
72                 }
73
74                 public bool PageOutput {
75                         get { return page_output; }
76                         set { page_output = value; }
77                 }
78
79                 public int RequestLimit {
80                         get { return request_limit; }
81                         set {
82                                 if (request_limit == value)
83                                         return;
84                                 TraceData[] swap = new TraceData [value];
85                                 Array.Copy (data, swap, (cur_item > value ? value : cur_item));
86                                 if (cur_item > value)
87                                         cur_item = value;
88                                 request_limit = value;
89                         }
90                 }
91
92                 public TraceMode TraceMode {
93                         get { return mode; }
94                         set { mode = value; }
95                 }
96
97                 public TraceData[] TraceData {
98                         get { return data; }
99                 }
100                 
101                 public void AddTraceData (TraceData item)
102                 {
103                         if (data == null)
104                                 data = new TraceData [request_limit];
105                         if (cur_item == request_limit)
106                                 return;
107                         data [cur_item++] = item;
108                 }
109
110                 public void Clear ()
111                 {
112                         if (data == null)
113                                 return;
114                         
115                         Array.Clear (data, 0, data.Length);
116                         cur_item = 0;
117                 }
118                 
119                 public int ItemCount {
120                         get { return cur_item; }
121                 }
122         }
123 }
124