Пример #1
0
        private void AddModuleToContentPane(Control pane, PageModule module, string ctrlKey, bool editMode)
        {
            string defId = module.ModuleDefinitionID;

            if (!PortalConfiguration.ModuleDefinitions.ContainsKey(defId))
            {
                ShowError(pane, String.Format("Module definition '{0}' could not be found", defId));
                return;
            }

            ModuleDefinition definition = PortalConfiguration.ModuleDefinitions[defId];
            ModuleControl    control    = null;

            if (String.IsNullOrEmpty(ctrlKey))
            {
                control = definition.DefaultControl;
            }
            else
            {
                if (definition.Controls.ContainsKey(ctrlKey))
                {
                    control = definition.Controls[ctrlKey];
                }
            }

            if (control == null)
            {
                return;
            }

            // container
            string containerName = editMode ?
                                   PortalConfiguration.SiteSettings["AdminContainer"] : PortalConfiguration.SiteSettings["PortalContainer"];

            if (!editMode && !String.IsNullOrEmpty(module.ContainerSrc))
            {
                containerName = module.ContainerSrc;
            }

            if (editMode && !String.IsNullOrEmpty(module.AdminContainerSrc))
            {
                containerName = module.AdminContainerSrc;
            }

            // load container
            string  containerPath = "~/" + CONTAINERS_FOLDER + "/" + this.Theme + "/" + containerName;
            Control ctrlContainer = null;

            try
            {
                ctrlContainer = LoadControl(containerPath);
            }
            catch (Exception ex)
            {
                ShowError(pane, String.Format("Container '{0}' could not be loaded: {1}", containerPath, ex.ToString()));
                return;
            }

            string title = module.Title;

            if (editMode || String.IsNullOrEmpty(title))
            {
                // get control title
                title = control.Title;
            }

            string iconFile = module.IconFile;

            if (editMode || String.IsNullOrEmpty(iconFile))
            {
                // get control icon
                iconFile = control.IconFile;
            }

            // set title
            Label lblModuleTitle = (Label)ctrlContainer.FindControl(MODULE_TITLE_CONTROL_ID);

            if (lblModuleTitle != null)
            {
                lblModuleTitle.Text = GetLocalizedModuleTitle(title);
            }

            // set icon
            System.Web.UI.WebControls.Image imgModuleIcon = (System.Web.UI.WebControls.Image)ctrlContainer.FindControl(MODULE_ICON_CONTROL_ID);
            if (imgModuleIcon != null)
            {
                if (String.IsNullOrEmpty(iconFile))
                {
                    imgModuleIcon.Visible = false;
                }
                else
                {
                    string iconPath = "~/" + THEMES_FOLDER + "/" + this.Theme + "/" + ICONS_FOLDER + "/" + iconFile;
                    imgModuleIcon.ImageUrl = iconPath;
                }
            }

            Control contentPane = ctrlContainer.FindControl(CONTENT_PANE_NAME);

            if (contentPane != null)
            {
                string controlName = control.Src;
                string controlPath = "~/" + DESKTOP_MODULES_FOLDER + "/" + controlName;
                if (!String.IsNullOrEmpty(controlName))
                {
                    PortalControlBase ctrlControl = null;
                    try
                    {
                        ctrlControl                  = (PortalControlBase)LoadControl(controlPath);
                        ctrlControl.Module           = module;
                        ctrlControl.ContainerControl = ctrlContainer;
                        contentPane.Controls.Add(ctrlControl);
                    }
                    catch (Exception ex)
                    {
                        ShowError(contentPane, String.Format("Control '{0}' could not be loaded: {1}", controlPath, ex.ToString()));
                    }
                }
            }


            // add controls to the pane
            pane.Controls.Add(ctrlContainer);
        }
Пример #2
0
        private static void LoadModulesFromXml(Dictionary <string, ModuleDefinition> modules, string path)
        {
            // open xml document
            XmlDocument xml = new XmlDocument();

            xml.Load(path);

            // select nodes
            XmlNodeList xmlModules = xml.SelectNodes("ModuleDefinitions/ModuleDefinition");

            foreach (XmlNode xmlModule in xmlModules)
            {
                ModuleDefinition module = new ModuleDefinition();
                if (xmlModule.Attributes["id"] == null)
                {
                    throw new Exception(String.Format("Module ID is not specified. File: {0}, Node: {1}",
                                                      path, xmlModule.OuterXml));
                }

                module.Id = xmlModule.Attributes["id"].Value.ToLower(CultureInfo.InvariantCulture);
                modules.Add(module.Id, module);

                // controls
                XmlNodeList xmlControls = xmlModule.SelectNodes("Controls/Control");
                foreach (XmlNode xmlControl in xmlControls)
                {
                    ModuleControl control = new ModuleControl();
                    if (xmlControl.Attributes["icon"] != null)
                    {
                        control.IconFile = xmlControl.Attributes["icon"].Value;
                    }

                    if (xmlControl.Attributes["key"] != null)
                    {
                        control.Key = xmlControl.Attributes["key"].Value.ToLower(CultureInfo.InvariantCulture);
                    }

                    if (xmlControl.Attributes["src"] == null)
                    {
                        throw new Exception(String.Format("Control 'src' is not specified. File: {0}, Node: {1}",
                                                          path, xmlControl.ParentNode.OuterXml));
                    }
                    control.Src = xmlControl.Attributes["src"].Value;

                    if (xmlControl.Attributes["title"] == null)
                    {
                        throw new Exception(String.Format("Control 'title' is not specified. File: {0}, Node: {1}",
                                                          path, xmlControl.ParentNode.OuterXml));
                    }
                    control.Title = xmlControl.Attributes["title"].Value;

                    if (xmlControl.Attributes["type"] != null)
                    {
                        control.ControlType = (ModuleControlType)Enum.Parse(typeof(ModuleControlType), xmlControl.Attributes["type"].Value, true);
                    }
                    else
                    {
                        control.ControlType = ModuleControlType.View;
                    }

                    if (String.IsNullOrEmpty(control.Key))
                    {
                        module.DefaultControl = control;
                    }

                    module.Controls.Add(control.Key, control);
                }
            }
        }