internal PartialCachingControl(IWebObjectFactory objectFactory, Type createCachedControlType, PartialCachingAttribute cacheAttrib, string cacheKey, object[] args) { string providerName = cacheAttrib.ProviderName; _ctrlID = cacheKey; Duration = new TimeSpan(0 /*hours*/, 0 /*mins*/, cacheAttrib.Duration /*seconds*/); SetVaryByParamsCollectionFromString(cacheAttrib.VaryByParams); if (cacheAttrib.VaryByControls != null) { _varyByControlsCollection = cacheAttrib.VaryByControls.Split(varySeparator); } _varyByCustom = cacheAttrib.VaryByCustom; _sqlDependency = cacheAttrib.SqlDependency; if (providerName == OutputCache.ASPNET_INTERNAL_PROVIDER_NAME) { providerName = null; } _provider = providerName; _guid = cacheKey; _objectFactory = objectFactory; _createCachedControlType = createCachedControlType; _args = args; }
public Control LoadControl(Type type, object[] parameters) { object [] attrs = null; if (type != null) { type.GetCustomAttributes(typeof(PartialCachingAttribute), true); } if (attrs != null && attrs.Length == 1) { PartialCachingAttribute attr = (PartialCachingAttribute)attrs [0]; PartialCachingControl ctrl = new PartialCachingControl(type, parameters); ctrl.VaryByParams = attr.VaryByParams; ctrl.VaryByControls = attr.VaryByControls; ctrl.VaryByCustom = attr.VaryByCustom; return(ctrl); } object control = Activator.CreateInstance(type, parameters); if (control is UserControl) { ((UserControl)control).InitializeAsUserControl(Page); } return((Control)control); }
internal BuildResultNoCompileUserControl(Type baseType, TemplateParser parser) : base(baseType, parser) { UserControlParser parser2 = (UserControlParser) parser; OutputCacheParameters outputCacheParameters = parser2.OutputCacheParameters; if ((outputCacheParameters != null) && (outputCacheParameters.Duration > 0)) { this._cachingAttribute = new PartialCachingAttribute(outputCacheParameters.Duration, outputCacheParameters.VaryByParam, outputCacheParameters.VaryByControl, outputCacheParameters.VaryByCustom, outputCacheParameters.SqlDependency, parser2.FSharedPartialCaching); this._cachingAttribute.ProviderName = parser2.Provider; } }
public void Ctor5_Deny_Unrestricted () { PartialCachingAttribute pca = new PartialCachingAttribute (0, "a", "b", "c", true); Assert.AreEqual (0, pca.Duration, "Duration"); Assert.AreEqual ("b", pca.VaryByControls, "VaryByControls"); Assert.AreEqual ("c", pca.VaryByCustom, "VaryByCustom"); Assert.AreEqual ("a", pca.VaryByParams, "VaryByParams"); Assert.IsNull (pca.SqlDependency, "SqlDependency"); Assert.IsTrue (pca.Shared, "Shared"); }
public void Ctor4_Deny_Unrestricted () { PartialCachingAttribute pca = new PartialCachingAttribute (Int32.MaxValue, "1", "2", "3"); Assert.AreEqual (Int32.MaxValue, pca.Duration, "Duration"); Assert.AreEqual ("2", pca.VaryByControls, "VaryByControls"); Assert.AreEqual ("3", pca.VaryByCustom, "VaryByCustom"); Assert.AreEqual ("1", pca.VaryByParams, "VaryByParams"); Assert.IsNull (pca.SqlDependency, "SqlDependency"); Assert.IsFalse (pca.Shared, "Shared"); }
public void Ctor1_Deny_Unrestricted () { PartialCachingAttribute pca = new PartialCachingAttribute (Int32.MinValue); Assert.AreEqual (Int32.MinValue, pca.Duration, "Duration"); Assert.IsNull (pca.VaryByControls, "VaryByControls"); Assert.IsNull (pca.VaryByCustom, "VaryByCustom"); Assert.IsNull (pca.VaryByParams, "VaryByParams"); #if NET_2_0 Assert.IsNull (pca.SqlDependency, "SqlDependency"); #endif Assert.IsFalse (pca.Shared, "Shared"); }
/// <include file='doc\TemplateControl.uex' path='docs/doc[@for="TemplateControl.LoadControl2"]/*' /> /// <devdoc> /// <para>Obtains a <see cref='System.Web.UI.UserControl'/> object from a control type.</para> /// </devdoc> internal Control LoadControl(Type t) { // Make sure the type has the correct base class (ASURT 123677) Util.CheckAssignableType(typeof(Control), t); // Check if the user control type has a PartialCachingAttribute attribute PartialCachingAttribute cacheAttrib = (PartialCachingAttribute) TypeDescriptor.GetAttributes(t)[typeof(PartialCachingAttribute)]; if (cacheAttrib == null) { // The control is not cached. Just create it. Control c = (Control)HttpRuntime.CreatePublicInstance(t); UserControl uc = c as UserControl; if (uc != null) { uc.InitializeAsUserControl(Page); } return(c); } string cacheKey; if (cacheAttrib.Shared) { // If the caching is shared, use the type of the control as the key cacheKey = t.GetHashCode().ToString(); } else { // Make sure we have reflection permission to use GetMethod below (ASURT 106196) InternalSecurityPermissions.Reflection.Assert(); HashCodeCombiner combinedHashCode = new HashCodeCombiner(); // Get a cache key based on the top two items of the caller's stack. // It's not guaranteed unique, but for all common cases, it will be StackTrace st = new StackTrace(); for (int i = 1; i < 3; i++) { StackFrame f = st.GetFrame(i); combinedHashCode.AddObject(f.GetMethod()); combinedHashCode.AddObject(f.GetNativeOffset()); } cacheKey = combinedHashCode.CombinedHashString; } // Wrap it to allow it to be cached return(new PartialCachingControl(t, cacheAttrib, "_" + cacheKey)); }
internal PartialCachingControl(Type createCachedControlType, PartialCachingAttribute cacheAttrib, string cacheKey) { _ctrlID = cacheKey; _duration = cacheAttrib.Duration; if (cacheAttrib.VaryByParams != null) { _varyByParamsCollection = cacheAttrib.VaryByParams.Split(s_varySeparators); } if (cacheAttrib.VaryByControls != null) { _varyByControlsCollection = cacheAttrib.VaryByControls.Split(s_varySeparators); } _varyByCustom = cacheAttrib.VaryByCustom; _guid = cacheKey; _createCachedControlType = createCachedControlType; }
internal PartialCachingControl(IWebObjectFactory objectFactory, Type createCachedControlType, PartialCachingAttribute cacheAttrib, string cacheKey, object[] args) { string providerName = cacheAttrib.ProviderName; base._ctrlID = cacheKey; base.Duration = new TimeSpan(0, 0, cacheAttrib.Duration); base.SetVaryByParamsCollectionFromString(cacheAttrib.VaryByParams); if (cacheAttrib.VaryByControls != null) { base._varyByControlsCollection = cacheAttrib.VaryByControls.Split(new char[] { ';' }); } base._varyByCustom = cacheAttrib.VaryByCustom; base._sqlDependency = cacheAttrib.SqlDependency; if (providerName == "AspNetInternalProvider") { providerName = null; } base._provider = providerName; base._guid = cacheKey; this._objectFactory = objectFactory; this._createCachedControlType = createCachedControlType; this._args = args; }
internal PartialCachingControl(IWebObjectFactory objectFactory, Type createCachedControlType, PartialCachingAttribute cacheAttrib, string cacheKey, object[] args) { string providerName = cacheAttrib.ProviderName; _ctrlID = cacheKey; Duration = new TimeSpan(0 /*hours*/, 0 /*mins*/, cacheAttrib.Duration /*seconds*/); SetVaryByParamsCollectionFromString(cacheAttrib.VaryByParams); if (cacheAttrib.VaryByControls != null) _varyByControlsCollection = cacheAttrib.VaryByControls.Split(varySeparator); _varyByCustom = cacheAttrib.VaryByCustom; _sqlDependency = cacheAttrib.SqlDependency; if (providerName == OutputCache.ASPNET_INTERNAL_PROVIDER_NAME) { providerName = null; } _provider = providerName; _guid = cacheKey; _objectFactory = objectFactory; _createCachedControlType = createCachedControlType; _args = args; }
internal BuildResultNoCompileUserControl(Type baseType, TemplateParser parser) : base(baseType, parser) { UserControlParser ucParser = (UserControlParser) parser; OutputCacheParameters cacheSettings = ucParser.OutputCacheParameters; // If the user control has an OutputCache directive, create // a PartialCachingAttribute with the information about it. if (cacheSettings != null && cacheSettings.Duration > 0) { _cachingAttribute = new PartialCachingAttribute( cacheSettings.Duration, cacheSettings.VaryByParam, cacheSettings.VaryByControl, cacheSettings.VaryByCustom, cacheSettings.SqlDependency, ucParser.FSharedPartialCaching); _cachingAttribute.ProviderName = ucParser.Provider; } }