Пример #1
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());
                        }
                    }
                }
            }
        }
Пример #2
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());
                    }
                }
            }
        }
        public void LoadOtherWidgets(List<Widget> 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 (Widget item in widgetModels.OrderBy(x => x.WidgetId))
            {
                using (MixERPWidget widget = page.LoadControl(item.WidgetSource) as MixERPWidget)
                {
                    if (widget != null)
                    {
                        placeholder.Controls.Add(widget);
                        widget.OnControlLoad(widget, new EventArgs());
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Creates the specified page.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="controlUid">The control uid.</param>
        /// <returns></returns>
        public static Control Create(TemplateControl page, string controlUid)
        {
            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 Control LoadInjectedControl(TemplateControl templateControl, string virtualPath)
        {
            var ctrl = templateControl.LoadControl(virtualPath);
            var userControl = ctrl as TemplateControl;
            if (userControl != null)
            {
                TemplateClassDependencyInjector.InjectDependency(userControl);
            }

            return ctrl;
        }
Пример #6
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;
        }
Пример #7
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);
        }
		/// <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;
		}
Пример #9
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;
        }
Пример #10
0
		public static Control LoadControlInvoker(TemplateControl templateControl, string virtualPath) {
			return templateControl.LoadControl(virtualPath);
		}
Пример #11
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;
        }
Пример #12
0
        /// <summary>
        /// Creates the property page.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="controlUid">The control uid.</param>
        /// <returns></returns>
        public static Control CreatePropertyPage(TemplateControl page, string controlUid)
        {
            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.Split('_')[0]);
            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.PropertyPagePath))
                retVal = page.LoadControl(CreateControlVirtualPath(info.PropertyPagePath));
            else if (!string.IsNullOrEmpty(info.PropertyPageType))
                retVal = (Control)AssemblyUtil.LoadObject(info.PropertyPageType);

            //TODO: Load default PP control
            //if (retVal == null)
            //    retVal = page.LoadControl();

            if (retVal == null)
                throw new InvalidOperationException(String.Format("Cant load PropertyPageControl for control: {0}", controlUid));

            return retVal;
        }
Пример #13
0
        private static IForum GetForum(TemplateControl caller)
        {
            if (isForumLoaded)
                return forum;

            lock (forumSync)
            {
                if (isForumLoaded)
                    return forum;

                if (IsForumModuleInstalled)
                    forum = caller.LoadControl("forum.ascx") as IForum;

                isForumLoaded = true;
                return forum;
            }
        }
Пример #14
0
        private static ICatalog GetCatalog(TemplateControl caller)
        {
            if (isCatalogLoaded)
                return catalog;

            lock (catalogSync)
            {
                if (isCatalogLoaded)
                    return catalog;

                if (IsCatalogModuleInstalled)
                    catalog = caller.LoadControl("catalog.ascx") as ICatalog;

                isCatalogLoaded = true;
                return catalog;
            }
        }