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;
        }
Beispiel #2
0
            internal SimpleTemplate(ITypedWebObjectFactory objectFactory)
            {
                // Make sure it's a user control (VSWhidbey 428718)
                Util.CheckAssignableType(typeof(UserControl), objectFactory.InstantiatedType);

                _objectFactory = objectFactory;
            }
Beispiel #3
0
        internal override IControlAdapter NewControlAdapter(Type originalControlType)
        {
            IControlAdapter   adapter;
            IWebObjectFactory adapterFactory = LookupControl(originalControlType);

            if (adapterFactory != null)
            {
                adapter = (IControlAdapter)adapterFactory.CreateInstance();
            }
            else
            {
                DesignerAdapterAttribute da;
                da = (DesignerAdapterAttribute)
                     TypeDescriptor.GetAttributes(originalControlType)
                     [typeof(DesignerAdapterAttribute)];
                if (da == null)
                {
                    return(new EmptyControlAdapter());
                }

                Type adapterType = Type.GetType(da.TypeName);
                if (adapterType == null)
                {
                    return(new EmptyControlAdapter());
                }

                adapter = Activator.CreateInstance(adapterType) as IControlAdapter;
            }

            if (adapter == null)
            {
                adapter = new EmptyControlAdapter();
            }
            return(adapter);
        }
        // Given a control's type, create a control adapter for it.

        internal virtual IControlAdapter NewControlAdapter(Type originalControlType)
        {
            IWebObjectFactory factory = GetAdapterFactory(originalControlType);

            // Should return non-null, or throw an exception.
            Debug.Assert(factory != null);

            IControlAdapter a = (IControlAdapter)factory.CreateInstance();

            return(a);
        }
        // Given a control's type, returns the adapter type to be used.
        // Note that it's legal to not register an adapter type for each
        // control type.
        //
        // This lookup uses the following steps:
        //
        // (1) Look up the control type directly, to see if an adapter type
        //     has been registered for it.
        // (2) Walk up the control inheritance chain, to see if an adapter type
        //     has been registered for the class. For example, if the passed
        //     control type is a validator, check BaseValidator, Label,
        //     TextControl, and finally MobileControl.
        // (3) If no adapter type has still been found, call the parent configuration,
        //     if any, to look up the adapter type. For example, the CHTML device
        //     configuration would call the HTML device configuration.
        // (4) If an adapter type is found, but is not explicitly registered for
        //     the passed control type, add an entry to the table, so that
        //     subsequent requests do not need to walk the hierarchy.

        protected IWebObjectFactory GetAdapterFactory(Type originalControlType)
        {
            Debug.Assert(_parentConfigName == null);

            Type controlType          = originalControlType;
            IWebObjectFactory factory = LookupControl(controlType, true); // Look in type cache

            // Walk up hierarchy looking for registered adapters.
            // Stop when we get to the base control.

            while (factory == null && controlType != _baseControlType)
            {
                factory = LookupControl(controlType);
                if (factory == null)
                {
                    controlType = controlType.BaseType;
                }
            }

            // Could not find one in the current hierarchy. So, look it up in
            // the parent config if there is one.

            if (factory == null && _parentConfig != null)
            {
                factory = _parentConfig.GetAdapterFactory(originalControlType);
            }

            if (factory == null)
            {
                throw new Exception(
                          SR.GetString(SR.IndividualDeviceConfig_ControlWithIncorrectPageAdapter,
                                       controlType.FullName, _pageAdapterType.FullName));
            }

            if (controlType != originalControlType)
            {
                // Add to lookup cache, so the next lookup won't require
                // traversing the hierarchy.

                // Grab writer lock...
                using (new ReaderWriterLockResource(_controlAdapterTypesLock,
                                                    true))
                {
                    _controlAdapterLookupCache[originalControlType] = factory;
                }
            }

            return(factory);
        }
 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;
 }
Beispiel #7
0
        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;
        }
Beispiel #8
0
        /// <summary>
        /// Initializes a module and prepares it to handle requests.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpApplication"/> that provides access to the methods, properties, and events common to all application objects within an ASP.NET application </param>
        public void Init(HttpApplication context)
        {
            const string errorPage = "~/Views/Shared/Error.cshtml";

            // When ever an error occurs on the Http Application, we'll now handle it, here.
            context.Error += (sender, e) =>
            {
                HttpContext.Current.ClearError();

                IWebObjectFactory webObjectFactory = BuildManager.GetObjectFactory(errorPage, true);

                WebPageBase webPageBase = webObjectFactory.CreateInstance() as WebPageBase;

                if (webPageBase == null)
                {
                    throw new InvalidOperationException("Failed to create an instance of the following page: " + errorPage);
                }

                var wrapper        = new HttpContextWrapper(HttpContext.Current);
                var webPageContext = new WebPageContext(wrapper, null, null);

                webPageBase.ExecutePageHierarchy(webPageContext, HttpContext.Current.Response.Output);
            };
        }
    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 SimpleTemplate(ITypedWebObjectFactory objectFactory)
 {
     Util.CheckAssignableType(typeof(UserControl), objectFactory.InstantiatedType);
     this._objectFactory = objectFactory;
 }
 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);
 }
Beispiel #12
0
 internal SimpleTemplate(ITypedWebObjectFactory objectFactory)
 {
     Util.CheckAssignableType(typeof(UserControl), objectFactory.InstantiatedType);
     this._objectFactory = objectFactory;
 }
Beispiel #13
0
        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));
        }
        internal SimpleTemplate(ITypedWebObjectFactory objectFactory) {

            // Make sure it's a user control (VSWhidbey 428718)
            Util.CheckAssignableType(typeof(UserControl), objectFactory.InstantiatedType);

            _objectFactory = objectFactory;
        }
    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);
    }
Beispiel #16
0
        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));
        }