private void CacheBrowserCapResult(ref HttpCapabilitiesBase result) { CacheInternal cacheInternal = HttpRuntime.CacheInternal; if (result.Capabilities != null) { string key = "z"; StringBuilder builder = new StringBuilder(); foreach (string str2 in result.Capabilities.Keys) { if (!string.IsNullOrEmpty(str2)) { string str3 = (string) result.Capabilities[str2]; if (str3 != null) { builder.Append(str2); builder.Append("$"); builder.Append(str3); builder.Append("$"); } } } key = key + builder.ToString().GetHashCode().ToString(CultureInfo.InvariantCulture); HttpCapabilitiesBase base2 = cacheInternal.Get(key) as HttpCapabilitiesBase; if (base2 != null) { result = base2; } else { cacheInternal.UtcInsert(key, result, null, Cache.NoAbsoluteExpiration, this._cachetime); } } }
internal HttpCapabilitiesBase EvaluateFinal(HttpRequest request, bool onlyEvaluateUserAgent) { HttpBrowserCapabilities httpBrowserCapabilities = this.BrowserCapFactory.GetHttpBrowserCapabilities(request); CapabilitiesState state = new CapabilitiesState(request, httpBrowserCapabilities.Capabilities); if (onlyEvaluateUserAgent) { state.EvaluateOnlyUserAgent = true; } if (this._rule != null) { string str = httpBrowserCapabilities["isMobileDevice"]; httpBrowserCapabilities.Capabilities["isMobileDevice"] = null; this._rule.Evaluate(state); string str2 = httpBrowserCapabilities["isMobileDevice"]; if (str2 == null) { httpBrowserCapabilities.Capabilities["isMobileDevice"] = str; } else if (str2.Equals("true")) { httpBrowserCapabilities.DisableOptimizedCacheKey(); } } HttpCapabilitiesBase base2 = (HttpCapabilitiesBase)HttpRuntime.CreateNonPublicInstance(this._resultType); base2.InitInternal(httpBrowserCapabilities); return(base2); }
private void CacheBrowserCapResult(ref HttpCapabilitiesBase result) { CacheInternal cacheInternal = HttpRuntime.CacheInternal; if (result.Capabilities != null) { string key = "z"; StringBuilder builder = new StringBuilder(); foreach (string str2 in result.Capabilities.Keys) { if (!string.IsNullOrEmpty(str2)) { string str3 = (string)result.Capabilities[str2]; if (str3 != null) { builder.Append(str2); builder.Append("$"); builder.Append(str3); builder.Append("$"); } } } key = key + builder.ToString().GetHashCode().ToString(CultureInfo.InvariantCulture); HttpCapabilitiesBase base2 = cacheInternal.Get(key) as HttpCapabilitiesBase; if (base2 != null) { result = base2; } else { cacheInternal.UtcInsert(key, result, null, Cache.NoAbsoluteExpiration, this._cachetime); } } }
protected bool IsBrowserUnknown(HttpCapabilitiesBase browserCaps) { if ((browserCaps.Browsers != null) && (browserCaps.Browsers.Count > 1)) { return(false); } return(true); }
public override HttpBrowserCapabilities GetBrowserCapabilities(HttpRequest request) { HttpBrowserCapabilities bcap = new HttpBrowserCapabilities(); bcap.capabilities = HttpCapabilitiesBase.GetConfigCapabilities(null, request).Capabilities; return(bcap); }
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); }
private void CacheBrowserCapResult(ref HttpCapabilitiesBase result) { // Use the previously cached browserCap object if an identical // browserCap is found. CacheStoreProvider cacheInternal = System.Web.HttpRuntime.Cache.InternalCache; if (result.Capabilities == null) { return; } string hashKey = CacheInternal.PrefixBrowserCapsHash; StringBuilder builder = new StringBuilder(); foreach (string attribute in result.Capabilities.Keys) { // Ignore useragent that is stored with empty key. if (String.IsNullOrEmpty(attribute)) { continue; } string value = (String)result.Capabilities[attribute]; if (value != null) { builder.Append(attribute); builder.Append("$"); builder.Append(value); builder.Append("$"); } } hashKey += builder.ToString().GetHashCode().ToString(CultureInfo.InvariantCulture); HttpCapabilitiesBase newResult = cacheInternal.Get(hashKey) as HttpCapabilitiesBase; if (newResult != null) { result = newResult; } else { // cache it and respect cachetime cacheInternal.Insert(hashKey, result, new CacheInsertOptions() { SlidingExpiration = _cachetime }); } }
internal virtual HttpCapabilitiesBase EvaluateFinal(HttpRequest request, bool onlyEvaluateUserAgent) { // not in cache: calculate the result Hashtable values = new Hashtable(new CaseInsensitiveHashCodeProvider(CultureInfo.InvariantCulture), new CaseInsensitiveComparer(CultureInfo.InvariantCulture)); CapabilitiesState state = new CapabilitiesState(request, values); if (onlyEvaluateUserAgent) { state.EvaluateOnlyUserAgent = true; } _rule.Evaluate(state); // create the new type // CONSIDER: don't allow non-public cap result types HttpCapabilitiesBase result = (HttpCapabilitiesBase)HttpRuntime.CreateNonPublicInstance(_resultType); result.InitInternal(values); return(result); }
internal HttpCapabilitiesBase EvaluateFinal(HttpRequest request, bool onlyEvaluateUserAgent) { HttpBrowserCapabilities browserCaps = BrowserCapFactory.GetHttpBrowserCapabilities(request); CapabilitiesState state = new CapabilitiesState(request, browserCaps.Capabilities); if (onlyEvaluateUserAgent) { state.EvaluateOnlyUserAgent = true; } if (_rule != null) { string oldIsMobileDevice = browserCaps[_isMobileDeviceCapKey]; browserCaps.Capabilities[_isMobileDeviceCapKey] = null; _rule.Evaluate(state); string newIsMobileDevice = browserCaps[_isMobileDeviceCapKey]; if (newIsMobileDevice == null) { browserCaps.Capabilities[_isMobileDeviceCapKey] = oldIsMobileDevice; } else if (newIsMobileDevice.Equals("true")) { browserCaps.DisableOptimizedCacheKey(); } } // create the new type // HttpCapabilitiesBase result = (HttpCapabilitiesBase)HttpRuntime.CreateNonPublicInstance(_resultType); result.InitInternal(browserCaps); return(result); }
protected bool IsBrowserUnknown(HttpCapabilitiesBase browserCaps) { if ((browserCaps.Browsers != null) && (browserCaps.Browsers.Count > 1)) { return false; } return true; }
private void CacheBrowserCapResult(ref HttpCapabilitiesBase result) { // Use the previously cached browserCap object if an identical // browserCap is found. CacheInternal cacheInternal = System.Web.HttpRuntime.CacheInternal; if (result.Capabilities == null) { return; } string hashKey = CacheInternal.PrefixBrowserCapsHash; StringBuilder builder = new StringBuilder(); foreach (string attribute in result.Capabilities.Keys) { // Ignore useragent that is stored with empty key. if (String.IsNullOrEmpty(attribute)) { continue; } string value = (String)result.Capabilities[attribute]; if (value != null) { builder.Append(attribute); builder.Append("$"); builder.Append(value); builder.Append("$"); } } hashKey += builder.ToString().GetHashCode().ToString(CultureInfo.InvariantCulture); HttpCapabilitiesBase newResult = cacheInternal.Get(hashKey) as HttpCapabilitiesBase; if (newResult != null) { result = newResult; } else { // cache it and respect cachetime cacheInternal.UtcInsert(hashKey, result, null, Cache.NoAbsoluteExpiration, _cachetime); } }
/// <summary> /// Gets a HtmlTextWriter to write output to, based on a TextWriter. /// </summary> /// <param name="writer">The Text writer holding the output stream.</param> /// <param name="browser">The browser capabilities of the client browser.</param> /// <returns></returns> protected static HtmlTextWriter CreateHtmlTextWriter(TextWriter writer, HttpCapabilitiesBase browser) { if (browser == null) return new HtmlTextWriter(writer); return browser.CreateHtmlTextWriter(writer); }
protected bool IsBrowserUnknown(HttpCapabilitiesBase browserCaps) { return(default(bool)); }
protected bool IsBrowserUnknown(HttpCapabilitiesBase browserCaps) { return default(bool); }
private static void SetDefaults(HttpCapabilitiesBase source) { // We'll assume a reasonable width for the browser, but we'll // do so before any other capabilities are detected. This way // our default will be overriden if an actual value is found // in one of our sources. if(!source.Capabilities.Contains(AllCapabilities.Width)) source.Capabilities[AllCapabilities.Width] = AllCapabilities.DefaultWidth.ToString(CultureInfo.InvariantCulture); }
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; }
internal HttpCapabilitiesBase Evaluate(HttpRequest request) { CacheInternal cacheInternal = HttpRuntime.CacheInternal; string userAgent = GetUserAgent(request); string str2 = userAgent; if ((str2 != null) && (str2.Length > this.UserAgentCacheKeyLength)) { str2 = str2.Substring(0, this.UserAgentCacheKeyLength); } bool flag = false; string key = this._cacheKeyPrefix + str2; object obj2 = cacheInternal.Get(key); HttpCapabilitiesBase result = obj2 as HttpCapabilitiesBase; if (result == null) { if (obj2 == _disableOptimisticCachingSingleton) { flag = true; } else { result = this.EvaluateFinal(request, true); if (result.UseOptimizedCacheKey) { this.CacheBrowserCapResult(ref result); cacheInternal.UtcInsert(key, result, null, Cache.NoAbsoluteExpiration, this._cachetime); return(result); } } IDictionaryEnumerator enumerator = this._variables.GetEnumerator(); StringBuilder builder = new StringBuilder(this._cacheKeyPrefix); InternalSecurityPermissions.AspNetHostingPermissionLevelLow.Assert(); while (enumerator.MoveNext()) { string str5; string str4 = (string)enumerator.Key; if (str4.Length == 0) { str5 = userAgent; } else { str5 = request.ServerVariables[str4]; } if (str5 != null) { builder.Append(str5); } } CodeAccessPermission.RevertAssert(); builder.Append(BrowserCapabilitiesFactoryBase.GetBrowserCapKey(this.BrowserCapFactory.InternalGetMatchedHeaders(), request)); string str6 = builder.ToString(); if ((userAgent == null) || flag) { result = cacheInternal.Get(str6) as HttpCapabilitiesBase; if (result != null) { return(result); } } result = this.EvaluateFinal(request, false); this.CacheBrowserCapResult(ref result); cacheInternal.UtcInsert(str6, result, null, Cache.NoAbsoluteExpiration, this._cachetime); if (key != null) { cacheInternal.UtcInsert(key, _disableOptimisticCachingSingleton, null, Cache.NoAbsoluteExpiration, this._cachetime); } } return(result); }