示例#1
0
        private string GenerateMarkup(Dictionary <string, string> Attributes)
        {
            try
            {
                PortalSettings ps = PortalController.Instance.GetCurrentSettings() as PortalSettings;

                if (ps != null && ps.ActiveTab != null && ps.ActiveTab.BreadCrumbs == null)
                {
                    ps.ActiveTab.BreadCrumbs = new System.Collections.ArrayList();
                }

                Dictionary <string, string> BaseAttributes = Core.Managers.BlockManager.GetGlobalConfigs(ps, "menu");
                if (Attributes["data-block-global"] == "true")
                {
                    Attributes = BaseAttributes;
                }
                else
                {
                    //Loop on base attributes and add missing attribute
                    foreach (KeyValuePair <string, string> attr in BaseAttributes)
                    {
                        if (!Attributes.ContainsKey(attr.Key))
                        {
                            Attributes.Add(attr.Key, attr.Value);
                        }
                    }
                }

                MenuSetting menuSetting = new MenuSetting
                {
                    NodeSelector  = Attributes["data-block-nodeselector"],
                    IncludeHidden = Convert.ToBoolean(Attributes["data-block-includehidden"]),
                };

                MenuNode rootNode = new MenuNode(
                    Localiser.LocaliseDNNNodeCollection(
                        Navigation.GetNavigationNodes(
                            ExtensionInfo.GUID,
                            Navigation.ToolTipSource.None,
                            -1,
                            -1,
                            MenuBase.GetNavNodeOptions(true))));

                MenuBase menu = new MenuBase();
                menu.ApplySetting(menuSetting);
                menu.RootNode = rootNode;
                menu.Initialize();

                IDictionary <string, object> dynObjects = new ExpandoObject() as IDictionary <string, object>;
                dynObjects.Add("Menu", menu);
                string Template = RazorEngineManager.RenderTemplate(ExtensionInfo.GUID, BlockPath, Attributes["data-block-template"], dynObjects);
                Template = new DNNLocalizationEngine(null, ResouceFilePath, false).Parse(Template);
                return(Template);
            }
            catch (Exception ex)
            {
                DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
                return(ex.Message);
            }
        }
        protected override void OnPreRender(EventArgs e)
        {
            using (new DNNContext(this))
            {
                try
                {
                    base.OnPreRender(e);

                    var menuStyle = GetStringSetting("MenuStyle");
                    if (String.IsNullOrEmpty(menuStyle))
                    {
                        menu = null;
                        return;
                    }

                    var menuSettings = new Settings
                    {
                        MenuStyle         = GetStringSetting("MenuStyle"),
                        NodeXmlPath       = GetStringSetting("NodeXmlPath"),
                        NodeSelector      = GetStringSetting("NodeSelector"),
                        IncludeContext    = GetBoolSetting("IncludeContext"),
                        IncludeHidden     = GetBoolSetting("IncludeHidden"),
                        IncludeNodes      = GetStringSetting("IncludeNodes"),
                        ExcludeNodes      = GetStringSetting("ExcludeNodes"),
                        NodeManipulator   = GetStringSetting("NodeManipulator"),
                        TemplateArguments =
                            DDRMenu.Settings.TemplateArgumentsFromSettingString(GetStringSetting("TemplateArguments")),
                        ClientOptions =
                            DDRMenu.Settings.ClientOptionsFromSettingString(GetStringSetting("ClientOptions"))
                    };

                    MenuNode rootNode = null;
                    if (String.IsNullOrEmpty(menuSettings.NodeXmlPath))
                    {
                        rootNode =
                            new MenuNode(
                                Localiser.LocaliseDNNNodeCollection(
                                    Navigation.GetNavigationNodes(
                                        ClientID,
                                        Navigation.ToolTipSource.None,
                                        -1,
                                        -1,
                                        DNNAbstract.GetNavNodeOptions(true))));
                    }

                    menu          = MenuBase.Instantiate(menuStyle);
                    menu.RootNode = rootNode;
                    menu.ApplySettings(menuSettings);

                    menu.PreRender();
                }
                catch (Exception exc)
                {
                    Exceptions.ProcessModuleLoadException(this, exc);
                }
            }
        }
示例#3
0
        protected override void OnPreRender(EventArgs e)
        {
            using (new DNNContext(this))
            {
                try
                {
                    base.OnPreRender(e);

                    menu = MenuBase.Instantiate(MenuStyle);
                    menu.ApplySettings(
                        new Settings
                    {
                        MenuStyle         = MenuStyle,
                        NodeXmlPath       = NodeXmlPath,
                        NodeSelector      = NodeSelector,
                        IncludeContext    = IncludeContext,
                        IncludeHidden     = IncludeHidden,
                        IncludeNodes      = IncludeNodes,
                        ExcludeNodes      = ExcludeNodes,
                        NodeManipulator   = NodeManipulator,
                        ClientOptions     = ClientOptions,
                        TemplateArguments = TemplateArguments
                    });

                    if (String.IsNullOrEmpty(NodeXmlPath))
                    {
                        menu.RootNode =
                            new MenuNode(
                                Localiser.LocaliseDNNNodeCollection(
                                    Navigation.GetNavigationNodes(
                                        ClientID,
                                        Navigation.ToolTipSource.None,
                                        -1,
                                        -1,
                                        DNNAbstract.GetNavNodeOptions(true))));
                    }

                    menu.PreRender();
                }
                catch (Exception exc)
                {
                    Exceptions.ProcessModuleLoadException(this, exc);
                }
            }
        }
        public void Bind(DNNNodeCollection objNodes, bool localise)
        {
            var clientOptions = new List <ClientOption>();

            var ignoreProperties = new List <string>
            {
                "CustomAttributes",
                "NavigationControl",
                "SupportsPopulateOnDemand",
                "NodeXmlPath",
                "NodeSelector",
                "IncludeContext",
                "IncludeHidden",
                "IncludeNodes",
                "ExcludeNodes",
                "NodeManipulator"
            };

            foreach (var prop in
                     typeof(NavigationProvider).GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance))
            {
                if (!string.IsNullOrEmpty(prop.Name) && !ignoreProperties.Contains(prop.Name))
                {
                    var propValue = prop.GetValue(this, null);
                    if (propValue != null)
                    {
                        if (propValue is bool)
                        {
                            clientOptions.Add(new ClientBoolean(prop.Name, propValue.ToString()));
                        }
                        else if (propValue is int || propValue is decimal || propValue is double)
                        {
                            clientOptions.Add(new ClientNumber(prop.Name, propValue.ToString()));
                        }
                        else
                        {
                            clientOptions.Add(new ClientString(prop.Name, propValue.ToString()));
                        }
                    }
                }
            }

            if (CustomAttributes != null)
            {
                foreach (var attr in CustomAttributes)
                {
                    if (!string.IsNullOrEmpty(attr.Name))
                    {
                        clientOptions.Add(new ClientString(attr.Name, attr.Value));
                    }
                }
            }

            if (localise)
            {
                objNodes = Localiser.LocaliseDNNNodeCollection(objNodes);
            }

            menuControl.RootNode         = new MenuNode(objNodes);
            menuControl.SkipLocalisation = !localise;
            menuControl.MenuSettings     = new Settings
            {
                MenuStyle         = GetCustomAttribute("MenuStyle") ?? MenuStyle ?? "DNNMenu",
                NodeXmlPath       = GetCustomAttribute("NodeXmlPath"),
                NodeSelector      = GetCustomAttribute("NodeSelector"),
                IncludeContext    = Convert.ToBoolean(GetCustomAttribute("IncludeContext") ?? "false"),
                IncludeHidden     = Convert.ToBoolean(GetCustomAttribute("IncludeHidden") ?? "false"),
                IncludeNodes      = GetCustomAttribute("IncludeNodes"),
                ExcludeNodes      = GetCustomAttribute("ExcludeNodes"),
                NodeManipulator   = GetCustomAttribute("NodeManipulator"),
                ClientOptions     = clientOptions,
                TemplateArguments = TemplateArguments,
            };
        }