コード例 #1
0
        public static Control LoadModuleControl(TemplateControl containerControl, ModuleInfo moduleConfiguration, string controlKey, string controlSrc)
        {
            if (TracelLogger.IsDebugEnabled)
            {
                TracelLogger.Debug($"ModuleControlFactory.LoadModuleControl Start (TabId:{moduleConfiguration.TabID},ModuleId:{moduleConfiguration.ModuleID}): ModuleControlSource:{moduleConfiguration.ModuleControl.ControlSrc}");
            }

            Control control = null;
            IModuleControlFactory controlFactory = GetModuleControlFactory(controlSrc);

            if (controlFactory != null)
            {
                control = controlFactory.CreateControl(containerControl, controlKey, controlSrc);
            }

            // 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(controlSrc);

                var moduleControl = control as IModuleControl;

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

            if (TracelLogger.IsDebugEnabled)
            {
                TracelLogger.Debug($"ModuleControlFactory.LoadModuleControl End (TabId:{moduleConfiguration.TabID},ModuleId:{moduleConfiguration.ModuleID}): ModuleControlSource:{moduleConfiguration.ModuleControl.ControlSrc}");
            }
            return(control);
        }
コード例 #2
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.CreateObject(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);
        }
コード例 #3
0
        private static IModuleControlFactory GetModuleControlFactory(string controlSrc)
        {
            string extension = Path.GetExtension(controlSrc.ToLowerInvariant());

            IModuleControlFactory controlFactory = null;
            Type factoryType;

            switch (extension)
            {
            case ".ascx":
                controlFactory = new WebFormsModuleControlFactory();
                break;

            case ".html":
            case ".htm":
                controlFactory = new Html5ModuleControlFactory();
                break;

            case ".cshtml":
            case ".vbhtml":
                factoryType = Reflection.CreateType("DotNetNuke.Web.Razor.RazorModuleControlFactory");
                if (factoryType != null)
                {
                    controlFactory = Reflection.CreateObject(factoryType) as IModuleControlFactory;
                }

                break;

            case ".mvc":
                factoryType = Reflection.CreateType("DotNetNuke.Web.Mvc.MvcModuleControlFactory");
                if (factoryType != null)
                {
                    controlFactory = Reflection.CreateObject(factoryType) as IModuleControlFactory;
                }

                break;

            default:
                controlFactory = new ReflectedModuleControlFactory();
                break;
            }

            return(controlFactory);
        }
コード例 #4
0
        public Control CreateModuleControl(ModuleInfo moduleConfiguration)
        {
            IModuleControlFactory factory = GetModuleControlFactory(moduleConfiguration.ModuleControl.ControlSrc);

            return(factory.CreateModuleControl(moduleConfiguration));
        }