CapabilitiesState.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / xsp / System / Web / Configuration / CapabilitiesState.cs / 1 / CapabilitiesState.cs

                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

namespace System.Web.Configuration { 
 
    using System.Collections;
    using System.Collections.Specialized; 
    using System.Diagnostics;
    using System.Globalization;
    using System.Reflection;
    using System.Security; 
    using System.Text;
    using System.Text.RegularExpressions; 
    using System.Threading; 
    using System.Web.Caching;
    using System.Web.Compilation; 
    using System.Web.Hosting;
    using System.Security.Permissions;

    // 
    // Encapsulates the evaluation state used in computing capabilities
    // 
    internal class CapabilitiesState { 
        internal HttpRequest _request;
        internal IDictionary _values; 
        internal ArrayList _matchlist;
        internal ArrayList _regexlist;
        internal bool _exit;
        internal bool _evaluateOnlyUserAgent; 

        internal CapabilitiesState(HttpRequest request, IDictionary values) { 
            _request = request; 
            _values = values;
            _matchlist = new ArrayList(); 
            _regexlist = new ArrayList();
        }

        internal bool EvaluateOnlyUserAgent { 
            get {
                return _evaluateOnlyUserAgent; 
            } 
            set {
                _evaluateOnlyUserAgent = value; 
            }
        }

        internal virtual void ClearMatch() { 
            if (_matchlist == null) {
                _regexlist = new ArrayList(); 
                _matchlist = new ArrayList(); 
            }
            else { 
                _regexlist.Clear();
                _matchlist.Clear();
            }
        } 

        internal virtual void AddMatch(DelayedRegex regex, Match match) { 
            _regexlist.Add(regex); 
            _matchlist.Add(match);
        } 

        internal virtual void PopMatch() {
            _regexlist.RemoveAt(_regexlist.Count - 1);
            _matchlist.RemoveAt(_matchlist.Count - 1); 
        }
 
        internal virtual String ResolveReference(String refname) { 
            if (_matchlist == null)
                return String.Empty; 

            int i = _matchlist.Count;

            while (i > 0) { 
                i--;
                int groupnum = ((DelayedRegex)_regexlist[i]).GroupNumberFromName(refname); 
 
                if (groupnum >= 0) {
                    Group group = ((Match)_matchlist[i]).Groups[groupnum]; 
                    if (group.Success) {
                        return group.ToString();
                    }
                } 
            }
 
            return String.Empty; 
        }
 
        [AspNetHostingPermission(SecurityAction.Assert, Level=AspNetHostingPermissionLevel.Low)]
        string ResolveServerVariableWithAssert(string varname) {
            string result = _request.ServerVariables[varname];
            if (result == null) 
                return string.Empty;
 
            return result; 
        }
 
        internal virtual String ResolveServerVariable(String varname) {
            if (varname.Length == 0 || varname == "HTTP_USER_AGENT")
                return HttpCapabilitiesEvaluator.GetUserAgent(_request);
 
            if (EvaluateOnlyUserAgent)
                return string.Empty; 
 
            return ResolveServerVariableWithAssert(varname);
        } 

        internal virtual String ResolveVariable(String varname) {
            String result;
 
            result = (String)_values[varname];
 
            if (result == null) 
                return String.Empty;
 
            return result;
        }

        internal virtual void SetVariable(String varname, String value) { 
            _values[varname] = value;
        } 
 
        internal virtual bool Exit {
            get { 
                return _exit;
            }
            set {
                _exit = value; 
            }
        } 
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

namespace System.Web.Configuration { 
 
    using System.Collections;
    using System.Collections.Specialized; 
    using System.Diagnostics;
    using System.Globalization;
    using System.Reflection;
    using System.Security; 
    using System.Text;
    using System.Text.RegularExpressions; 
    using System.Threading; 
    using System.Web.Caching;
    using System.Web.Compilation; 
    using System.Web.Hosting;
    using System.Security.Permissions;

    // 
    // Encapsulates the evaluation state used in computing capabilities
    // 
    internal class CapabilitiesState { 
        internal HttpRequest _request;
        internal IDictionary _values; 
        internal ArrayList _matchlist;
        internal ArrayList _regexlist;
        internal bool _exit;
        internal bool _evaluateOnlyUserAgent; 

        internal CapabilitiesState(HttpRequest request, IDictionary values) { 
            _request = request; 
            _values = values;
            _matchlist = new ArrayList(); 
            _regexlist = new ArrayList();
        }

        internal bool EvaluateOnlyUserAgent { 
            get {
                return _evaluateOnlyUserAgent; 
            } 
            set {
                _evaluateOnlyUserAgent = value; 
            }
        }

        internal virtual void ClearMatch() { 
            if (_matchlist == null) {
                _regexlist = new ArrayList(); 
                _matchlist = new ArrayList(); 
            }
            else { 
                _regexlist.Clear();
                _matchlist.Clear();
            }
        } 

        internal virtual void AddMatch(DelayedRegex regex, Match match) { 
            _regexlist.Add(regex); 
            _matchlist.Add(match);
        } 

        internal virtual void PopMatch() {
            _regexlist.RemoveAt(_regexlist.Count - 1);
            _matchlist.RemoveAt(_matchlist.Count - 1); 
        }
 
        internal virtual String ResolveReference(String refname) { 
            if (_matchlist == null)
                return String.Empty; 

            int i = _matchlist.Count;

            while (i > 0) { 
                i--;
                int groupnum = ((DelayedRegex)_regexlist[i]).GroupNumberFromName(refname); 
 
                if (groupnum >= 0) {
                    Group group = ((Match)_matchlist[i]).Groups[groupnum]; 
                    if (group.Success) {
                        return group.ToString();
                    }
                } 
            }
 
            return String.Empty; 
        }
 
        [AspNetHostingPermission(SecurityAction.Assert, Level=AspNetHostingPermissionLevel.Low)]
        string ResolveServerVariableWithAssert(string varname) {
            string result = _request.ServerVariables[varname];
            if (result == null) 
                return string.Empty;
 
            return result; 
        }
 
        internal virtual String ResolveServerVariable(String varname) {
            if (varname.Length == 0 || varname == "HTTP_USER_AGENT")
                return HttpCapabilitiesEvaluator.GetUserAgent(_request);
 
            if (EvaluateOnlyUserAgent)
                return string.Empty; 
 
            return ResolveServerVariableWithAssert(varname);
        } 

        internal virtual String ResolveVariable(String varname) {
            String result;
 
            result = (String)_values[varname];
 
            if (result == null) 
                return String.Empty;
 
            return result;
        }

        internal virtual void SetVariable(String varname, String value) { 
            _values[varname] = value;
        } 
 
        internal virtual bool Exit {
            get { 
                return _exit;
            }
            set {
                _exit = value; 
            }
        } 
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK