TraceContext.cs :  » 2.6.4-mono-.net-core » System.Web » System » Web » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » 2.6.4 mono .net core » System.Web 
System.Web » System » Web » TraceContext.cs
// 
// 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
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

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]);
    }
  }
}

www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.