/// <summary>
 /// Test if the maximal node level has not been reached
 /// </summary>
 /// <param name="maxDepth">The normal max depth.</param>
 /// <param name="node">The starting node</param>
 /// <param name="drillDownToCurrent">Should the model exceed the maxDepth to reach the current node</param>
 /// <returns></returns>
 private bool ReachedMaximalNodelevel(int maxDepth, ISiteMapNode node, bool drillDownToCurrent)
 {
     if (maxDepth > 0)
     {
         return(true);
     }
     if (!drillDownToCurrent)
     {
         return(false);
     }
     if (node.IsInCurrentPath())
     {
         return(true);
     }
     if (node.ParentNode != null && node.ParentNode.Equals(node.SiteMap.CurrentNode))
     {
         return(true);
     }
     foreach (ISiteMapNode sibling in node.ParentNode.ChildNodes)
     {
         if (sibling.IsInCurrentPath())
         {
             return(true);
         }
     }
     return(false);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="SiteMapNodeModel"/> class.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="sourceMetadata">The source metadata provided by the HtmlHelper.</param>
        /// <param name="maxDepth">The max depth.</param>
        /// <param name="drillDownToCurrent">Should the model exceed the maxDepth to reach the current node</param>
        /// <param name="startingNodeInChildLevel">Renders startingNode in child level if set to <c>true</c>.</param>
        public SiteMapNodeModel(ISiteMapNode node, IDictionary<string, object> sourceMetadata, int maxDepth, bool drillDownToCurrent, bool startingNodeInChildLevel, bool visibilityAffectsDescendants)
        {
            if (node == null)
                throw new ArgumentNullException("node");
            if (sourceMetadata == null)
                throw new ArgumentNullException("sourceMetadata");
            if (maxDepth < 0)
                throw new ArgumentOutOfRangeException("maxDepth");

            this.node = node;
            this.maxDepth = maxDepth;
            this.startingNodeInChildLevel = startingNodeInChildLevel;
            this.drillDownToCurrent = drillDownToCurrent;
            this.SourceMetadata = sourceMetadata;

            Key = node.Key;
            Area = node.Area;
            Controller = node.Controller;
            Action = node.Action;
            Title = node.Title;
            Description = node.Description;
            TargetFrame = node.TargetFrame;
            ImageUrl = node.ImageUrl;
            Url = node.Url;
            CanonicalUrl = node.CanonicalUrl;
            MetaRobotsContent = node.GetMetaRobotsContentString();
            IsCurrentNode = (node == node.SiteMap.CurrentNode);
            IsInCurrentPath = node.IsInCurrentPath();
            IsRootNode = (node == node.SiteMap.RootNode);
            IsClickable = node.Clickable;
            VisibilityAffectsDescendants = visibilityAffectsDescendants;
            RouteValues = node.RouteValues;
            Attributes = node.Attributes;
        }
        /// <summary>
        /// Determines whether the node is visible.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="sourceMetadata">The source metadata.</param>
        /// <returns>
        /// 	<c>true</c> if the specified node is visible; otherwise, <c>false</c>.
        /// </returns>
        public override bool IsVisible(ISiteMapNode node, IDictionary<string, object> sourceMetadata)
        {
            // Is a visibility attribute specified?
            string visibility = string.Empty;
            if (node.Attributes.ContainsKey("visibility"))
            {
                visibility = node.Attributes["visibility"].GetType().Equals(typeof(string)) ? node.Attributes["visibility"].ToString() : string.Empty;
            }
            if (string.IsNullOrEmpty(visibility))
            {
                return true;
            }
            visibility = visibility.Trim();

            string name = string.Empty;
            string htmlHelper = string.Empty;
            if (sourceMetadata.ContainsKey("name"))
            {
                name = Convert.ToString(sourceMetadata["name"]);
            }
            if (sourceMetadata.ContainsKey("HtmlHelper"))
            {
                htmlHelper = Convert.ToString(sourceMetadata["HtmlHelper"]);
            }

            // Check for the source HtmlHelper or given name. If neither are configured,
            // then always visible.
            if (string.IsNullOrEmpty(name) && string.IsNullOrEmpty(htmlHelper))
            {
                return true;
            }

            // Chop off the namespace
            htmlHelper = htmlHelper.Substring(htmlHelper.LastIndexOf(".") + 1);

            // Get the keywords
            var visibilityKeywords = visibility.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);

            // All set. Now parse the visibility variable.
            foreach (string visibilityKeyword in visibilityKeywords)
            {
                if (visibilityKeyword == htmlHelper || visibilityKeyword == name || visibilityKeyword == "*")
                {
                    return true;
                }
                else if (visibilityKeyword == "IfSelected" && node.IsInCurrentPath())
                {
                    return true;
                }
                else if (visibilityKeyword == "!" + htmlHelper || visibilityKeyword == "!" + name || visibilityKeyword == "!*")
                {
                    return false;
                }
            }

            // Still nothing? Then it's OK!
            return true;
        }
Esempio n. 4
0
        //default false
        public static bool IsCurrentNode(ISiteMapNode siteMapNode)
        {
            if (siteMapNode.IsInCurrentPath())
            {
                if (siteMapNode.Url == HttpContext.Current.Request.Url.ToString())
                {
                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SiteMapNodeModel"/> class.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="sourceMetadata">The source metadata provided by the HtmlHelper.</param>
        /// <param name="maxDepth">The max depth.</param>
        /// <param name="drillDownToCurrent">Should the model exceed the maxDepth to reach the current node</param>
        /// <param name="startingNodeInChildLevel">Renders startingNode in child level if set to <c>true</c>.</param>
        public SiteMapNodeModel(ISiteMapNode node, IDictionary <string, object> sourceMetadata, int maxDepth, bool drillDownToCurrent, bool startingNodeInChildLevel, bool visibilityAffectsDescendants)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            if (sourceMetadata == null)
            {
                throw new ArgumentNullException("sourceMetadata");
            }
            if (maxDepth < 0)
            {
                throw new ArgumentOutOfRangeException("maxDepth");
            }

            this.node     = node;
            this.maxDepth = maxDepth;
            this.startingNodeInChildLevel = startingNodeInChildLevel;
            this.drillDownToCurrent       = drillDownToCurrent;
            this.SourceMetadata           = sourceMetadata;

            Key        = node.Key;
            Area       = node.Area;
            Controller = node.Controller;
            Action     = node.Action;
            Site       = node.Site;
            if (string.IsNullOrEmpty(node.Site))
            {
                Site = node.RootNode.Site;
            }
            Title                        = node.Title;
            Description                  = node.Description;
            TargetFrame                  = node.TargetFrame;
            ImageUrl                     = node.ImageUrl;
            Url                          = node.Url;
            ResolvedUrl                  = node.ResolvedUrl;
            CanonicalUrl                 = node.CanonicalUrl;
            CanonicalUrlSeo              = node.CanonicalUrlSeo;
            MetaRobotsContent            = node.GetMetaRobotsContentString();
            Include                      = node.Include;
            Exclude                      = node.Exclude;
            IsCurrentNode                = (node.Equals(node.SiteMap.CurrentNode));
            IsInCurrentPath              = node.IsInCurrentPath();
            IsRootNode                   = (node.Equals(node.SiteMap.RootNode));
            IsClickable                  = node.Clickable;
            VisibilityAffectsDescendants = visibilityAffectsDescendants;
            RouteValues                  = node.RouteValues;
            Attributes                   = node.Attributes;
            Order                        = node.Order;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SiteMapNodeModel"/> class.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="sourceMetadata">The source metadata provided by the HtmlHelper.</param>
        /// <param name="maxDepth">The max depth.</param>
        /// <param name="drillDownToCurrent">Should the model exceed the maxDepth to reach the current node</param>
        /// <param name="startingNodeInChildLevel">Renders startingNode in child level if set to <c>true</c>.</param>
        public SiteMapNodeModel(ISiteMapNode node, IDictionary <string, object> sourceMetadata, int maxDepth, bool drillDownToCurrent, bool startingNodeInChildLevel)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            if (sourceMetadata == null)
            {
                throw new ArgumentNullException("sourceMetadata");
            }
            if (maxDepth < 0)
            {
                throw new ArgumentOutOfRangeException("maxDepth");
            }

            this.node     = node;
            this.maxDepth = maxDepth;
            this.startingNodeInChildLevel = startingNodeInChildLevel;
            this.drillDownToCurrent       = drillDownToCurrent;
            this.SourceMetadata           = sourceMetadata;

            Area              = node.Area;
            Controller        = node.Controller;
            Action            = node.Action;
            Title             = node.Title;
            Description       = node.Description;
            TargetFrame       = node.TargetFrame;
            ImageUrl          = node.ImageUrl;
            Url               = node.Url;
            CanonicalUrl      = node.CanonicalUrl;
            MetaRobotsContent = node.GetMetaRobotsContentString();
            IsCurrentNode     = (node == node.SiteMap.CurrentNode);
            IsInCurrentPath   = node.IsInCurrentPath();
            IsRootNode        = (node == node.SiteMap.RootNode);
            IsClickable       = node.Clickable;
            RouteValues       = node.RouteValues;
            Attributes        = node.Attributes;
        }
Esempio n. 7
0
        /// <summary>
        /// Determines whether the node is visible.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="sourceMetadata">The source metadata.</param>
        /// <returns>
        ///     <c>true</c> if the specified node is visible; otherwise, <c>false</c>.
        /// </returns>
        public override bool IsVisible(ISiteMapNode node, IDictionary <string, object> sourceMetadata)
        {
            // Is a visibility attribute specified?
            string visibility = string.Empty;

            if (node.Attributes.ContainsKey("visibility"))
            {
                visibility = node.Attributes["visibility"].GetType().Equals(typeof(string)) ? node.Attributes["visibility"].ToString() : string.Empty;
            }
            if (string.IsNullOrEmpty(visibility))
            {
                return(true);
            }
            visibility = visibility.Trim();

            string name       = string.Empty;
            string htmlHelper = string.Empty;

            if (sourceMetadata.ContainsKey("name"))
            {
                name = Convert.ToString(sourceMetadata["name"]);
            }
            if (sourceMetadata.ContainsKey("HtmlHelper"))
            {
                htmlHelper = Convert.ToString(sourceMetadata["HtmlHelper"]);
            }

            // Check for the source HtmlHelper or given name. If neither are configured,
            // then always visible.
            if (string.IsNullOrEmpty(name) && string.IsNullOrEmpty(htmlHelper))
            {
                return(true);
            }

            // Chop off the namespace
            htmlHelper = htmlHelper.Substring(htmlHelper.LastIndexOf(".") + 1);

            // Get the keywords and trim any white-spaces
            var visibilityKeywords = visibility.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries)
                                     .Select(k => k.Trim()).ToList();

            // All set. Now parse the visibility variable.
            foreach (string visibilityKeyword in visibilityKeywords)
            {
                if (visibilityKeyword == htmlHelper || visibilityKeyword == name || visibilityKeyword == "*")
                {
                    return(true);
                }
                else if ((visibilityKeyword == htmlHelper + "IfSelected" ||
                          visibilityKeyword == name + "IfSelected" ||
                          visibilityKeyword == "IfSelected") &&
                         node.IsInCurrentPath())
                {
                    return(true);
                }
                else if (visibilityKeyword == "!" + htmlHelper || visibilityKeyword == "!" + name || visibilityKeyword == "!*")
                {
                    return(false);
                }
            }

            // Still nothing? Then it's OK!
            return(true);
        }
 /// <summary>
 /// Test if the maximal nodelevel has not been reached
 /// </summary>
 /// <param name="maxDepth">The normal max depth.</param>
 /// <param name="node">The starting node</param>
 /// <param name="drillDownToCurrent">Should the model exceed the maxDepth to reach the current node</param>
 /// <returns></returns>
 private bool ReachedMaximalNodelevel(int maxDepth, ISiteMapNode node, bool drillDownToCurrent)
 {
     if (maxDepth > 0)
         return true;
     if (!drillDownToCurrent)
         return false;
     if (node.IsInCurrentPath())
         return true;
     if (node.ParentNode == node.SiteMap.CurrentNode)
         return true;
     foreach (ISiteMapNode sibling in node.ParentNode.ChildNodes)
     {
         if (sibling.IsInCurrentPath())
             return true;
     }
     return false;
 }