-// \r
-// System.Web.TraceContext\r
-//\r
-// Author:\r
-// Patrik Torstensson (Patrik.Torstensson@labs2.com)\r
-// Jackson Harper (jackson@ximian.com)\r
-//\r
-// (C) 2002 2003, Patrik Torstensson\r
-// (C) 2003 Novell, Inc (http://www.novell.com) \r
-//\r
-
+//
+// System.Web.TraceContext
+//
+// Author:
+// Patrik Torstensson (Patrik.Torstensson@labs2.com)
+// Jackson Harper (jackson@ximian.com)
+//
+// (C) 2002 2003, Patrik Torstensson
+// Copyright (C) 2003-2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-\r
-using System;\r
-using System.Data;\r
-using System.Web.UI;\r
-using System.Web.UI.WebControls;\r
-\r
-namespace System.Web {\r
- public sealed class TraceContext {\r
- private HttpContext _Context;\r
- private bool _Enabled;\r
- private TraceMode _Mode;\r
- private TraceData data;\r
- private bool data_saved;\r
- private bool _haveTrace;
- \r
- public TraceContext(HttpContext Context) {\r
- _Context = Context;\r
- _Enabled = false;\r
- }\r
-
-
- internal bool HaveTrace {
- get {
- return _haveTrace;
+
+using System.ComponentModel;
+using System.Collections;
+using System.Security.Permissions;
+using System.Web.UI;
+
+namespace System.Web
+{
+ // CAS - no InheritanceDemand here as the class is sealed
+ [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+ public sealed class TraceContext
+ {
+ static readonly object traceFinishedEvent = new object ();
+
+ HttpContext _Context;
+ TraceManager _traceManager;
+ bool _Enabled;
+ TraceMode _Mode = TraceMode.Default;
+ TraceData data;
+ bool data_saved;
+ bool _haveTrace;
+ Hashtable view_states;
+ Hashtable control_states;
+ Hashtable sizes;
+ EventHandlerList events = new EventHandlerList ();
+
+ public event TraceContextEventHandler TraceFinished {
+ add { events.AddHandler (traceFinishedEvent, value); }
+ remove { events.AddHandler (traceFinishedEvent, value); }
+ }
+
+ public TraceContext (HttpContext Context)
+ {
+ _Context = Context;
+ }
+
+ internal bool HaveTrace {
+ get {
+ return _haveTrace;
+ }
+ }
+
+ public bool IsEnabled {
+ get {
+ if (!_haveTrace)
+ return TraceManager.Enabled;
+ return _Enabled;
+ }
+
+ set {
+ if (value && data == null)
+ data = new TraceData ();
+ _haveTrace = true;
+ _Enabled = value;
+ }
+ }
+
+ TraceManager TraceManager
+ {
+ get
+ {
+ if (_traceManager == null)
+ _traceManager = HttpRuntime.TraceManager;
+
+ return _traceManager;
+ }
+ }
+
+ public TraceMode TraceMode {
+ get {
+ return (_Mode == TraceMode.Default) ? TraceManager.TraceMode : _Mode;
+ }
+ set {
+ _Mode = value;
+ }
+ }
+
+ public void Warn(string msg)
+ {
+ Write (String.Empty, msg, null, true);
+ }
+
+ public void Warn(string category, string msg)
+ {
+ Write (category, msg, null, true);
+ }
+
+ public void Warn (string category, string msg, Exception error)
+ {
+ Write (category, msg, error, true);
+ }
+
+ public void Write (string msg)
+ {
+ Write (String.Empty, msg, null, false);
+ }
+
+ public void Write (string category, string msg)
+ {
+ Write (category, msg, null, false);
+ }
+
+ public void Write (string category, string msg, Exception error)
+ {
+ Write (category, msg, error, false);
+ }
+
+ void Write (string category, string msg, Exception error, bool Warning)
+ {
+ if (!IsEnabled)
+ return;
+ if (data == null)
+ data = new TraceData ();
+ data.Write (category, msg, error, Warning);
+ }
+
+ internal void SaveData ()
+ {
+ if (data == null)
+ data = new TraceData ();
+
+ data.TraceMode = _Context.Trace.TraceMode;
+
+ SetRequestDetails ();
+ if (_Context.Handler is Page)
+ data.AddControlTree ((Page) _Context.Handler, view_states, control_states, sizes);
+
+ AddCookies ();
+ AddHeaders ();
+ AddServerVars ();
+ TraceManager.AddTraceData (data);
+ data_saved = true;
+ }
+
+ internal void SaveViewState (Control ctrl, object vs)
+ {
+ if (view_states == null)
+ view_states = new Hashtable ();
+
+ view_states [ctrl] = vs;
+ }
+
+ internal void SaveControlState (Control ctrl, object vs) {
+ if (control_states == null)
+ control_states = new Hashtable ();
+
+ control_states [ctrl] = vs;
+ }
+
+ internal void SaveSize (Control ctrl, int size)
+ {
+ if (sizes == null)
+ sizes = new Hashtable ();
+
+ sizes [ctrl] = size;
+ }
+
+ internal void Render (HtmlTextWriter output)
+ {
+ if (!data_saved)
+ SaveData ();
+ data.Render (output);
+ }
+
+ void SetRequestDetails ()
+ {
+ data.RequestPath = _Context.Request.FilePath;
+ data.SessionID = (_Context.Session != null ? _Context.Session.SessionID : String.Empty);
+ data.RequestType = _Context.Request.RequestType;
+ data.RequestTime = _Context.Timestamp;
+ data.StatusCode = _Context.Response.StatusCode;
+ data.RequestEncoding = _Context.Request.ContentEncoding;
+ data.ResponseEncoding = _Context.Response.ContentEncoding;
+ }
+
+ void AddCookies ()
+ {
+ foreach (string key in _Context.Request.Cookies.Keys)
+ data.AddCookie (key, _Context.Request.Cookies [key].Value);
+ }
+
+ void AddHeaders ()
+ {
+ foreach (string key in _Context.Request.Headers.Keys)
+ data.AddHeader (key, _Context.Request.Headers [key]);
+ }
+
+ void AddServerVars ()
+ {
+ foreach (string key in _Context.Request.ServerVariables)
+ data.AddServerVar (key, _Context.Request.ServerVariables [key]);
}
}
-\r
- public bool IsEnabled {\r
- get {\r
- if (!_haveTrace)
- return HttpRuntime.TraceManager.Enabled;
- return _Enabled;\r
- }\r
-\r
- set {\r
- if (value && data == null)\r
- data = new TraceData ();\r
- _haveTrace = true;
- _Enabled = value;\r
- }\r
- }\r
-\r
- public TraceMode TraceMode {\r
- get {\r
- return _Mode;\r
- }\r
-\r
- set {\r
- _Mode = value;\r
- }\r
- }\r
-\r
- public void Warn(string msg) {\r
- Write(String.Empty, msg, null, true);\r
- }\r
-\r
- public void Warn(string category, string msg) {\r
- Write(category, msg, null, true);\r
- }\r
-\r
- public void Warn(string category, string msg, Exception error) {\r
- Write(category, msg, error, true);\r
- }\r
-\r
- public void Write(string msg) {\r
- Write(String.Empty, msg, null, false);\r
- }\r
-\r
- public void Write(string category, string msg) {\r
- Write(category, msg, null, false);\r
- }\r
-\r
- public void Write(string category, string msg, Exception error) {\r
- Write(category, msg, error, false);\r
- }\r
-\r
- private void Write(string category, string msg, Exception error, bool Warning) {\r
- if (!IsEnabled)\r
- return;\r
- if (data == null)\r
- data = new TraceData ();\r
- data.Write (category, msg, error, Warning);\r
- }\r
-\r
- internal void SaveData ()\r
- {\r
- if (data == null)\r
- data = new TraceData ();\r
- SetRequestDetails ();\r
- if (_Context.Handler is Page)
- data.AddControlTree ((Page) _Context.Handler);
-
- AddCookies ();\r
- AddHeaders ();\r
- AddServerVars ();\r
- HttpRuntime.TraceManager.AddTraceData (data);\r
- data_saved = true;\r
- }\r
- \r
- internal void Render (HtmlTextWriter output)\r
- {\r
- if (!data_saved)\r
- SaveData ();\r
- data.Render (output);\r
- }\r
-\r
- private void SetRequestDetails ()\r
- {\r
- data.RequestPath = _Context.Request.FilePath;\r
- data.SessionID = (_Context.Session != null ? _Context.Session.SessionID : String.Empty);\r
- data.RequestType = _Context.Request.RequestType;\r
- data.RequestTime = _Context.Timestamp;\r
- data.StatusCode = _Context.Response.StatusCode;\r
- data.RequestEncoding = _Context.Request.ContentEncoding;\r
- data.ResponseEncoding = _Context.Response.ContentEncoding;\r
- }\r
-\r
- private void AddCookies ()\r
- {\r
- foreach (string key in _Context.Request.Cookies.Keys)\r
- data.AddCookie (key, _Context.Request.Cookies [key].Value);\r
- }\r
- \r
- private void AddHeaders ()\r
- {\r
- foreach (string key in _Context.Request.Headers.Keys)\r
- data.AddHeader (key, _Context.Request.Headers [key]);\r
- }\r
-\r
- private void AddServerVars ()\r
- {\r
- foreach (string key in _Context.Request.ServerVariables)\r
- data.AddServerVar (key, _Context.Request.ServerVariables [key]);\r
- }\r
- }\r
-}\r
+}
+