Ejemplo n.º 1
0
        public void LoadWidgets(IEnumerable<DefaultWidgetSetupView> widgetModels, Control placeholder, TemplateControl page)
        {
            if (placeholder == null)
            {
                return;
            }

            if (page == null)
            {
                return;
            }

            if (widgetModels == null)
            {
                return;
            }

            foreach (DefaultWidgetSetupView item in widgetModels.OrderBy(x => x.WidgetOrder))
            {
                using (MixERPWidget widget = page.LoadControl(item.WidgetSource) as MixERPWidget)
                {
                    if (widget != null)
                    {
                        placeholder.Controls.Add(widget);
                        widget.OnControlLoad(widget, new EventArgs());
                    }
                }
            }
        }
 internal virtual void FrameworkInitialize(TemplateControl templateControl)
 {
     HttpContext current = HttpContext.Current;
     TemplateControl control = current.TemplateControl;
     current.TemplateControl = templateControl;
     try
     {
         if (!this._initialized)
         {
             lock (this)
             {
                 this._rootBuilder.InitObject(templateControl);
             }
             this._initialized = true;
         }
         else
         {
             this._rootBuilder.InitObject(templateControl);
         }
     }
     finally
     {
         if (control != null)
         {
             current.TemplateControl = control;
         }
     }
 }
        public void LoadSelectedWidgets(List<WidgetSetupView> widgetModels, Control placeholder, TemplateControl page)
        {
            if (placeholder == null)
            {
                return;
            }

            if (page == null)
            {
                return;
            }

            if (widgetModels == null || widgetModels.Count().Equals(0))
            {
                this.AppendNotFoundMessage(placeholder);
                return;
            }


            foreach (WidgetSetupView item in widgetModels.OrderBy(x => x.WidgetOrder))
            {
                using (MixERPWidget widget = page.LoadControl(item.WidgetSource) as MixERPWidget)
                {
                    if (widget != null)
                    {
                        placeholder.Controls.Add(widget);
                        widget.OnControlLoad(widget, new EventArgs());
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public void LoadWidgets(IEnumerable<Widget> widgetModels, Control placeholder, TemplateControl page)
        {
            if (placeholder == null)
            {
                return;
            }

            if (page == null)
            {
                return;
            }

            if (widgetModels == null)
            {
                return;
            }

            var groups = widgetModels.OrderBy(x => x.RowNumber).ThenBy(x => x.ColumnNumber).GroupBy(x => new {x.RowNumber});

            foreach (var group in groups)
            {
                foreach (Widget item in group)
                {
                    using (MixERPWidgetBase widget = page.LoadControl(item.WidgetSource) as MixERPWidgetBase)
                    {
                        if (widget != null)
                        {
                            placeholder.Controls.Add(widget);
                            widget.OnControlLoad(widget, new EventArgs());
                        }
                    }
                }
            }
        }
        public virtual void InstantiateIn(Control container)
        {
            IServiceProvider serviceProvider = null;

            if (this._designerHost != null)
            {
                serviceProvider = this._designerHost;
            }
            else if (!base.IsNoCompile)
            {
                ServiceContainer container2 = new ServiceContainer();
                if (container is IThemeResolutionService)
                {
                    container2.AddService(typeof(IThemeResolutionService), (IThemeResolutionService)container);
                }
                if (container is IFilterResolutionService)
                {
                    container2.AddService(typeof(IFilterResolutionService), (IFilterResolutionService)container);
                }
                serviceProvider = container2;
            }
            HttpContext     current         = null;
            TemplateControl templateControl = null;
            TemplateControl control2        = container as TemplateControl;

            if (control2 != null)
            {
                current = HttpContext.Current;
                if (current != null)
                {
                    templateControl = current.TemplateControl;
                }
            }
            try
            {
                if (!base.IsNoCompile)
                {
                    base.SetServiceProvider(serviceProvider);
                }
                if (current != null)
                {
                    current.TemplateControl = control2;
                }
                this.BuildChildren(container);
            }
            finally
            {
                if (!base.IsNoCompile)
                {
                    base.SetServiceProvider(null);
                }
                if (current != null)
                {
                    current.TemplateControl = templateControl;
                }
            }
        }
 private static void InitializeField(Queue<TemplateControl> queue, TemplateControl control, FieldInfo field)
 {
     var userControl = field.GetValue(control) as UserControl;
     if (userControl != null)
     {
         TemplateClassDependencyInjector.InjectDependency(userControl);
         queue.Enqueue(userControl);
     }
 }
		/// <summary>
		/// Initializes a new instance of the MultiBindableTemplate class.
		/// </summary>
		/// <param name="control"></param>
		/// <param name="paths"></param>
		public MultiBindableTemplate(TemplateControl control, params String[] paths)
		{
			_templates = new IBindableTemplate[paths.Length];

			for ( int i=0; i<paths.Length; i++ )
			{
				_templates[i] = FormUtil.LoadBindableTemplate(control, paths[i]);
			}
		}
Ejemplo n.º 8
0
        public ControlLocalizer (TemplateControl control)
        {
            LocalResourceFile = Localization.GetResourceFile (control, Path.GetFileName (control.AppRelativeVirtualPath));

            // skinobjects must use resources from parent (skins) directory
            if (control is SkinObjectBase) {
                LocalResourceFile = LocalResourceFile.Replace ("/SkinObjects", string.Empty);
            }
        }
        public static Control LoadInjectedControl(TemplateControl templateControl, string virtualPath)
        {
            var ctrl = templateControl.LoadControl(virtualPath);
            var userControl = ctrl as TemplateControl;
            if (userControl != null)
            {
                TemplateClassDependencyInjector.InjectDependency(userControl);
            }

            return ctrl;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Returns a string value stored in resources.
        /// </summary>
        /// <param name="control">Current page or usercontrol</param>
        /// <param name="resourceKey">Resource key.</param>
        /// <returns>String value stored in resources</returns>
        public static string GetResourceString(TemplateControl control, string resourceKey)
        {
            string resourceString = (string)HttpContext.GetLocalResourceObject(control.AppRelativeVirtualPath, resourceKey);
            if (resourceString != null)
            {
                return resourceString;
            }

            Logger.Log(String.Format("String '{0}' was not found in resources", resourceKey), LogLevel.Warn);
            return String.Format("[{0}]", resourceKey);
        }
Ejemplo n.º 11
0
		public Control LoadControl(TemplateControl templateControl, string virtualPath, string varyByCustom) {
			var cacheKey = GetCacheKey(virtualPath, varyByCustom);
			if(!delegateStore.ContainsKey(cacheKey)) {
				lock(padLock) {
					if(!delegateStore.ContainsKey(cacheKey)) {
						delegateStore[cacheKey] = CreateLoadControlDelegate();
					}
				}
			}
			return delegateStore[cacheKey](templateControl, virtualPath);
		}
        internal static MasterPage CreateMaster(TemplateControl owner, HttpContext context, VirtualPath masterPageFile, IDictionary contentTemplateCollection)
        {
            MasterPage child = null;

            if (masterPageFile == null)
            {
                if ((contentTemplateCollection != null) && (contentTemplateCollection.Count > 0))
                {
                    throw new HttpException(System.Web.SR.GetString("Content_only_allowed_in_content_page"));
                }
                return(null);
            }
            VirtualPath            virtualPath      = VirtualPathProvider.CombineVirtualPathsInternal(owner.TemplateControlVirtualPath, masterPageFile);
            ITypedWebObjectFactory vPathBuildResult = (ITypedWebObjectFactory)BuildManager.GetVPathBuildResult(context, virtualPath);

            if (!typeof(MasterPage).IsAssignableFrom(vPathBuildResult.InstantiatedType))
            {
                throw new HttpException(System.Web.SR.GetString("Invalid_master_base", new object[] { masterPageFile }));
            }
            child = (MasterPage)vPathBuildResult.CreateInstance();
            child.TemplateControlVirtualPath = virtualPath;
            if (owner.HasControls())
            {
                foreach (Control control in owner.Controls)
                {
                    LiteralControl control2 = control as LiteralControl;
                    if ((control2 == null) || (System.Web.UI.Util.FirstNonWhiteSpaceIndex(control2.Text) >= 0))
                    {
                        throw new HttpException(System.Web.SR.GetString("Content_allowed_in_top_level_only"));
                    }
                }
                owner.Controls.Clear();
            }
            if (owner.Controls.IsReadOnly)
            {
                throw new HttpException(System.Web.SR.GetString("MasterPage_Cannot_ApplyTo_ReadOnly_Collection"));
            }
            if (contentTemplateCollection != null)
            {
                foreach (string str in contentTemplateCollection.Keys)
                {
                    if (!child.ContentPlaceHolders.Contains(str.ToLower(CultureInfo.InvariantCulture)))
                    {
                        throw new HttpException(System.Web.SR.GetString("MasterPage_doesnt_have_contentplaceholder", new object[] { str, masterPageFile }));
                    }
                }
                child._contentTemplates = contentTemplateCollection;
            }
            child._ownerControl = owner;
            child.InitializeAsUserControl(owner.Page);
            owner.Controls.Add(child);
            return(child);
        }
 internal ResourceBasedLiteralControl(TemplateControl tplControl, int offset, int size, bool fAsciiOnly)
 {
     if ((offset < 0) || ((offset + size) > tplControl.MaxResourceOffset))
     {
         throw new ArgumentException();
     }
     this._tplControl = tplControl;
     this._offset     = offset;
     this._size       = size;
     this._fAsciiOnly = fAsciiOnly;
     base.PreventAutoID();
     this.EnableViewState = false;
 }
 internal ResourceBasedLiteralControl(TemplateControl tplControl, int offset, int size, bool fAsciiOnly)
 {
     if ((offset < 0) || ((offset + size) > tplControl.MaxResourceOffset))
     {
         throw new ArgumentException();
     }
     this._tplControl = tplControl;
     this._offset = offset;
     this._size = size;
     this._fAsciiOnly = fAsciiOnly;
     base.PreventAutoID();
     this.EnableViewState = false;
 }
Ejemplo n.º 15
0
        internal static MasterPage CreateMasterPage(TemplateControl owner, HttpContext context,
                                                    string masterPageFile, IDictionary contentTemplateCollection)
        {
            var req = context.Request;

            if (req != null)
            {
                masterPageFile = HostingEnvironment.VirtualPathProvider.CombineVirtualPaths(req.CurrentExecutionFilePath, masterPageFile);
            }
#if TARGET_JVM
            MasterPage masterPage = MasterPageParser.GetCompiledMasterInstance(masterPageFile,
                                                                               owner.Page.MapPath(masterPageFile),
                                                                               context);
#else
            MasterPage masterPage = BuildManager.CreateInstanceFromVirtualPath(masterPageFile, typeof(MasterPage)) as MasterPage;
#endif
            if (masterPage == null)
            {
                throw new HttpException("Failed to create MasterPage instance for '" + masterPageFile + "'.");
            }

            if (contentTemplateCollection != null)
            {
                foreach (string templateName in contentTemplateCollection.Keys)
                {
                    if (masterPage.ContentTemplates [templateName] == null)
                    {
                        masterPage.ContentTemplates [templateName] = contentTemplateCollection[templateName];
                    }
                }
            }

            masterPage.Page = owner.Page;
            masterPage.InitializeAsUserControlInternal();

            List <string> placeholders = masterPage.placeholders;
            if (contentTemplateCollection != null && placeholders != null && placeholders.Count > 0)
            {
                foreach (string templateName in contentTemplateCollection.Keys)
                {
                    if (!placeholders.Contains(templateName.ToLowerInvariant()))
                    {
                        throw new HttpException(
                                  String.Format("Cannot find ContentPlaceHolder '{0}' in the master page '{1}'",
                                                templateName, masterPageFile));
                    }
                }
            }

            return(masterPage);
        }
 internal static MasterPage CreateMaster(TemplateControl owner, HttpContext context, VirtualPath masterPageFile, IDictionary contentTemplateCollection)
 {
     MasterPage child = null;
     if (masterPageFile == null)
     {
         if ((contentTemplateCollection != null) && (contentTemplateCollection.Count > 0))
         {
             throw new HttpException(System.Web.SR.GetString("Content_only_allowed_in_content_page"));
         }
         return null;
     }
     VirtualPath virtualPath = VirtualPathProvider.CombineVirtualPathsInternal(owner.TemplateControlVirtualPath, masterPageFile);
     ITypedWebObjectFactory vPathBuildResult = (ITypedWebObjectFactory) BuildManager.GetVPathBuildResult(context, virtualPath);
     if (!typeof(MasterPage).IsAssignableFrom(vPathBuildResult.InstantiatedType))
     {
         throw new HttpException(System.Web.SR.GetString("Invalid_master_base", new object[] { masterPageFile }));
     }
     child = (MasterPage) vPathBuildResult.CreateInstance();
     child.TemplateControlVirtualPath = virtualPath;
     if (owner.HasControls())
     {
         foreach (Control control in owner.Controls)
         {
             LiteralControl control2 = control as LiteralControl;
             if ((control2 == null) || (System.Web.UI.Util.FirstNonWhiteSpaceIndex(control2.Text) >= 0))
             {
                 throw new HttpException(System.Web.SR.GetString("Content_allowed_in_top_level_only"));
             }
         }
         owner.Controls.Clear();
     }
     if (owner.Controls.IsReadOnly)
     {
         throw new HttpException(System.Web.SR.GetString("MasterPage_Cannot_ApplyTo_ReadOnly_Collection"));
     }
     if (contentTemplateCollection != null)
     {
         foreach (string str in contentTemplateCollection.Keys)
         {
             if (!child.ContentPlaceHolders.Contains(str.ToLower(CultureInfo.InvariantCulture)))
             {
                 throw new HttpException(System.Web.SR.GetString("MasterPage_doesnt_have_contentplaceholder", new object[] { str, masterPageFile }));
             }
         }
         child._contentTemplates = contentTemplateCollection;
     }
     child._ownerControl = owner;
     child.InitializeAsUserControl(owner.Page);
     owner.Controls.Add(child);
     return child;
 }
        public void InstantiateInContentPlaceHolder(Control contentPlaceHolder, ITemplate template)
        {
            HttpContext     current         = HttpContext.Current;
            TemplateControl templateControl = current.TemplateControl;

            current.TemplateControl = this._ownerControl;
            try
            {
                template.InstantiateIn(contentPlaceHolder);
            }
            finally
            {
                current.TemplateControl = templateControl;
            }
        }
Ejemplo n.º 18
0
        public static Control LoadModuleControl(TemplateControl containerControl, ModuleInfo moduleConfiguration)
        {
            Control control = null;

            string extension = Path.GetExtension(moduleConfiguration.ModuleControl.ControlSrc.ToLower());

            IModuleControlFactory controlFactory = null;
            switch (extension)
            {
                case ".ascx":
                    controlFactory = new WebFormsModuleControlFactory();
                    break;
                case ".cshtml":
                case ".vbhtml":
                    Type factoryType = Reflection.CreateType("DotNetNuke.Web.Razor.RazorModuleControlFactory");
                    if (factoryType != null)
                    {
                        controlFactory = Reflection.CreateInstance(factoryType) as IModuleControlFactory;
                    }
                    break;
                default:
                    // load from a typename in an assembly ( ie. server control)
                    Type objType = Reflection.CreateType(moduleConfiguration.ModuleControl.ControlSrc);
                    control = (containerControl.LoadControl(objType, null));
                    break;
            }

            if (controlFactory != null)
            {
                control = controlFactory.CreateModuleControl(containerControl, moduleConfiguration);
            }

            // set the control ID to the resource file name ( ie. controlname.ascx = controlname )
            // this is necessary for the Localization in PageBase
            if (control != null)
            {
                control.ID = Path.GetFileNameWithoutExtension(moduleConfiguration.ModuleControl.ControlSrc);

                var moduleControl = control as IModuleControl;

                if (moduleControl != null)
                {
                    moduleControl.ModuleContext.Configuration = moduleConfiguration;
                }
            }

            return control;
        }
Ejemplo n.º 19
0
        private bool _fAsciiOnly; // Does the string contain only 7-bit ascii characters

        internal ResourceBasedLiteralControl(TemplateControl tplControl, int offset, int size, bool fAsciiOnly)
        {
            // Make sure we don't access invalid data
            if (offset < 0 || offset + size > tplControl.MaxResourceOffset)
            {
                throw new ArgumentException();
            }

            _tplControl = tplControl;
            _offset     = offset;
            _size       = size;
            _fAsciiOnly = fAsciiOnly;

            PreventAutoID();
            EnableViewState = false;
        }
Ejemplo n.º 20
0
        public Control ParseControl(string content)
        {
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }

#if NET_2_0
            // FIXME: This method needs to be rewritten in some sane way - the way it is now,
            // is a kludge. New version should not use
            // UserControlParser.GetCompiledType, but instead resort to some other way
            // of creating the content (template instantiation? BuildManager? TBD)
            TextReader reader  = new StringReader(content);
            Type       control = UserControlParser.GetCompiledType(reader, content.GetHashCode(), HttpContext.Current);
            if (control == null)
            {
                return(null);
            }

            TemplateControl parsedControl = Activator.CreateInstance(control, null) as TemplateControl;
            if (parsedControl == null)
            {
                return(null);
            }

            if (this is System.Web.UI.Page)
            {
                parsedControl.Page = (System.Web.UI.Page) this;
            }
            parsedControl.FrameworkInitialize();

            Control   ret   = new Control();
            int       count = parsedControl.Controls.Count;
            Control[] parsedControlControls = new Control [count];
            parsedControl.Controls.CopyTo(parsedControlControls, 0);

            for (int i = 0; i < count; i++)
            {
                ret.Controls.Add(parsedControlControls [i]);
            }

            parsedControl = null;
            return(ret);
#else
            return(null);
#endif
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Creates the specified page.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="controlUid">The control uid.</param>
        /// <param name="instanseUid">The instanse uid.</param>
        /// <returns></returns>
        public static Control Create(TemplateControl page, string controlUid, string instanseUid)
        {
            if (page == null)
                throw new ArgumentNullException("page");

            if (controlUid == null)
                throw new ArgumentNullException("controlUid");

            Initialize();
            Control retVal = null;

            // Load Control Info
            DynamicControlInfo info = GetControlInfo(controlUid);
            if (info == null)
                return null;
            //throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid control Uid '{0}'", controlUid), "controlUid");

            // Try Load Control
            if (!string.IsNullOrEmpty(info.Path))
                retVal = page.LoadControl(CreateControlVirtualPath(info.Path));
            else if (!string.IsNullOrEmpty(info.Type))
                retVal = (Control)AssemblyUtil.LoadObject(info.Type);

            // Try Load Adapter
            if (retVal != null && (!string.IsNullOrEmpty(info.AdapterPath) || !string.IsNullOrEmpty(info.AdapterType)))
            {
                Control adapter = null;

                if (!string.IsNullOrEmpty(info.Path))
                    adapter = page.LoadControl(CreateControlVirtualPath(info.AdapterPath));
                else if (!string.IsNullOrEmpty(info.Type))
                    adapter = (Control)AssemblyUtil.LoadObject(info.AdapterType);

                if (adapter != null)
                {
                    // Add Control to adapter
                    adapter.Controls.Add(retVal);

                    // Return adapter
                    retVal = adapter;
                }
            }

            return retVal;
        }
        public static void InjectDependency(TemplateControl control)
        {
            try
            {
                var ctrlType = control.GetType().BaseType;
                ConstructorInfo ctor;
                if (!_typeConstructor.TryGetValue(ctrlType, out ctor))
                {
                    var ctors = ctrlType.GetConstructors();
                    if (ctors.Length == 0)
                    {
                        return;
                    }

                    ctor = ctors[0];
                    for (int i = 1; i < ctors.Length; i++)
                    {
                        if (ctor.GetParameters()
                                .Length < ctors[i].GetParameters()
                                                  .Length)
                        {
                            ctor = ctors[i];
                        }
                    }

                    if (!_typeConstructor.ContainsKey(ctrlType))
                    {
                        _typeConstructor.Add(ctrlType, ctor);
                    }
                }

                var paramTypes = ctor.GetParameters();
                var paramValues = new object[paramTypes.Length];
                for (int i = 0; i < paramTypes.Length; i++)
                {
                    paramValues[i] = DependencyResolver.GetDependencyResolver()
                                                       .GetService(paramTypes[i].ParameterType);
                }

                ctor.Invoke(control, paramValues);
            }
            catch { }
        }
        public void InstantiateInContentPlaceHolder(Control contentPlaceHolder, ITemplate template)
        {
            HttpContext context = HttpContext.Current;

            // Remember the old TemplateControl
            TemplateControl oldControl = context.TemplateControl;

            // Storing the template control into the context
            // since each thread needs to set it differently.
            context.TemplateControl = _ownerControl;

            try {
                // Instantiate the template using the correct TemplateControl
                template.InstantiateIn(contentPlaceHolder);
            }
            finally {
                // Revert back to the old templateControl
                context.TemplateControl = oldControl;
            }
        }
Ejemplo n.º 24
0
        internal static ResourceManager GetLocalResourceManager( TemplateControl control )
        {
            IResourceProvider localResourceProvider = GetLocalResourceProvider( control );
            if (localResourceProvider == null)
            {
                return null;
            }

            if (localResourceProvider.GetType() == LocalResXResourceProviderType)
            {
                Assembly localResourceAssembly = GetLocalResourceAssembly( control );
                if (localResourceAssembly != null)
                {
                    return new LocalResXAssemblyResourceManager(control, localResourceAssembly);
                }
                else
                {
                    return null;
                }
            }

            return new ResourceProviderResourceManager(localResourceProvider);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Loads a user control with a constructor with a signature matching the supplied params
        /// Control must implement a blank default constructor as well as the custom one or we will error
        /// </summary>
        /// <param name="templateControl">Template control base object</param>
        /// <param name="controlPath">Path to the user control</param>
        /// <param name="constructorParams">Parameters for the constructor</param>
        /// <returns></returns>
        public static UserControl LoadControl(this TemplateControl templateControl, string controlPath, params object[] constructorParams)
        {
            List <Type> constParamTypes = new List <Type>();

            foreach (object constParam in constructorParams)
            {
                constParamTypes.Add(constParam.GetType());
            }

            UserControl ctl = templateControl.LoadControl(controlPath) as UserControl;

            // Find the relevant constructor
            ConstructorInfo constructor = ctl.GetType().BaseType.GetConstructor(constParamTypes.ToArray());

            //And then call the relevant constructor
            if (constructor == null)
            {
                throw new MemberAccessException("The requested constructor was not found on : " + ctl.GetType().BaseType.ToString());
            }
            constructor.Invoke(ctl, constructorParams);

            // Finally return the fully initialized UC
            return(ctl);
        }
Ejemplo n.º 26
0
        private bool _fAsciiOnly;    // Does the string contain only 7-bit ascii characters

        internal ResourceBasedLiteralControl(TemplateControl tplControl, int offset, int size, bool fAsciiOnly) {

            // Make sure we don't access invalid data
            if (offset < 0 || offset+size > tplControl.MaxResourceOffset)
                throw new ArgumentException();

            _tplControl = tplControl;
            _offset = offset;
            _size = size;
            _fAsciiOnly = fAsciiOnly;

            PreventAutoID();
            EnableViewState = false;
        }
 public static void SetOwnerControl(this MasterPage master, TemplateControl owner)
 {
     var f = typeof(MasterPage).GetField("_ownerControl", BindingFlags.NonPublic | BindingFlags.Instance);
       f.SetValue(master, owner);
 }
Ejemplo n.º 28
0
 internal ScriptTemplateControl(TemplateControl templateControl) {
     _templateControl = templateControl;
 }
Ejemplo n.º 29
0
        /// <summary>
        /// Get a <see cref="System.Web.UI.Control">Control</see> from the specified 
        /// loation.
        /// </summary>
        /// <param name="controlLocation">The location of the control.</param>
        /// <returns>The control to display on the screen.</returns>
        public Control GetControlFromLocation(string controlLocation)
        {
            Control skin = new Control();
            TemplateControl template = new TemplateControl();
            template.AppRelativeVirtualPath = "~" + SectionInfo.Current.UrlPath.PathAndQuery;

            // checks to see if the application path was included in the controlLocation
            controlLocation = GetDiskPath(controlLocation, WebApplicationPath);

            // attempt to load control
            try { skin = template.LoadControl(controlLocation); }
            catch (FileNotFoundException)
            {
                // nothing worked code is giving up
                throw new  ApplicationException(controlLocation);
            }

            return skin;
        }
Ejemplo n.º 30
0
		internal static MasterPage CreateMasterPage (TemplateControl owner, HttpContext context,
							     string masterPageFile, IDictionary contentTemplateCollection)
		{
#if TARGET_JVM
			MasterPage masterPage = MasterPageParser.GetCompiledMasterInstance (masterPageFile,
											    owner.Page.MapPath (masterPageFile),
											    context);
#else
			MasterPage masterPage = BuildManager.CreateInstanceFromVirtualPath (masterPageFile, typeof (MasterPage)) as MasterPage;
#endif
			if (masterPage == null)
				throw new HttpException ("Failed to create MasterPage instance for '" + masterPageFile + "'.");

			if (contentTemplateCollection != null) {
				foreach (string templateName in contentTemplateCollection.Keys) {
					if (masterPage.ContentTemplates [templateName] == null)
						masterPage.ContentTemplates [templateName] = contentTemplateCollection[templateName];
				}
			}
			
			masterPage.Page = owner.Page;
			masterPage.InitializeAsUserControlInternal ();

			List <string> placeholders = masterPage.placeholders;
			if (contentTemplateCollection != null && placeholders != null && placeholders.Count > 0) {
				foreach (string templateName in contentTemplateCollection.Keys) {
					if (!placeholders.Contains (templateName.ToLowerInvariant ())) {
						throw new HttpException (
							String.Format ("Cannot find ContentPlaceHolder '{0}' in the master page '{1}'",
								       templateName, masterPageFile));
					}
				}
			}

			return masterPage;
		}
 public Control CreateModuleControl(TemplateControl containerControl, ModuleInfo moduleConfiguration)
 {
     return ControlUtilities.LoadControl<Control>(containerControl, moduleConfiguration.ModuleControl.ControlSrc);
 }
Ejemplo n.º 32
0
 public ExpressionBuilderContext(System.Web.UI.TemplateControl templateControl)
 {
     this._templateControl = templateControl;
 }
 public Control CreateModuleControl(TemplateControl containerControl, ModuleInfo moduleConfiguration)
 {
     return new RazorHostControl("~/" + moduleConfiguration.ModuleControl.ControlSrc);
 }
		public ExpressionBuilderContext (TemplateControl templateControl)
		{
			this.tcontrol = templateControl;
		}
Ejemplo n.º 35
0
		public static Control LoadControlInvoker(TemplateControl templateControl, string virtualPath) {
			return templateControl.LoadControl(virtualPath);
		}
        internal static MasterPage CreateMaster(TemplateControl owner, HttpContext context,
                                                VirtualPath masterPageFile, IDictionary contentTemplateCollection)
        {
            Debug.Assert(owner is MasterPage || owner is Page);

            MasterPage master = null;

            if (masterPageFile == null)
            {
                if (contentTemplateCollection != null && contentTemplateCollection.Count > 0)
                {
                    throw new HttpException(SR.GetString(SR.Content_only_allowed_in_content_page));
                }

                return(null);
            }

            // If it's relative, make it *app* relative.  Treat is as relative to this
            // user control (ASURT 55513)
            VirtualPath virtualPath = VirtualPathProvider.CombineVirtualPathsInternal(
                owner.TemplateControlVirtualPath, masterPageFile);

            // Compile the declarative control and get its Type
            ITypedWebObjectFactory result = (ITypedWebObjectFactory)BuildManager.GetVPathBuildResult(
                context, virtualPath);

            // Make sure it has the correct base type
            if (!typeof(MasterPage).IsAssignableFrom(result.InstantiatedType))
            {
                throw new HttpException(SR.GetString(SR.Invalid_master_base,
                                                     masterPageFile));
            }

            master = (MasterPage)result.CreateInstance();

            master.TemplateControlVirtualPath = virtualPath;

            if (owner.HasControls())
            {
                foreach (Control control in owner.Controls)
                {
                    LiteralControl literal = control as LiteralControl;
                    if (literal == null || Util.FirstNonWhiteSpaceIndex(literal.Text) >= 0)
                    {
                        throw new HttpException(SR.GetString(SR.Content_allowed_in_top_level_only));
                    }
                }

                // Remove existing controls.
                owner.Controls.Clear();
            }

            // Make sure the control collection is writable.
            if (owner.Controls.IsReadOnly)
            {
                throw new HttpException(SR.GetString(SR.MasterPage_Cannot_ApplyTo_ReadOnly_Collection));
            }

            if (contentTemplateCollection != null)
            {
                foreach (String contentName in contentTemplateCollection.Keys)
                {
                    if (!master.ContentPlaceHolders.Contains(contentName.ToLower(CultureInfo.InvariantCulture)))
                    {
                        throw new HttpException(SR.GetString(SR.MasterPage_doesnt_have_contentplaceholder, contentName, masterPageFile));
                    }
                }
                master._contentTemplates = contentTemplateCollection;
            }

            master._ownerControl = owner;
            master.InitializeAsUserControl(owner.Page);
            owner.Controls.Add(master);
            return(master);
        }
Ejemplo n.º 37
0
        internal static MasterPage CreateMaster(TemplateControl owner, HttpContext context,
            VirtualPath masterPageFile, IDictionary contentTemplateCollection) {

            Debug.Assert(owner is MasterPage || owner is Page);

            MasterPage master = null;

            if (masterPageFile == null) {
                if (contentTemplateCollection != null && contentTemplateCollection.Count > 0) {
                    throw new HttpException(SR.GetString(SR.Content_only_allowed_in_content_page));
                }
 
                return null;
            }

            // If it's relative, make it *app* relative.  Treat is as relative to this
            // user control (ASURT 55513)
            VirtualPath virtualPath = VirtualPathProvider.CombineVirtualPathsInternal(
                owner.TemplateControlVirtualPath, masterPageFile);

            // Compile the declarative control and get its Type
            ITypedWebObjectFactory result = (ITypedWebObjectFactory)BuildManager.GetVPathBuildResult(
                context, virtualPath);

            // Make sure it has the correct base type
            if (!typeof(MasterPage).IsAssignableFrom(result.InstantiatedType)) {
                throw new HttpException(SR.GetString(SR.Invalid_master_base,
                    masterPageFile));
            }

            master = (MasterPage)result.CreateInstance();
            
            master.TemplateControlVirtualPath = virtualPath;

            if (owner.HasControls()) {
                foreach (Control control in owner.Controls) {
                    LiteralControl literal = control as LiteralControl;
                    if (literal == null || Util.FirstNonWhiteSpaceIndex(literal.Text) >= 0) {
                        throw new HttpException(SR.GetString(SR.Content_allowed_in_top_level_only));
                    }
                }

                // Remove existing controls.
                owner.Controls.Clear();
            }

            // Make sure the control collection is writable.
            if (owner.Controls.IsReadOnly) {
                throw new HttpException(SR.GetString(SR.MasterPage_Cannot_ApplyTo_ReadOnly_Collection));
            }

            if (contentTemplateCollection != null) {
                foreach(String contentName in contentTemplateCollection.Keys) {
                    if (!master.ContentPlaceHolders.Contains(contentName.ToLower(CultureInfo.InvariantCulture))) {
                        throw new HttpException(SR.GetString(SR.MasterPage_doesnt_have_contentplaceholder, contentName, masterPageFile));
                    }
                }
                master._contentTemplates = contentTemplateCollection;
            }

            master._ownerControl = owner;
            master.InitializeAsUserControl(owner.Page);
            owner.Controls.Add(master);
            return master;
        }
Ejemplo n.º 38
0
        // Internals //////////////////////////////////////////////////////
        private Control LoadUserInterface(TemplateControl page, string path)
        {
            if (page == null)
                throw new ArgumentNullException("page");

            Control ui;
            try
            {
                ui = page.LoadControl(path);
            }
            catch (Exception e) //logged
            {
                Logger.WriteException(e);
                HasError = true;
                var msg = String.Format("{0}", e.Message);
                var msgControl = new Label { ID = "RuntimeErrMsg", Text = msg, ForeColor = Color.Red };
                return msgControl;
            }
            return ui;
        }
Ejemplo n.º 39
0
        /*
         * ITemplate implementation
         * This implementation of ITemplate is only used in the designer
         */

        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public virtual void InstantiateIn(Control container)
        {
            IServiceProvider builderServiceProvider = null;

            // Use the designer host to get one at designtime as the service provider
            if (_designerHost != null)
            {
                builderServiceProvider = _designerHost;
            }
            else if (!IsNoCompile)
            {
                // Otherwise, create a ServiceContainer and try using the container as the service provider
                ServiceContainer serviceContainer = new ServiceContainer();
                if (container is IThemeResolutionService)
                {
                    serviceContainer.AddService(typeof(IThemeResolutionService), (IThemeResolutionService)container);
                }

                if (container is IFilterResolutionService)
                {
                    serviceContainer.AddService(typeof(IFilterResolutionService), (IFilterResolutionService)container);
                }
                builderServiceProvider = serviceContainer;
            }

            HttpContext     context = null;
            TemplateControl savedTemplateControl = null;

            TemplateControl templateControl = container as TemplateControl;

            if (templateControl != null)
            {
                context = HttpContext.Current;
                if (context != null)
                {
                    savedTemplateControl = context.TemplateControl;
                }
            }

            try {
                if (!IsNoCompile)
                {
                    SetServiceProvider(builderServiceProvider);
                }

                if (context != null)
                {
                    context.TemplateControl = templateControl;
                }

                BuildChildren(container);
            }
            finally {
                if (!IsNoCompile)
                {
                    SetServiceProvider(null);
                }

                // Restore the previous template control
                if (context != null)
                {
                    context.TemplateControl = savedTemplateControl;
                }
            }
        }
 // Get the page-level IResourceProvider
 internal static IResourceProvider GetLocalResourceProvider(TemplateControl templateControl) {
     return GetLocalResourceProvider(templateControl.VirtualPath);
 }
Ejemplo n.º 41
0
		HttpResponseSubstitutionCallback CreateCallback (string method, TemplateControl tc)
		{
			try {
				return Delegate.CreateDelegate (typeof(HttpResponseSubstitutionCallback),
								tc.GetType (),
								method,
								true,
								true) as HttpResponseSubstitutionCallback;
			} catch (Exception ex) {
				throw new HttpException ("Cannot find static method '" + method + "' matching HttpResponseSubstitutionCallback", ex);
			}
		}
Ejemplo n.º 42
0
		/// <summary>
		/// Loads an instance of an IBindableTemplate from the specified path.
		/// </summary>
		/// <param name="control">The TemplateControl which will perform the load.</param>
		/// <param name="path">The path to the template to load.</param>
		/// <returns>An instance of IBindableTemplate found at the specified path.</returns>
		/// <remarks>
		/// Adapted from an article written by James Crowley, which can be found at:
		/// http://www.developerfusion.co.uk/show/4721/
		/// </remarks>
		public static IBindableTemplate LoadBindableTemplate(TemplateControl control, String path)
		{
			Control container = control.LoadControl(path);
			FormView formView = container.Controls[0] as FormView;

			if ( formView == null )
			{
				throw new Exception("Required FormView control not found as the first child of specified template");
			}

			return (IBindableTemplate) formView.ItemTemplate;
		}
Ejemplo n.º 43
0
 public static object FastEval(this TemplateControl control, string propertyName)
 {
     return(control.FastEval(control.Page.GetDataItem(), propertyName));
 }