예제 #1
0
        internal override Control CreateCachedControl()
        {
            Control cachedControl;

            if (_objectFactory != null)
            {
                cachedControl = (Control)_objectFactory.CreateInstance();
            }
            else
            {
                // Instantiate the control
                cachedControl = (Control)HttpRuntime.CreatePublicInstance(_createCachedControlType, _args);
            }

            // If it's a user control, do some extra initialization
            UserControl uc = cachedControl as UserControl;

            if (uc != null)
            {
                uc.InitializeAsUserControl(Page);
            }

            cachedControl.ID = _ctrlID;

            return(cachedControl);
        }
예제 #2
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);
        }
예제 #3
0
            public virtual void InstantiateIn(Control control)
            {
                UserControl uc = (UserControl)_objectFactory.CreateInstance();

                uc.InitializeAsUserControl(control.Page);

                control.Controls.Add(uc);
            }
예제 #4
0
        // 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);
        }
예제 #5
0
        // Create a new page adapter for the device.
        internal /*public*/ IPageAdapter NewPageAdapter()
        {
            IPageAdapter a = _pageAdapterFactory.CreateInstance() as IPageAdapter;

            if (a == null)
            {
                throw new Exception(
                          SR.GetString(SR.IndividualDeviceConfig_TypeMustSupportInterface,
                                       _pageAdapterType.FullName, "IPageAdapter"));
            }

            return(a);
        }
예제 #6
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);
            };
        }
 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);
 }
예제 #8
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));
        }
    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);
    }
예제 #10
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));
        }