private Control LoadControl(IWebObjectFactory objectFactory, System.Web.VirtualPath virtualPath, Type t, object[] parameters) { BuildResultCompiledType type = null; BuildResultNoCompileUserControl control = null; PartialCachingAttribute cachingAttribute; if (objectFactory != null) { type = objectFactory as BuildResultCompiledType; if (type != null) { t = type.ResultType; Util.CheckAssignableType(typeof(UserControl), t); } else { control = (BuildResultNoCompileUserControl)objectFactory; } } else if (t != null) { Util.CheckAssignableType(typeof(Control), t); } if (t != null) { cachingAttribute = (PartialCachingAttribute)TypeDescriptor.GetAttributes(t)[typeof(PartialCachingAttribute)]; } else { cachingAttribute = control.CachingAttribute; } if (cachingAttribute == null) { Control control2; if (objectFactory != null) { control2 = (Control)objectFactory.CreateInstance(); } else { control2 = (Control)HttpRuntime.CreatePublicInstance(t, parameters); } UserControl control3 = control2 as UserControl; if (control3 != null) { if (virtualPath != null) { control3.TemplateControlVirtualPath = virtualPath; } control3.InitializeAsUserControl(this.Page); } return(control2); } HashCodeCombiner combinedHashCode = new HashCodeCombiner(); if (objectFactory != null) { combinedHashCode.AddObject(objectFactory); } else { combinedHashCode.AddObject(t); } if (!cachingAttribute.Shared) { this.AddStackContextToHashCode(combinedHashCode); } string combinedHashString = combinedHashCode.CombinedHashString; return(new PartialCachingControl(objectFactory, t, cachingAttribute, "_" + combinedHashString, parameters)); }
private string ComputeVaryCacheKey(HashCodeCombiner combinedHashCode, ControlCachedVary cachedVary) { // Add something to the has to differentiate it from the non-vary hash. // This is needed in case this method doesn't add anything else to the hash (VSWhidbey 194199) combinedHashCode.AddInt(1); // Get the request value collection NameValueCollection reqValCollection; HttpRequest request = Page.Request; if (request != null && request.HttpVerb == HttpVerb.POST) { // reqValCollection = new NameValueCollection(request.QueryString); reqValCollection.Add(request.Form); } else { // Use the existing value if possible to avoid recreating a NameValueCollection reqValCollection = Page.RequestValueCollection; // If it's not set, get it based on the method if (reqValCollection == null) { reqValCollection = Page.GetCollectionBasedOnMethod(true /*dontReturnNull*/); } } if (cachedVary._varyByParams != null) { ICollection itemsToUseForHashCode; // If '*' was specified, use all the items in the request collection. // Otherwise, use only those specified. if (cachedVary._varyByParams.Length == 1 && cachedVary._varyByParams[0] == "*") { itemsToUseForHashCode = reqValCollection; } else { itemsToUseForHashCode = cachedVary._varyByParams; } // Add the items and their values to compute the hash code foreach (string varyByParam in itemsToUseForHashCode) { // Note: we use to ignore certain system fields here (like VIEWSTATE), but decided // not to for consistency with pahe output caching (VSWhidbey 196267, 479252) combinedHashCode.AddCaseInsensitiveString(varyByParam); string val = reqValCollection[varyByParam]; if (val != null) { combinedHashCode.AddObject(val); } } } if (cachedVary._varyByControls != null) { // Prepend them with a prefix to make them fully qualified string prefix; if (NamingContainer == Page) { // No prefix if it's the page prefix = String.Empty; } else { prefix = NamingContainer.UniqueID; Debug.Assert(!String.IsNullOrEmpty(prefix)); prefix += IdSeparator; } prefix += _ctrlID + IdSeparator; // Add all the relative vary params and their values to the hash code foreach (string varyByParam in cachedVary._varyByControls) { string temp = prefix + varyByParam.Trim(); combinedHashCode.AddCaseInsensitiveString(temp); string val = reqValCollection[temp]; if (val != null) { combinedHashCode.AddObject(reqValCollection[temp]); } } } if (cachedVary._varyByCustom != null) { string customString = Context.ApplicationInstance.GetVaryByCustomString( Context, cachedVary._varyByCustom); if (customString != null) { combinedHashCode.AddObject(customString); } } return(CacheInternal.PrefixPartialCachingControl + combinedHashCode.CombinedHashString); }
internal override void InitRecursive(Control namingContainer) { HashCodeCombiner combinedHashCode = new HashCodeCombiner(); _cacheKey = ComputeNonVaryCacheKey(combinedHashCode); // Save the non-varying hash, so we don't need to recalculate it later _nonVaryHashCode = combinedHashCode.CombinedHash; PartialCachingCacheEntry cacheEntry = null; // Check if there is a cache entry for the non-varying key object tmpCacheEntry = OutputCache.GetFragment(_cacheKey, _provider); if (tmpCacheEntry != null) { ControlCachedVary cachedVary = tmpCacheEntry as ControlCachedVary; if (cachedVary != null) { string varyCachedKey = ComputeVaryCacheKey(combinedHashCode, cachedVary); // Check if there is a cache entry for the varying key cacheEntry = (PartialCachingCacheEntry)OutputCache.GetFragment(varyCachedKey, _provider); if (cacheEntry != null && cacheEntry._cachedVaryId != cachedVary.CachedVaryId) { cacheEntry = null; // explicitly remove the entry OutputCache.RemoveFragment(varyCachedKey, _provider); } } else { // If it wasn't a ControlCachedVary, it must be a PartialCachingCacheEntry cacheEntry = (PartialCachingCacheEntry)tmpCacheEntry; } } // If it's a cache miss, create the control and make it our child if (cacheEntry == null) { // Cache miss _cacheEntry = new PartialCachingCacheEntry(); _cachedCtrl = CreateCachedControl(); Controls.Add(_cachedCtrl); // Make sure the Page knows about us while the control's OnInit is called Page.PushCachingControl(this); base.InitRecursive(namingContainer); Page.PopCachingControl(); } else { // Cache hit _outputString = cacheEntry.OutputString; _cssStyleString = cacheEntry.CssStyleString; // If any calls to Register* API's were made when the control was run, // make them now to restore correct behavior (VSWhidbey 80907) if (cacheEntry.RegisteredClientCalls != null) { foreach (RegisterCallData registerCallData in cacheEntry.RegisteredClientCalls) { switch (registerCallData.Type) { case ClientAPIRegisterType.WebFormsScript: Page.RegisterWebFormsScript(); break; case ClientAPIRegisterType.PostBackScript: Page.RegisterPostBackScript(); break; case ClientAPIRegisterType.FocusScript: Page.RegisterFocusScript(); break; case ClientAPIRegisterType.ClientScriptBlocks: case ClientAPIRegisterType.ClientScriptBlocksWithoutTags: case ClientAPIRegisterType.ClientStartupScripts: case ClientAPIRegisterType.ClientStartupScriptsWithoutTags: Page.ClientScript.RegisterScriptBlock(registerCallData.Key, registerCallData.StringParam2, registerCallData.Type); break; case ClientAPIRegisterType.OnSubmitStatement: Page.ClientScript.RegisterOnSubmitStatementInternal(registerCallData.Key, registerCallData.StringParam2); break; case ClientAPIRegisterType.ArrayDeclaration: Page.ClientScript.RegisterArrayDeclaration(registerCallData.StringParam1, registerCallData.StringParam2); break; case ClientAPIRegisterType.HiddenField: Page.ClientScript.RegisterHiddenField(registerCallData.StringParam1, registerCallData.StringParam2); break; case ClientAPIRegisterType.ExpandoAttribute: Page.ClientScript.RegisterExpandoAttribute(registerCallData.StringParam1, registerCallData.StringParam2, registerCallData.StringParam3, false); break; case ClientAPIRegisterType.EventValidation: if (_registeredCallDataForEventValidation == null) { _registeredCallDataForEventValidation = new ArrayList(); } _registeredCallDataForEventValidation.Add(registerCallData); break; default: Debug.Assert(false); break; } } } base.InitRecursive(namingContainer); } }
public override int GetHashCode() { return(HashCodeCombiner.CombineHashCodes((this.Name != null) ? this.Name.GetHashCode() : 0, (this.DefaultValue != null) ? this.DefaultValue.GetHashCode() : 0)); }
/// <internalonly/> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> protected internal override void Render(HtmlTextWriter output) { CacheDependency sqlCacheDep = null; // If the output is cached, use it and do nothing else if (_outputString != null) { output.Write(_outputString); RegisterValidationEvents(); return; } // If caching was turned off, just render the control if (_cachingDisabled || !RuntimeConfig.GetAppConfig().OutputCache.EnableFragmentCache) { _cachedCtrl.RenderControl(output); return; } // Create SQL cache dependency before we render the page if (_sqlDependency != null) { sqlCacheDep = SqlCacheDependency.CreateOutputCacheDependency(_sqlDependency); } _cacheEntry.CssStyleString = GetCssStyleRenderString(output.GetType()); // Create a new HtmlTextWriter, with the same type as the current one (see ASURT 118922) StringWriter tmpWriter = new StringWriter(); HtmlTextWriter tmpHtmlWriter = Page.CreateHtmlTextWriterFromType(tmpWriter, output.GetType()); CacheDependency cacheDep; TextWriter savedWriter = Context.Response.SwitchWriter(tmpWriter); try { // Make sure the Page knows about us while the control's OnPreRender is called Page.PushCachingControl(this); _cachedCtrl.RenderControl(tmpHtmlWriter); Page.PopCachingControl(); } finally { Context.Response.SwitchWriter(savedWriter); } _cacheEntry.OutputString = tmpWriter.ToString(); // Send the output to the response output.Write(_cacheEntry.OutputString); // Cache the output cacheDep = _cacheDependency; if (sqlCacheDep != null) { if (cacheDep == null) { cacheDep = sqlCacheDep; } else { AggregateCacheDependency aggr = new AggregateCacheDependency(); aggr.Add(cacheDep); aggr.Add(sqlCacheDep); cacheDep = aggr; } } ControlCachedVary cachedVary = null; string realItemCacheKey; // If there are no varies, use the non-varying key if (_varyByParamsCollection == null && _varyByControlsCollection == null && _varyByCustom == null) { realItemCacheKey = _cacheKey; } else { string[] varyByParams = null; if (_varyByParamsCollection != null) { varyByParams = _varyByParamsCollection.GetParams(); } cachedVary = new ControlCachedVary(varyByParams, _varyByControlsCollection, _varyByCustom); HashCodeCombiner combinedHashCode = new HashCodeCombiner(_nonVaryHashCode); realItemCacheKey = ComputeVaryCacheKey(combinedHashCode, cachedVary); } // Compute the correct expiration, sliding or absolute DateTime utcExpirationTime; TimeSpan slidingExpiration; if (_useSlidingExpiration) { utcExpirationTime = Cache.NoAbsoluteExpiration; slidingExpiration = _utcExpirationTime - DateTime.UtcNow; } else { utcExpirationTime = _utcExpirationTime; slidingExpiration = Cache.NoSlidingExpiration; } try { OutputCache.InsertFragment(_cacheKey, cachedVary, realItemCacheKey, _cacheEntry, cacheDep /*dependencies*/, utcExpirationTime, slidingExpiration, _provider); } catch { if (cacheDep != null) { cacheDep.Dispose(); } throw; } }
protected internal override void Render(HtmlTextWriter output) { CacheDependency dependency = null; if (this._outputString != null) { output.Write(this._outputString); this.RegisterValidationEvents(); } else if (this._cachingDisabled || !RuntimeConfig.GetAppConfig().OutputCache.EnableFragmentCache) { this._cachedCtrl.RenderControl(output); } else { string str; DateTime noAbsoluteExpiration; TimeSpan noSlidingExpiration; if (this._sqlDependency != null) { dependency = SqlCacheDependency.CreateOutputCacheDependency(this._sqlDependency); } this._cacheEntry.CssStyleString = this.GetCssStyleRenderString(output.GetType()); StringWriter tw = new StringWriter(); HtmlTextWriter writer = Page.CreateHtmlTextWriterFromType(tw, output.GetType()); TextWriter writer3 = this.Context.Response.SwitchWriter(tw); try { this.Page.PushCachingControl(this); this._cachedCtrl.RenderControl(writer); this.Page.PopCachingControl(); } finally { this.Context.Response.SwitchWriter(writer3); } this._cacheEntry.OutputString = tw.ToString(); output.Write(this._cacheEntry.OutputString); CacheDependency dependencies = this._cacheDependency; if (dependency != null) { if (dependencies == null) { dependencies = dependency; } else { AggregateCacheDependency dependency3 = new AggregateCacheDependency(); dependency3.Add(new CacheDependency[] { dependencies }); dependency3.Add(new CacheDependency[] { dependency }); dependencies = dependency3; } } ControlCachedVary cachedVary = null; if (((this._varyByParamsCollection == null) && (this._varyByControlsCollection == null)) && (this._varyByCustom == null)) { str = this._cacheKey; } else { string[] varyByParams = null; if (this._varyByParamsCollection != null) { varyByParams = this._varyByParamsCollection.GetParams(); } cachedVary = new ControlCachedVary(varyByParams, this._varyByControlsCollection, this._varyByCustom); HashCodeCombiner combinedHashCode = new HashCodeCombiner(this._nonVaryHashCode); str = this.ComputeVaryCacheKey(combinedHashCode, cachedVary); } if (this._useSlidingExpiration) { noAbsoluteExpiration = Cache.NoAbsoluteExpiration; noSlidingExpiration = (TimeSpan)(this._utcExpirationTime - DateTime.UtcNow); } else { noAbsoluteExpiration = this._utcExpirationTime; noSlidingExpiration = Cache.NoSlidingExpiration; } try { OutputCache.InsertFragment(this._cacheKey, cachedVary, str, this._cacheEntry, dependencies, noAbsoluteExpiration, noSlidingExpiration, this._provider); } catch { if (dependencies != null) { dependencies.Dispose(); } throw; } } }
private string ComputeVaryCacheKey(HashCodeCombiner combinedHashCode, ControlCachedVary cachedVary) { combinedHashCode.AddInt(1); NameValueCollection requestValueCollection = this.Page.RequestValueCollection; if (requestValueCollection == null) { requestValueCollection = this.Page.GetCollectionBasedOnMethod(true); } if (cachedVary._varyByParams != null) { ICollection is2; if ((cachedVary._varyByParams.Length == 1) && (cachedVary._varyByParams[0] == "*")) { is2 = requestValueCollection; } else { is2 = cachedVary._varyByParams; } foreach (string str in is2) { combinedHashCode.AddCaseInsensitiveString(str); string s = requestValueCollection[str]; if (s != null) { combinedHashCode.AddObject(s); } } } if (cachedVary._varyByControls != null) { string str3; if (this.NamingContainer == this.Page) { str3 = string.Empty; } else { str3 = this.NamingContainer.UniqueID + base.IdSeparator; } str3 = str3 + this._ctrlID + base.IdSeparator; foreach (string str4 in cachedVary._varyByControls) { string str5 = str3 + str4.Trim(); combinedHashCode.AddCaseInsensitiveString(str5); if (requestValueCollection[str5] != null) { combinedHashCode.AddObject(requestValueCollection[str5]); } } } if (cachedVary._varyByCustom != null) { string varyByCustomString = this.Context.ApplicationInstance.GetVaryByCustomString(this.Context, cachedVary._varyByCustom); if (varyByCustomString != null) { combinedHashCode.AddObject(varyByCustomString); } } return("l" + combinedHashCode.CombinedHashString); }
internal override void InitRecursive(Control namingContainer) { HashCodeCombiner combinedHashCode = new HashCodeCombiner(); this._cacheKey = this.ComputeNonVaryCacheKey(combinedHashCode); this._nonVaryHashCode = combinedHashCode.CombinedHash; PartialCachingCacheEntry entry = null; object fragment = OutputCache.GetFragment(this._cacheKey, this._provider); if (fragment != null) { ControlCachedVary cachedVary = fragment as ControlCachedVary; if (cachedVary != null) { string key = this.ComputeVaryCacheKey(combinedHashCode, cachedVary); entry = (PartialCachingCacheEntry)OutputCache.GetFragment(key, this._provider); if ((entry != null) && (entry._cachedVaryId != cachedVary.CachedVaryId)) { entry = null; OutputCache.RemoveFragment(key, this._provider); } } else { entry = (PartialCachingCacheEntry)fragment; } } if (entry == null) { this._cacheEntry = new PartialCachingCacheEntry(); this._cachedCtrl = this.CreateCachedControl(); this.Controls.Add(this._cachedCtrl); this.Page.PushCachingControl(this); base.InitRecursive(namingContainer); this.Page.PopCachingControl(); } else { this._outputString = entry.OutputString; this._cssStyleString = entry.CssStyleString; if (entry.RegisteredClientCalls != null) { foreach (RegisterCallData data in entry.RegisteredClientCalls) { switch (data.Type) { case ClientAPIRegisterType.WebFormsScript: this.Page.RegisterWebFormsScript(); break; case ClientAPIRegisterType.PostBackScript: this.Page.RegisterPostBackScript(); break; case ClientAPIRegisterType.FocusScript: this.Page.RegisterFocusScript(); break; case ClientAPIRegisterType.ClientScriptBlocks: case ClientAPIRegisterType.ClientScriptBlocksWithoutTags: case ClientAPIRegisterType.ClientStartupScripts: case ClientAPIRegisterType.ClientStartupScriptsWithoutTags: this.Page.ClientScript.RegisterScriptBlock(data.Key, data.StringParam2, data.Type); break; case ClientAPIRegisterType.OnSubmitStatement: this.Page.ClientScript.RegisterOnSubmitStatementInternal(data.Key, data.StringParam2); break; case ClientAPIRegisterType.ArrayDeclaration: this.Page.ClientScript.RegisterArrayDeclaration(data.StringParam1, data.StringParam2); break; case ClientAPIRegisterType.HiddenField: this.Page.ClientScript.RegisterHiddenField(data.StringParam1, data.StringParam2); break; case ClientAPIRegisterType.ExpandoAttribute: this.Page.ClientScript.RegisterExpandoAttribute(data.StringParam1, data.StringParam2, data.StringParam3, false); break; case ClientAPIRegisterType.EventValidation: if (this._registeredCallDataForEventValidation == null) { this._registeredCallDataForEventValidation = new ArrayList(); } this._registeredCallDataForEventValidation.Add(data); break; } } } base.InitRecursive(namingContainer); } }
private Control LoadControl(IWebObjectFactory objectFactory, VirtualPath virtualPath, Type t, object[] parameters) { // Make sure we get an object factory or a type, but not both Debug.Assert((objectFactory == null) != (t == null)); BuildResultCompiledType compiledUCResult = null; BuildResultNoCompileUserControl noCompileUCResult = null; if (objectFactory != null) { // It can be a compiled or no-compile user control compiledUCResult = objectFactory as BuildResultCompiledType; if (compiledUCResult != null) { t = compiledUCResult.ResultType; Debug.Assert(t != null); // Make sure it's a user control (VSWhidbey 428718) Util.CheckAssignableType(typeof(UserControl), t); } else { noCompileUCResult = (BuildResultNoCompileUserControl)objectFactory; Debug.Assert(noCompileUCResult != null); } } else { // Make sure the type has the correct base class (ASURT 123677) if (t != null) { Util.CheckAssignableType(typeof(Control), t); } } PartialCachingAttribute cacheAttrib; // Check if the user control has a PartialCachingAttribute attribute if (t != null) { cacheAttrib = (PartialCachingAttribute) TypeDescriptor.GetAttributes(t)[typeof(PartialCachingAttribute)]; } else { cacheAttrib = noCompileUCResult.CachingAttribute; } if (cacheAttrib == null) { // The control is not cached. Just create it. Control c; if (objectFactory != null) { c = (Control)objectFactory.CreateInstance(); } else { c = (Control)HttpRuntime.CreatePublicInstance(t, parameters); } // If it's a user control, do some extra initialization UserControl uc = c as UserControl; if (uc != null) { Debug.Assert(virtualPath != null); if (virtualPath != null) { uc.TemplateControlVirtualPath = virtualPath; } uc.InitializeAsUserControl(Page); } return(c); } HashCodeCombiner combinedHashCode = new HashCodeCombiner(); // Start by adding the type or object factory of the user control to the hash. // This guarantees that two unrelated user controls don't share the same cached data. if (objectFactory != null) { combinedHashCode.AddObject(objectFactory); } else { combinedHashCode.AddObject(t); } // If it's not shared, add some stack frames to the hash if (!cacheAttrib.Shared) { AddStackContextToHashCode(combinedHashCode); } string cacheKey = combinedHashCode.CombinedHashString; // Wrap it to allow it to be cached return(new PartialCachingControl(objectFactory, t, cacheAttrib, "_" + cacheKey, parameters)); }
internal static long GetRecompilationHash(PagesSection ps) { HashCodeCombiner combiner = new HashCodeCombiner(); combiner.AddObject(ps.Buffer); combiner.AddObject(ps.EnableViewState); combiner.AddObject(ps.EnableViewStateMac); combiner.AddObject(ps.EnableEventValidation); combiner.AddObject(ps.SmartNavigation); combiner.AddObject(ps.ValidateRequest); combiner.AddObject(ps.AutoEventWireup); if (ps.PageBaseTypeInternal != null) { combiner.AddObject(ps.PageBaseTypeInternal.FullName); } if (ps.UserControlBaseTypeInternal != null) { combiner.AddObject(ps.UserControlBaseTypeInternal.FullName); } if (ps.PageParserFilterTypeInternal != null) { combiner.AddObject(ps.PageParserFilterTypeInternal.FullName); } combiner.AddObject(ps.MasterPageFile); combiner.AddObject(ps.Theme); combiner.AddObject(ps.StyleSheetTheme); combiner.AddObject(ps.EnableSessionState); combiner.AddObject(ps.CompilationMode); combiner.AddObject(ps.MaxPageStateFieldLength); combiner.AddObject(ps.ViewStateEncryptionMode); combiner.AddObject(ps.MaintainScrollPositionOnPostBack); NamespaceCollection namespaces = ps.Namespaces; combiner.AddObject(namespaces.AutoImportVBNamespace); if (namespaces.Count == 0) { combiner.AddObject("__clearnamespaces"); } else { foreach (NamespaceInfo info in namespaces) { combiner.AddObject(info.Namespace); } } TagPrefixCollection controls = ps.Controls; if (controls.Count == 0) { combiner.AddObject("__clearcontrols"); } else { foreach (TagPrefixInfo info2 in controls) { combiner.AddObject(info2.TagPrefix); if ((info2.TagName != null) && (info2.TagName.Length != 0)) { combiner.AddObject(info2.TagName); combiner.AddObject(info2.Source); } else { combiner.AddObject(info2.Namespace); combiner.AddObject(info2.Assembly); } } } TagMapCollection tagMapping = ps.TagMapping; if (tagMapping.Count == 0) { combiner.AddObject("__cleartagmapping"); } else { foreach (TagMapInfo info3 in tagMapping) { combiner.AddObject(info3.TagType); combiner.AddObject(info3.MappedTagType); } } return(combiner.CombinedHash); }
public override int GetHashCode() { return(HashCodeCombiner.CombineHashCodes(this._maximumRows.GetHashCode(), this._retrieveTotalRowCount.GetHashCode(), this._sortExpression.GetHashCode(), this._startRowIndex.GetHashCode(), this._totalRowCount.GetHashCode())); }
public override int GetHashCode() { return(HashCodeCombiner.CombineHashCodes(this._type.GetHashCode(), this._key.GetHashCode(), this._isInclude.GetHashCode())); }