Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / xsp / System / Web / Configuration / BrowserCapabilitiesFactoryBase.cs / 1 / BrowserCapabilitiesFactoryBase.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* * Base class for browser capabilities object: just a read-only dictionary * holder that supports Init() * * */ using System.Web.UI; using System.Collections; using System.Collections.Specialized; using System.ComponentModel; using System.Globalization; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using System.Web.Util; namespace System.Web.Configuration { [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] public class BrowserCapabilitiesFactoryBase { private IDictionary _matchedHeaders; private IDictionary _browserElements; private object _lock = new object(); public BrowserCapabilitiesFactoryBase() { } [EditorBrowsable(EditorBrowsableState.Advanced)] protected IDictionary BrowserElements { get { if (_browserElements == null) lock (_lock) { if (_browserElements == null) { _browserElements = Hashtable.Synchronized(new Hashtable(StringComparer.OrdinalIgnoreCase)); PopulateBrowserElements(_browserElements); } } return _browserElements; } } [EditorBrowsable(EditorBrowsableState.Advanced)] protected virtual void PopulateBrowserElements(IDictionary dictionary) { } internal IDictionary InternalGetMatchedHeaders() { return MatchedHeaders; } internal IDictionary InternalGetBrowserElements() { return BrowserElements; } [EditorBrowsable(EditorBrowsableState.Advanced)] protected IDictionary MatchedHeaders { get { if (_matchedHeaders == null) lock (_lock) { if (_matchedHeaders == null) { _matchedHeaders = Hashtable.Synchronized(new Hashtable(24, StringComparer.OrdinalIgnoreCase)); PopulateMatchedHeaders(_matchedHeaders); } } return _matchedHeaders; } } [EditorBrowsable(EditorBrowsableState.Advanced)] protected virtual void PopulateMatchedHeaders(IDictionary dictionary) { } internal int CompareFilters(string filter1, string filter2) { bool isFilter1DefaultFilter = String.IsNullOrEmpty(filter1); bool isFilter2DefaultFilter = String.IsNullOrEmpty(filter2); IDictionary browsers = BrowserElements; bool filter1Exists = (browsers.Contains(filter1)) || isFilter1DefaultFilter; bool filter2Exists = (browsers.Contains(filter2)) || isFilter2DefaultFilter; if (!filter1Exists) { if (!filter2Exists) { return 0; } else { return -1; } } else { if (!filter2Exists) { return 1; } } if (isFilter1DefaultFilter && !isFilter2DefaultFilter) { return 1; } if (isFilter2DefaultFilter && !isFilter1DefaultFilter) { return -1; } if (isFilter1DefaultFilter && isFilter2DefaultFilter) { return 0; } int filter1Depth = (int)((Triplet)BrowserElements[filter1]).Third; int filter2Depth = (int)((Triplet)BrowserElements[filter2]).Third; return filter2Depth - filter1Depth; } public virtual void ConfigureBrowserCapabilities(NameValueCollection headers, HttpBrowserCapabilities browserCaps) { } // CodeGenerator will override this function to declare custom browser capabilities public virtual void ConfigureCustomCapabilities(NameValueCollection headers, HttpBrowserCapabilities browserCaps) { } internal static string GetBrowserCapKey(IDictionary headers, HttpRequest request) { StringBuilder sb = new StringBuilder(); foreach(String key in headers.Keys) { if (key.Length == 0) { sb.Append(HttpCapabilitiesEvaluator.GetUserAgent(request)); } else { sb.Append(request.Headers[key]); } sb.Append("\n"); } return sb.ToString(); } internal HttpBrowserCapabilities GetHttpBrowserCapabilities(HttpRequest request) { if (request == null) throw new ArgumentNullException("request"); NameValueCollection headers = request.Headers; HttpBrowserCapabilities browserCaps = new HttpBrowserCapabilities(); Hashtable values = new Hashtable(180, StringComparer.OrdinalIgnoreCase); values[String.Empty] = HttpCapabilitiesEvaluator.GetUserAgent(request); browserCaps.Capabilities = values; ConfigureBrowserCapabilities(headers, browserCaps); ConfigureCustomCapabilities(headers, browserCaps); return browserCaps; } protected bool IsBrowserUnknown(HttpCapabilitiesBase browserCaps) { // We want to ignore the "Default" node, which will also be matched. if(browserCaps.Browsers == null || browserCaps.Browsers.Count <= 1) { return true; } return false; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* * Base class for browser capabilities object: just a read-only dictionary * holder that supports Init() * * */ using System.Web.UI; using System.Collections; using System.Collections.Specialized; using System.ComponentModel; using System.Globalization; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using System.Web.Util; namespace System.Web.Configuration { [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] public class BrowserCapabilitiesFactoryBase { private IDictionary _matchedHeaders; private IDictionary _browserElements; private object _lock = new object(); public BrowserCapabilitiesFactoryBase() { } [EditorBrowsable(EditorBrowsableState.Advanced)] protected IDictionary BrowserElements { get { if (_browserElements == null) lock (_lock) { if (_browserElements == null) { _browserElements = Hashtable.Synchronized(new Hashtable(StringComparer.OrdinalIgnoreCase)); PopulateBrowserElements(_browserElements); } } return _browserElements; } } [EditorBrowsable(EditorBrowsableState.Advanced)] protected virtual void PopulateBrowserElements(IDictionary dictionary) { } internal IDictionary InternalGetMatchedHeaders() { return MatchedHeaders; } internal IDictionary InternalGetBrowserElements() { return BrowserElements; } [EditorBrowsable(EditorBrowsableState.Advanced)] protected IDictionary MatchedHeaders { get { if (_matchedHeaders == null) lock (_lock) { if (_matchedHeaders == null) { _matchedHeaders = Hashtable.Synchronized(new Hashtable(24, StringComparer.OrdinalIgnoreCase)); PopulateMatchedHeaders(_matchedHeaders); } } return _matchedHeaders; } } [EditorBrowsable(EditorBrowsableState.Advanced)] protected virtual void PopulateMatchedHeaders(IDictionary dictionary) { } internal int CompareFilters(string filter1, string filter2) { bool isFilter1DefaultFilter = String.IsNullOrEmpty(filter1); bool isFilter2DefaultFilter = String.IsNullOrEmpty(filter2); IDictionary browsers = BrowserElements; bool filter1Exists = (browsers.Contains(filter1)) || isFilter1DefaultFilter; bool filter2Exists = (browsers.Contains(filter2)) || isFilter2DefaultFilter; if (!filter1Exists) { if (!filter2Exists) { return 0; } else { return -1; } } else { if (!filter2Exists) { return 1; } } if (isFilter1DefaultFilter && !isFilter2DefaultFilter) { return 1; } if (isFilter2DefaultFilter && !isFilter1DefaultFilter) { return -1; } if (isFilter1DefaultFilter && isFilter2DefaultFilter) { return 0; } int filter1Depth = (int)((Triplet)BrowserElements[filter1]).Third; int filter2Depth = (int)((Triplet)BrowserElements[filter2]).Third; return filter2Depth - filter1Depth; } public virtual void ConfigureBrowserCapabilities(NameValueCollection headers, HttpBrowserCapabilities browserCaps) { } // CodeGenerator will override this function to declare custom browser capabilities public virtual void ConfigureCustomCapabilities(NameValueCollection headers, HttpBrowserCapabilities browserCaps) { } internal static string GetBrowserCapKey(IDictionary headers, HttpRequest request) { StringBuilder sb = new StringBuilder(); foreach(String key in headers.Keys) { if (key.Length == 0) { sb.Append(HttpCapabilitiesEvaluator.GetUserAgent(request)); } else { sb.Append(request.Headers[key]); } sb.Append("\n"); } return sb.ToString(); } internal HttpBrowserCapabilities GetHttpBrowserCapabilities(HttpRequest request) { if (request == null) throw new ArgumentNullException("request"); NameValueCollection headers = request.Headers; HttpBrowserCapabilities browserCaps = new HttpBrowserCapabilities(); Hashtable values = new Hashtable(180, StringComparer.OrdinalIgnoreCase); values[String.Empty] = HttpCapabilitiesEvaluator.GetUserAgent(request); browserCaps.Capabilities = values; ConfigureBrowserCapabilities(headers, browserCaps); ConfigureCustomCapabilities(headers, browserCaps); return browserCaps; } protected bool IsBrowserUnknown(HttpCapabilitiesBase browserCaps) { // We want to ignore the "Default" node, which will also be matched. if(browserCaps.Browsers == null || browserCaps.Browsers.Count <= 1) { return true; } return false; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ZipIOZip64EndOfCentralDirectoryLocatorBlock.cs
- LineGeometry.cs
- StreamInfo.cs
- RegexMatchCollection.cs
- BlockUIContainer.cs
- Matrix3DConverter.cs
- Vector3DIndependentAnimationStorage.cs
- DeviceSpecificDialogCachedState.cs
- WebScriptServiceHostFactory.cs
- FactoryMaker.cs
- CompilerResults.cs
- TextOnlyOutput.cs
- DefaultProxySection.cs
- WebScriptClientGenerator.cs
- XamlStyleSerializer.cs
- WebReferencesBuildProvider.cs
- EventLogPermissionEntryCollection.cs
- SyndicationItemFormatter.cs
- DirectoryRootQuery.cs
- SHA256CryptoServiceProvider.cs
- EntitySqlQueryBuilder.cs
- PropertyCondition.cs
- EventDescriptorCollection.cs
- EndpointDiscoveryElement.cs
- TableRow.cs
- Connector.cs
- XamlFxTrace.cs
- ExclusiveTcpListener.cs
- PassportAuthenticationModule.cs
- ModelUIElement3D.cs
- TextServicesContext.cs
- TextRangeEditLists.cs
- Utils.cs
- IncrementalCompileAnalyzer.cs
- wmiprovider.cs
- Resources.Designer.cs
- OrthographicCamera.cs
- DelimitedListTraceListener.cs
- DependencySource.cs
- ImmComposition.cs
- FixedElement.cs
- PTProvider.cs
- SelectedGridItemChangedEvent.cs
- CustomValidator.cs
- EntityDataSourceUtil.cs
- HttpListenerRequest.cs
- TextDecoration.cs
- CodeVariableReferenceExpression.cs
- ToolboxItemFilterAttribute.cs
- NullNotAllowedCollection.cs
- URIFormatException.cs
- HtmlInputSubmit.cs
- WebServiceTypeData.cs
- PageAction.cs
- DataService.cs
- DynamicControlParameter.cs
- RequestTimeoutManager.cs
- SplitterCancelEvent.cs
- ButtonPopupAdapter.cs
- ScriptResourceDefinition.cs
- __TransparentProxy.cs
- XhtmlBasicListAdapter.cs
- ImageBrush.cs
- TextLineBreak.cs
- AppDomainEvidenceFactory.cs
- Utils.cs
- Line.cs
- ScriptModule.cs
- Line.cs
- CompoundFileIOPermission.cs
- BamlRecords.cs
- SplashScreenNativeMethods.cs
- SiteMapNodeItem.cs
- HWStack.cs
- HttpListenerContext.cs
- ForEachAction.cs
- TemplatePagerField.cs
- OdbcHandle.cs
- TemplateContainer.cs
- MetafileHeaderWmf.cs
- LinqTreeNodeEvaluator.cs
- ResourceDescriptionAttribute.cs
- SystemIPGlobalStatistics.cs
- HttpCacheVaryByContentEncodings.cs
- CodeEntryPointMethod.cs
- DataFormat.cs
- GeneralTransform3DTo2DTo3D.cs
- ListManagerBindingsCollection.cs
- MsmqHostedTransportConfiguration.cs
- path.cs
- QueryStringConverter.cs
- StateMachineSubscriptionManager.cs
- KeyEventArgs.cs
- MetadataImporterQuotas.cs
- SpeechSeg.cs
- AllMembershipCondition.cs
- listitem.cs
- InstallerTypeAttribute.cs
- InvokePattern.cs
- BitHelper.cs