/// <summary>
        /// Determines whether node is accessible to user.
        /// </summary>
        /// <param name="siteMap">The site map.</param>
        /// <param name="node">The node.</param>
        /// <returns>
        /// 	<c>true</c> if accessible to user; otherwise, <c>false</c>.
        /// </returns>
        public bool IsAccessibleToUser(ISiteMap siteMap, ISiteMapNode node)
        {
            // If we have roles assigned, check them against the roles defined in the sitemap
            if (node.Roles != null && node.Roles.Count > 0)
            {
                var context = mvcContextFactory.CreateHttpContext();

                    // if there is an authenticated user and the role allows anyone authenticated ("*"), show it
                if ((context.User.Identity.IsAuthenticated) && node.Roles.Contains("*"))
                {
                    return true;
                }

                    // if there is no user, but the role allows unauthenticated users ("?"), show it
                if ((!context.User.Identity.IsAuthenticated) && node.Roles.Contains("?"))
                    {
                        return true;
                    }

                    // if the user is in one of the listed roles, show it
                if (node.Roles.OfType<string>().Any(role => context.User.IsInRole(role)))
                    {
                        return true;
                    }

                    // if we got this far, deny showing
                    return false;
            }

            // Everything seems OK...
            return true;
        }
        public XmlSiteMapResult(
            int page,
            ISiteMapNode rootNode,
            IEnumerable<string> siteMapCacheKeys,
            string baseUrl,
            string siteMapUrlTemplate,
            ISiteMapLoader siteMapLoader,
            IUrlPath urlPath,
            ICultureContextFactory cultureContextFactory)
        {
            if (siteMapLoader == null)
                throw new ArgumentNullException("siteMapLoader");
            if (urlPath == null)
                throw new ArgumentNullException("urlPath");
            if (cultureContextFactory == null)
                throw new ArgumentNullException("cultureContextFactory");

            this.Ns = "http://www.sitemaps.org/schemas/sitemap/0.9";
            this.Page = page;
            this.RootNode = rootNode;
            this.SiteMapCacheKeys = siteMapCacheKeys;
            this.BaseUrl = baseUrl;
            this.SiteMapUrlTemplate = siteMapUrlTemplate;
            this.siteMapLoader = siteMapLoader;
            this.urlPath = urlPath;
            this.cultureContextFactory = cultureContextFactory;
        }
        /// <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;
        }
 public override IEnumerable<DynamicNode> GetDynamicNodeCollection(ISiteMapNode nodes)
 {
     var returnValue = new List<DynamicNode>();
     
     // 向BLL層取得選單
     foreach (var item in PermissionService.GetMenu())
     {
         DynamicNode node = new DynamicNode();
         // 選單名稱
         node.Title = item.Name; 
         // 有無父類別,沒有的話則傳空字串
         node.ParentKey = item.ParentID == 0 ? "" : item.ParentID.ToString();
         // 唯一值
         node.Key = item.MenuID.ToString();
         // MVC的View
         node.Action = item.Action;
         // MVC的Controller
         node.Controller = item.Controller;
         // 選單所分配的腳色,逗號分隔
         node.Roles = item.Roles.Split(',').Where(c => !string.IsNullOrEmpty(c)).ToList();
         // 
         node.RouteValues.Add("id", item.MenuID);
         returnValue.Add(node);
     }
     // Return
     return returnValue;
 }
        public SiteMapNodeUrlKey(
            ISiteMapNode node,
            IUrlPath urlPath
            )
            : base(urlPath)
        {
            if (node == null)
                throw new ArgumentNullException("node");

            this.node = node;

            // Host name in absolute URL overrides this one.
            this.hostName = node.HostName;

            // Fixes #322 - If using a custom URL resolver, we need to account for the case that
            // the URL will be provided by the resolver instead of specified explicitly.
            if (!string.IsNullOrEmpty(node.UnresolvedUrl))
            {
                this.SetUrlValues(node.UnresolvedUrl);
            }
            else if (!node.UsesDefaultUrlResolver())
            {
                // For a custom URL resolver, if the unresolved URL property
                // is not set use the one returned from the URL resolver.
                // This ensures URLs that are unidentifiable by MVC can still
                // be matched by URL.
                this.SetUrlValues(node.Url);
            }
        }
 public void Execute(ISiteMapNode node)
 {
     foreach (var visitor in this.siteMapNodeVisitors)
     {
         visitor.Execute(node);
     }
 }
        protected virtual void AddDescendantNodes(
            ISiteMap siteMap,
            ISiteMapNode currentNode,
            IList<ISiteMapNodeToParentRelation> sourceNodes,
            ILookup<string, ISiteMapNodeToParentRelation> sourceNodesByParent,
            HashSet<string> nodesAlreadyAdded)
        {
            if (sourceNodes.Count == 0)
            {
                return;
            }

            var children = sourceNodesByParent[currentNode.Key].OrderBy(x => x.Node.Order).ToArray();
            if (children.Count() == 0)
            {
                return;
            }

            foreach (var child in children)
            {
                if (sourceNodes.Count == 0)
                {
                    return;
                }

                this.AddAndTrackNode(siteMap, child, currentNode, sourceNodes, nodesAlreadyAdded);

                if (sourceNodes.Count == 0)
                {
                    return;
                }

                this.AddDescendantNodes(siteMap, child.Node, sourceNodes, sourceNodesByParent, nodesAlreadyAdded);
            }
        }
        public override IEnumerable<DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
        {
            var categories = _unitOfWork.CategoryRepository.Get().ToList();// categoryBuilder.Build();

            foreach (var category in categories.Where(i=>i.ParentCategory==null))
            {
                var dynamicNode = new DynamicNode();
                dynamicNode.Title = category.Name;
                dynamicNode.Key = category.Id.ToString();
                dynamicNode.RouteValues.Add("id",category.Id);

                var category1 = category;
                foreach (var childCategory in categories.Where(c=>c.ParentCategory==category1))
                {
                    var childDynamicNode = new DynamicNode();
                    childDynamicNode.Title = childCategory.Name;
                    childDynamicNode.ParentKey = category.Id.ToString();
                    childDynamicNode.Key = childCategory.Id.ToString();
                    childDynamicNode.RouteValues.Add("id",childCategory.Id);
/*                    foreach (var productItem in productItems.Where(i=>i.CategoryId==childCategory.Id))
                    {
                        var productDynamicNode = new DynamicNode();
                        productDynamicNode.Title = productItem.Name;
                        productDynamicNode.ParentKey = childCategory.Id;
                        productDynamicNode.Key = productItem.Id;
                        productDynamicNode.RouteValues.Add("id", productItem.Id);

                        yield return productDynamicNode;
                    }*/
                    yield return childDynamicNode;
                }

                yield return dynamicNode;
            }
        }
        protected virtual HttpContextBase CreateHttpContext(ISiteMapNode node, TextWriter writer)
        {
            var currentHttpContext = this.mvcContextFactory.CreateHttpContext();

            // Create a URI with the home page and no query string values.
            var uri = new Uri(currentHttpContext.Request.Url, "/");
            return this.mvcContextFactory.CreateHttpContext(node, uri, writer);
        }
 /// <summary>
 /// Resolves the URL.
 /// </summary>
 /// <param name="node">The MVC site map node.</param>
 /// <param name="area">The area.</param>
 /// <param name="controller">The controller.</param>
 /// <param name="action">The action.</param>
 /// <param name="routeValues">The route values.</param>
 /// <returns>The resolved URL.</returns>
 public override string ResolveUrl(ISiteMapNode node, string area, string controller, string action, IDictionary<string, object> routeValues)
 {
     if (!string.IsNullOrEmpty(node.UnresolvedUrl))
     {
         return this.ResolveVirtualPath(node);
     }
     return this.ResolveRouteUrl(node, area, controller, action, routeValues);
 }
Esempio n. 11
0
        public override bool IsVisible(ISiteMapNode node, IDictionary<string, object> sourceMetadata)
        {

            return visability(node, sourceMetadata) & rights(node, sourceMetadata) & module(node, sourceMetadata);



        }
 public override bool IsVisible(ISiteMapNode node, IDictionary<string, object> sourceMetadata)
 {
     if (!node.HasChildNodes && !node.Clickable)
     {
         return false;
     }
     return true;
 }
        /// <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;
        }
        /// <summary>
        /// Adds the dynamic nodes for node.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="parentNode">The parent node.</param>
        public IEnumerable<ISiteMapNode> BuildDynamicNodesFor(ISiteMap siteMap, ISiteMapNode node, ISiteMapNode parentNode)
        {
            // List of dynamic nodes that have been created
            var createdDynamicNodes = new List<ISiteMapNode>();

            if (!node.HasDynamicNodeProvider)
            {
                return createdDynamicNodes;
            }

            // Build dynamic nodes
            foreach (var dynamicNode in node.GetDynamicNodeCollection())
            {
                string key = dynamicNode.Key;
                if (string.IsNullOrEmpty(key))
                {
                    key = nodeKeyGenerator.GenerateKey(
                        parentNode == null ? "" : parentNode.Key, 
                        Guid.NewGuid().ToString(), 
                        node.Url, 
                        node.Title, 
                        node.Area, 
                        node.Controller, 
                        node.Action,
                        node.HttpMethod,
                        node.Clickable);
                }

                // Create a new node
                var newNode = siteMapNodeFactory.CreateDynamic(siteMap, key, node.ResourceKey);

                // Copy the values from the original node to the new one
                node.CopyTo(newNode);

                // Copy any values that were set in the dynamic node and overwrite the new node.
                dynamicNode.SafeCopyTo(newNode);

                // If the dynamic node has a parent key set, use that as the parent. Otherwise use the parentNode.
                if (!string.IsNullOrEmpty(dynamicNode.ParentKey))
                {
                    var parent = siteMap.FindSiteMapNodeFromKey(dynamicNode.ParentKey);
                    if (parent != null)
                    {
                        siteMap.AddNode(newNode, parent);
                        createdDynamicNodes.Add(newNode);
                    }
                }
                else
                {
                    siteMap.AddNode(newNode, parentNode);
                    createdDynamicNodes.Add(newNode);
                }
            }

            // Done!
            return createdDynamicNodes;
        }
 public ISiteMapNode BuildSiteMap(ISiteMap siteMap, ISiteMapNode rootNode)
 {
     ISiteMapNode result = rootNode;
     foreach (var builder in this.siteMapBuilders)
     {
         result = builder.BuildSiteMap(siteMap, result);
     }
     return result;
 }
        /// <summary>
        /// Gets the dynamic nodes for node.
        /// </summary>
        /// <param name="node">The SiteMap node.</param>
        /// <param name="defaultParentKey">The key of the parent node.</param>
        public virtual IEnumerable<ISiteMapNodeToParentRelation> BuildDynamicNodes(ISiteMapNode node, string defaultParentKey)
        {
            var result = new List<ISiteMapNodeToParentRelation>();

            if (!node.HasDynamicNodeProvider)
            {
                return result;
            }

            // Get the dynamic nodes using the request's culture context.
            // NOTE: In version 5, we need to use the invariant context and pass a reference to it
            // into the dynamic node provider. This would be a breaking change, so for now we are 
            // swapping the context back to the state of the current request. This way, the end user
            // still can opt to change to invariant culture, but in the reverse situation there would 
            // be no way to identify the culture of the current request without a reference to the 
            // cultureContext object.
            IEnumerable<DynamicNode> dynamicNodes;
            using (var originalCultureContext = this.cultureContextFactory.Create(this.cultureContext.OriginalCulture, this.cultureContext.OriginalUICulture))
            {
                dynamicNodes = node.GetDynamicNodeCollection();
            }

            // Build dynamic nodes
            foreach (var dynamicNode in dynamicNodes)
            {
                // If the dynamic node has a parent key set, use that as the parent. Otherwise use the parentNode.
                var parentKey = !string.IsNullOrEmpty(dynamicNode.ParentKey) ? dynamicNode.ParentKey : defaultParentKey;
                var key = dynamicNode.Key;

                if (string.IsNullOrEmpty(key))
                {
                    key = this.siteMapNodeCreator.GenerateSiteMapNodeKey(
                        parentKey,
                        Guid.NewGuid().ToString(),
                        node.Url,
                        node.Title,
                        node.Area,
                        node.Controller,
                        node.Action,
                        node.HttpMethod,
                        node.Clickable);
                }

                // Create a new node
                var nodeParentMap = this.siteMapNodeCreator.CreateDynamicSiteMapNode(key, parentKey, node.DynamicNodeProvider, node.ResourceKey);
                var newNode = nodeParentMap.Node;

                // Copy the values from the original node to the new one
                node.CopyTo(newNode);

                // Copy any values that were set in the dynamic node and overwrite the new node.
                dynamicNode.SafeCopyTo(newNode);

                result.Add(nodeParentMap);
            }
            return result;
        }
Esempio n. 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SiteMapHttpContext"/> class.
 /// </summary>
 /// <param name="httpContext">The object that this wrapper class provides access to.</param>
 /// <param name="node">The site map node to fake node access context for or <c>null</c>.</param>
 /// <exception cref="T:System.ArgumentNullException">
 ///     <paramref name="httpContext"/> is null.
 /// </exception>
 public SiteMapHttpContext(HttpContext httpContext, ISiteMapNode node, Uri uri)
     : base(httpContext)
 {
     this.httpContext = httpContext;
     this.node = node;
     if(node != null) {
         nodeUri = uri ?? new Uri(HttpContext.Current.Request.Url, node.Url);
     }
 }
 protected virtual string ResolveVirtualPath(ISiteMapNode node)
 {
     var url = node.UnresolvedUrl;
     if (!urlPath.IsAbsoluteUrl(url))
     {
         return urlPath.MakeVirtualPathAppAbsolute(urlPath.Combine(urlPath.AppDomainAppVirtualPath, url));
     }
     return url;
 }
Esempio n. 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SiteMapHttpRequest"/> class.
 /// </summary>
 /// <param name="httpRequest">The object that this wrapper class provides access to.</param>
 /// <param name="node">The site map node to fake node access context for or <c>null</c>.</param>
 /// <exception cref="T:System.ArgumentNullException">
 ///     <paramref name="httpRequest"/> is null.
 /// </exception>
 public SiteMapHttpRequest(HttpRequest httpRequest, ISiteMapNode node, RequestContext requestContext, Uri nodeUri)
     : base(httpRequest, requestContext)
 {
     this.node = node;
     this.currentRequest = new HttpRequest(
         filename: string.Empty,
         url: nodeUri.ToString(),
         queryString: string.IsNullOrEmpty(nodeUri.Query) ? string.Empty : nodeUri.Query.Substring(1));
 }
        /// <summary>
        /// Adds the MvcCodeRouting.RouteContext DataToken necessary for interoperability 
        /// with the MvcCodeRouting library https://github.com/maxtoroq/MvcCodeRouting
        /// </summary>
        /// <param name="routeData">The route data.</param>
        /// <param name="node">The current site map node.</param>
        internal static void SetMvcCodeRoutingContext(this RouteData routeData, ISiteMapNode node)
        {
            if (routeData == null)
                return;

            var controllerType = node.SiteMap.ResolveControllerType(node.Area, node.Controller);
            var mvcCodeRoutingRouteContext = GetMvcCodeRoutingRouteContext(controllerType, node.Controller);
            routeData.DataTokens["MvcCodeRouting.RouteContext"] = mvcCodeRoutingRouteContext;
        }
        /// <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)
        {
            // Convert to MvcSiteMapNode
            var mvcNode = node as MvcSiteMapProvider.SiteMapNode;

	        if (mvcNode != null)
	        {
		        var menu = String.Empty;
                if (sourceMetadata != null && sourceMetadata.ContainsKey("name"))
                    menu = sourceMetadata["name"].ToString();

		        // Is a visibility attribute specified?
		        var visibility = GetValue(mvcNode, "visibility");

		        if (mvcNode.Attributes.ContainsKey("permissions"))
		        {
                    if (!CustomerSession.IsRegistered)
				        return false;

			        var allPermissions =
				        GetValue(mvcNode, "permissions").Split(',').Select(x => new Permission {PermissionId = x});
			        if (
				        allPermissions.Any(
					        permission => !SecurityService.CheckMemberPermission(StoreHelper.CustomerSession.CustomerId, permission)))
			        {
				        return false;
			        }
		        }

		        if (!string.IsNullOrEmpty(visibility))
		        {
			        visibility = visibility.Trim();

			        // All set. Now parse the visibility variable.
			        if (visibility.Split(new[] {',', ';'})
						.TakeWhile(visibilityKeyword => visibilityKeyword != menu && visibilityKeyword != "*")
						.Any(visibilityKeyword => visibilityKeyword == "!" + menu || visibilityKeyword == "!*"))
			        {
				        return false;
			        }
		        }

		        var stores = GetValue(mvcNode, "stores");
		        if (!string.IsNullOrEmpty(stores))
		        {
			        if(!stores.Trim().Split(new[] {',', ';'}, StringSplitOptions.RemoveEmptyEntries)
						.Any(store => store.Equals(CustomerSession.StoreId, StringComparison.OrdinalIgnoreCase)))
			        {
				        return false;
			        }
		        }
	        }

	        // Still nothing? Then it's OK!
            return true;
        }
        public virtual ISiteMapNode BuildSiteMap(ISiteMap siteMap, ISiteMapNode rootNode)
        {
            if (rootNode == null)
            {
                throw new ArgumentNullException("rootNode", Resources.Messages.VisitingSiteMapBuilderRequiresRootNode);
            }

            VisitNodes(rootNode);
            return rootNode;
        }
Esempio n. 23
0
 public override IEnumerable<DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
 {
     var result = new List<DynamicNode>();
     result.Add(new DynamicNode()
     {
         ParentKey = "Org",
         Title = node.Title
     });
     return result;
 }
 public override IEnumerable<DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
 {
     return new List<DynamicNode>
     {
         new DynamicNode
         {
             Action = "DisplayItem",
             PreservedRouteParameters = new[] {Constants.Language, Constants.Store, Constants.Category, Constants.Item},
         }
     };
 }
        /// <summary>
        /// Gets the dynamic node collection.
        /// </summary>
        /// <param name="node">The current node.</param>
        /// <returns>
        /// A dynamic node collection represented as a <see cref="IEnumerable&lt;MvcSiteMapProvider.Extensibility.DynamicNode&gt;"/> instance 
        /// </returns>
        public override IEnumerable<DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
        {
            // Create a node for each genre
            foreach (var genre in storeDB.Genres)
            {
                DynamicNode dynamicNode = new DynamicNode("Genre_" + genre.Name, genre.Name);
                dynamicNode.RouteValues.Add("genre", genre.Name);

                yield return dynamicNode; 
            }
        }
        public override bool IsVisible(ISiteMapNode node, IDictionary<string, object> sourceMetadata)
        {
            // Optimization - return quickly if clickable.
            if (node.Clickable)
            {
                return true;
            }

            var childNodes = node.ChildNodes;
            return childNodes == null || childNodes.Any(c => c.IsVisible(sourceMetadata));
        }
        public virtual ISiteMapNode BuildSiteMap(ISiteMap siteMap, ISiteMapNode rootNode)
        {
            var xml = xmlSource.GetXml();
            if (xml != null)
            {
                rootNode = LoadSiteMapFromXml(siteMap, xml);
            }

            // Done!
            return rootNode;
        }
        public override IEnumerable<DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
        {
            var Departments = DepartmentGetter.GetDepartments();

            foreach (Department dep in Departments)
            {
                DynamicNode dynamicNode = new DynamicNode { Title = dep.Name };
                dynamicNode.RouteValues.Add("acronym", dep.Acronym);
                yield return dynamicNode;
            }
        }
 protected virtual void AddAndTrackNode(
     ISiteMap siteMap,
     ISiteMapNodeToParentRelation nodeParentMap,
     ISiteMapNode parentNode,
     IList<ISiteMapNodeToParentRelation> sourceNodes,
     HashSet<string> nodesAlreadyAdded)
 {
     siteMap.AddNode(nodeParentMap.Node, parentNode);
     nodesAlreadyAdded.Add(nodeParentMap.Node.Key);
     sourceNodes.Remove(nodeParentMap);
 }
 /// <summary>
 /// Determines whether node is accessible to user.
 /// </summary>
 /// <param name="siteMap">The site map.</param>
 /// <param name="node">The node.</param>
 /// <returns>
 /// 	<c>true</c> if accessible to user; otherwise, <c>false</c>.
 /// </returns>
 public virtual bool IsAccessibleToUser(ISiteMap siteMap, ISiteMapNode node)
 {
     foreach (var module in aclModules)
     {
         var authorized = module.IsAccessibleToUser(siteMap, node);
         if (authorized == false)
             return false;
     }
     // Convention throughout the provider: if the IAclModule can not authenticate a user, true is returned.
     return true;
 }
Esempio n. 31
0
        public ISiteMapNodeCollection GetChildNodes(ISiteMapNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            ISiteMapNodeCollection collection = null;

            if (this.childNodeCollectionTable.ContainsKey(node))
            {
                collection = this.childNodeCollectionTable[node];
            }
            if (collection == null)
            {
                ISiteMapNode keyNode = null;
                if (this.keyTable.ContainsKey(node.Key))
                {
                    keyNode = this.keyTable[node.Key];
                }
                if (keyNode != null && this.childNodeCollectionTable.ContainsKey(keyNode))
                {
                    collection = this.childNodeCollectionTable[keyNode];
                }
            }
            if (collection == null)
            {
                return(new FakeSiteMapNodeCollection());
            }
            if (!this.SecurityTrimmingEnabled)
            {
                return(new FakeSiteMapNodeCollection(collection));
            }
            var secureCollection = new FakeSiteMapNodeCollection();

            foreach (ISiteMapNode secureNode in collection)
            {
                if (secureNode.IsAccessibleToUser())
                {
                    secureCollection.Add(secureNode);
                }
            }
            return(secureCollection);
        }
Esempio n. 32
0
        /// <summary>
        /// Retrieves a Boolean value indicating whether the specified <see cref="T:MvcSiteMapProvider.SiteMapNode"/> object can be viewed by the user in the specified context.
        /// </summary>
        /// <param name="node">The <see cref="T:MvcSiteMapProvider.SiteMapNode"/> that is requested by the user.</param>
        /// <returns>
        /// true if security trimming is enabled and <paramref name="node"/> can be viewed by the user or security trimming is not enabled; otherwise, false.
        /// </returns>
        /// <exception cref="T:System.ArgumentNullException">
        ///     <paramref name="node"/> is null.
        /// </exception>
        public virtual bool IsAccessibleToUser(ISiteMapNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            // If the sitemap is still being constructed, always
            // make all nodes accessible regardless of security trimming.
            if (!IsReadOnly)
            {
                return(true);
            }
            if (!SecurityTrimmingEnabled)
            {
                return(true);
            }
            return(pluginProvider.AclModule.IsAccessibleToUser(this, node));
        }
        public override IEnumerable <DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
        {
            var filmsDN = new List <DynamicNode>();

            foreach (var film in db.Films)
            {
                DynamicNode dn = new DynamicNode()
                {
                    Title     = film.Title,
                    Key       = "Film_" + film.FilmId,
                    ParentKey = "Category_" + film.CategoryId
                };
                dn.RouteValues.Add("id", film.FilmId);

                filmsDN.Add(dn);
            }

            return(filmsDN);
        }
Esempio n. 34
0
        protected virtual bool VerifyNode(ISiteMap siteMap, ISiteMapNode node, HttpContextBase httpContext)
        {
            var routes = this.FindRoutesForNode(node, httpContext);

            if (routes == null)
            {
                return(true); // Static URLs will sometimes have no route data, therefore return true.
            }
            // Time to delve into the AuthorizeAttribute defined on the node.
            // Let's start by getting all metadata for the controller...
            var controllerType = siteMap.ResolveControllerType(routes.GetAreaName(), routes.GetOptionalString("controller"));

            if (controllerType == null)
            {
                return(true);
            }

            return(this.VerifyController(node, routes, controllerType));
        }
Esempio n. 35
0
        /// <summary>
        /// Generates flat list of SiteMapNode from SiteMap hierarchy.
        /// </summary>
        /// <param name="startingNode">The starting node.</param>
        /// <param name="url">The URL.</param>
        /// <returns>A flat list of SiteMapNode.</returns>
        protected virtual IEnumerable <ISiteMapNode> FlattenHierarchy(ISiteMapNode startingNode, string url)
        {
            // Mvc node
            var mvcNode = startingNode;

            // Render current node?
            if (mvcNode == null || mvcNode.Clickable)
            {
                yield return(startingNode);
            }
            if (startingNode.HasChildNodes)
            {
                // Make sure all child nodes are accessible prior to rendering them...
                var shouldRender = true;
                foreach (ISiteMapNode node in startingNode.ChildNodes)
                {
                    // Check visibility
                    if (node != null)
                    {
                        shouldRender = node.IsVisible(SourceMetadata);
                    }

                    // Check ACL
                    if (!node.IsAccessibleToUser())
                    {
                        shouldRender = false;
                        break;
                    }

                    // Render child nodes?
                    if (shouldRender)
                    {
                        if (node.IsAccessibleToUser())
                        {
                            foreach (var childNode in FlattenHierarchy(node, url))
                            {
                                yield return(childNode);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 36
0
        protected virtual RequestContext CreateRequestContext(ISiteMapNode node, TextWriter writer)
        {
            var realRequestContext = this.mvcContextFactory.CreateRequestContext();

            // For interop with MvcCodeRouting, we need to build a data token with the appropriate value.
            realRequestContext.RouteData.SetMvcCodeRoutingContext(node);

            if (!node.IncludeAmbientValuesInUrl)
            {
                var httpContext        = this.CreateHttpContext(node, writer);
                var fakeRequestContext = this.mvcContextFactory.CreateRequestContext(httpContext);
                fakeRequestContext.RouteData.MergeDataTokens(realRequestContext.RouteData.DataTokens);
                fakeRequestContext.RouteData.Route        = realRequestContext.RouteData.Route;
                fakeRequestContext.RouteData.RouteHandler = realRequestContext.RouteData.RouteHandler;
                return(fakeRequestContext);
            }

            return(realRequestContext);
        }
 public override IEnumerable <DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
 {
     // BlogEntities would be your entity framework context class
     // or repository.
     using (var entities = new BlogEntities())
     {
         // Create a node for each blog
         foreach (var blogPost in entities.Blog)
         {
             DynamicNode dynamicNode = new DynamicNode();
             dynamicNode.Title     = blogPost.Title;
             dynamicNode.ParentKey = "Blog";
             dynamicNode.Key       = "BlogPost_" + blogPost.Id;
             dynamicNode.RouteValues.Add("id", blogPost.Id);
             dynamicNode.RouteValues.Add("seoName", blogPost.SeoName);
             yield return(dynamicNode);
         }
     }
 }
Esempio n. 38
0
        public override IEnumerable <DynamicNode> GetDynamicNodeCollection(ISiteMapNode nodes)
        {
            var returnValue = new List <DynamicNode>();

            using (EPSContext context = new EPSContext())
            {
                var LoginUserID = HttpContext.Current.Session["UserID"].ToString();
                int UserRole    = Convert.ToInt32(HttpContext.Current.Session["UserRole"].ToString());
                var query       = from rm in context.ROLEFUNCMAPPINGS
                                  where rm.RId == UserRole
                                  join f in context.FUNCS on rm.FId equals f.FId into memu
                                  from x in memu.DefaultIfEmpty()
                                  select new
                {
                    PId        = x.PId,
                    FId        = x.FId,
                    FuncName   = x.FuncName,
                    Controller = x.Controller,
                    Action     = x.Action,
                    Url        = x.Url,
                    ShowOrder  = x.ShowOrder
                };
                var SysMenus = query.OrderBy(c => c.ShowOrder).ToList();

                foreach (var menu in SysMenus)
                {
                    DynamicNode Node = new DynamicNode()
                    {
                        Title      = menu.FuncName,
                        ParentKey  = menu.PId > 0 ? menu.PId.ToString():"",
                        Key        = menu.FId.ToString(),
                        Controller = menu.Controller,
                        Action     = menu.Action,
                        Url        = menu.Url
                    };

                    returnValue.Add(Node);
                }
            }

            return(returnValue);
        }
        public override IEnumerable <DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
        {
            foreach (var server in serverManager.Servers.Values)
            {
                IList <SenkaData> playerList = server.GetFullPlayerList();
                foreach (var player in playerList)
                {
                    DynamicNode dynamicNode = new DynamicNode();
                    dynamicNode.Title       = player.PlayerName;
                    dynamicNode.Description = string.Format("{0} ({1})の戦果データ。", player.PlayerName, server.Name);

                    dynamicNode.ChangeFrequency = ChangeFrequency.Daily;
                    dynamicNode.UpdatePriority  = UpdatePriority.Absolute_040; //Below Normal
                    dynamicNode.RouteValues.Add("playerID", player.PlayerID);
                    dynamicNode.ParentKey = "Server" + server.ID.ToString();

                    yield return(dynamicNode);
                }
            }
        }
Esempio n. 40
0
        private void ProcessTreeNodes(ISiteMap siteMap, ISiteMapNode rootNode, SiteMapPageTree tree)
        {
            var parentNode = rootNode;

            foreach (var page in tree.ChildPages)
            {
                var childNode = GetSiteMapNodeFromTreeNode(siteMap, page);

                siteMap.AddNode(childNode, parentNode);

                // Process next level
                ProcessTreeNodes(siteMap, childNode, page);
            }

            foreach (var product in tree.Products)
            {
                var productNode = GetSiteMapNodeFromProductInfo(siteMap, product);
                siteMap.AddNode(productNode, parentNode);
            }
        }
Esempio n. 41
0
        public virtual HttpContextBase CreateHttpContext(ISiteMapNode node, Uri uri, TextWriter writer)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            var request = new HttpRequest(
                filename: string.Empty,
                url: uri.ToString(),
                queryString: string.IsNullOrEmpty(uri.Query) ? string.Empty : uri.Query.Substring(1));
            var response    = new HttpResponse(writer);
            var httpContext = new HttpContext(request, response);

            return(new SiteMapHttpContext(httpContext, node, uri));
        }
        protected virtual string ResolveRouteUrl(ISiteMapNode node, string area, string controller, string action, IDictionary <string, object> routeValues)
        {
            string result = string.Empty;

            // Create a TextWriter with null stream as a backing stream
            // which doesn't consume resources
            using (var nullWriter = new StreamWriter(Stream.Null))
            {
                var requestContext = this.CreateRequestContext(node, nullWriter);
                result = this.ResolveRouteUrl(node, area, controller, action, routeValues, requestContext);
            }

            if (string.IsNullOrEmpty(result))
            {
                // fixes #115 - UrlResolver should not throw exception.
                result = "#";
            }

            return(result);
        }
Esempio n. 43
0
        public virtual void RemoveNode(ISiteMapNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            lock (this.synclock)
            {
                // Remove the parent node relationship
                ISiteMapNode parentNode = null;
                if (this.parentNodeTable.ContainsKey(node))
                {
                    parentNode = this.parentNodeTable[node];
                    this.parentNodeTable.Remove(node);
                }

                // Remove the child node relationship
                if (parentNode != null)
                {
                    var nodes = this.childNodeCollectionTable[parentNode];
                    if ((nodes != null) && nodes.Contains(node))
                    {
                        nodes.Remove(node);
                    }
                }

                // Remove the URL
                var url = this.siteMapChildStateFactory.CreateUrlKey(node);
                if (this.urlTable.ContainsKey(url))
                {
                    this.urlTable.Remove(url);
                }

                // Remove the key
                string key = node.Key;
                if (this.keyTable.ContainsKey(key))
                {
                    this.keyTable.Remove(key);
                }
            }
        }
        /// <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.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>
        ///
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="siteMapPermission"></param>
        /// <param name="maxLevel"></param>
        /// <returns></returns>
        public static IList <MainMenu> GetUserMenus(this HtmlHelper helper,
                                                    SiteMapPermission siteMapPermission, int maxLevel)
        {
            ISiteMapNode node   = helper.MvcSiteMap().SiteMap.RootNode;
            var          result = new List <MainMenu>();

            for (int i = 0; i < node.ChildNodes.Count; i++)
            {
                ISiteMapNode childNode = node.ChildNodes[i];
                if (Match(siteMapPermission, childNode))
                {
                    var mainMenu = new MainMenu
                    {
                        Current = childNode,
                    };
                    SubMenuMatch(helper, siteMapPermission, mainMenu, maxLevel, 0);
                    result.Add(mainMenu);
                }
            }
            return(result);
        }
Esempio n. 46
0
        public override IEnumerable <DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
        {
            //throw new NotImplementedException();

            var filmsDN = new List <DynamicNode>();

            foreach (var film in db.Films)
            {
                DynamicNode dn = new DynamicNode()
                {
                    Title     = film.Title,
                    Key       = "Film_" + film.FilmID,
                    ParentKey = "Category_" + film.CategoryID
                };
                dn.RouteValues.Add("id", film.FilmID); //nazwa arg i jej wartosc

                filmsDN.Add(dn);
            }

            return(filmsDN);
        }
Esempio n. 47
0
        public override bool IsAccessibleToUser(ISiteMapNode node)
        {
            var key    = this.GetCacheKey("IsAccessibleToUser_" + node.Key);
            var result = this.requestCache.GetValue <bool?>(key);

            if (result == null)
            {
                // Fix for #272 - Change the context of the URL cache to ensure
                // that the AclModule doesn't prevent manually setting route values
                // from having any effect on the URL. This setting takes effect in
                // the RequestCacheableSiteMapNode.Url property.
                var urlContextKey = this.GetUrlContextKey();
                this.requestCache.SetValue <string>(urlContextKey, "AclModule");
                result = base.IsAccessibleToUser(node);
                this.requestCache.SetValue <bool>(key, (bool)result);

                // Restore the URL context.
                this.requestCache.SetValue <string>(urlContextKey, string.Empty);
            }
            return((bool)result);
        }
        public virtual HttpContextBase CreateHttpContext(ISiteMapNode node, Uri uri, TextWriter writer)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            var request     = new HttpRequest(string.Empty, uri.ToString(), uri.Query);
            var response    = new HttpResponse(writer);
            var httpContext = new HttpContext(request, response);

            return(new SiteMapHttpContext(httpContext, node));
        }
Esempio n. 49
0
        protected virtual RouteData FindRoutesForNode(ISiteMapNode node, HttpContextBase httpContext)
        {
            RouteData routeData = null;

            // Create a Uri for the current node. If we have an absolute URL,
            // it will be used instead of the baseUri.
            var nodeUri = new Uri(httpContext.Request.Url, node.Url);

            // Create a TextWriter with null stream as a backing stream
            // which doesn't consume resources
            using (var nullWriter = new StreamWriter(Stream.Null))
            {
                // Create a new HTTP context using the node's URL instead of the current one.
                var nodeHttpContext = this.mvcContextFactory.CreateHttpContext(node, nodeUri, nullWriter);

                // Find routes for the sitemap node's URL using the new HTTP context
                routeData = node.GetRouteData(nodeHttpContext);
            }

            return(routeData);
        }
Esempio n. 50
0
        public XmlSiteMapResult(
            int page,
            ISiteMapNode rootNode,
            IEnumerable <string> siteMapCacheKeys,
            string baseUrl,
            string siteMapUrlTemplate,
            ISiteMapLoader siteMapLoader)
        {
            if (siteMapLoader == null)
            {
                throw new ArgumentNullException("siteMapLoader");
            }

            this.Ns                 = "http://www.sitemaps.org/schemas/sitemap/0.9";
            this.Page               = page;
            this.RootNode           = rootNode;
            this.SiteMapCacheKeys   = siteMapCacheKeys;
            this.BaseUrl            = baseUrl;
            this.SiteMapUrlTemplate = siteMapUrlTemplate;
            this.siteMapLoader      = siteMapLoader;
        }
        /// <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();

            // Check for the source HtmlHelper
            if (sourceMetadata["HtmlHelper"] == null)
            {
                return(true);
            }
            string htmlHelper = sourceMetadata["HtmlHelper"].ToString();

            htmlHelper = htmlHelper.Substring(htmlHelper.LastIndexOf(".") + 1);

            // All set. Now parse the visibility variable.
            foreach (string visibilityKeyword in visibility.Split(new[] { ',', ';' }))
            {
                if (visibilityKeyword == htmlHelper || visibilityKeyword == "*")
                {
                    return(true);
                }
                else if (visibilityKeyword == "!" + htmlHelper || visibilityKeyword == "!*")
                {
                    return(false);
                }
            }

            // Still nothing? Then it's OK!
            return(true);
        }
Esempio n. 52
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>
        /// <exception cref="System.ArgumentNullException">node</exception>
        public bool IsVisible(ISiteMapNode node, IDictionary <string, object> sourceMetadata)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            sessionStateProvider = new SessionStateProvider();
            session = new SessionStateService(sessionStateProvider);

            //TODO: Uncomment below before deployment to prod.
            var isUserLoggedIn = (session.GetSessionValue(SessionKey.UserIsAuthenticated) ?? "").ToString().AsBoolean();

            if (!isUserLoggedIn && (node.Title != "Home"))
            {
                return(false);
            }

            IRoleCollection roles = node.Roles;

            //if no role is associated to node - allow it to show
            if (!roles.Any())
            {
                return(true);
            }

            var roleCollection        = ((string[])session.GetSessionValue(SessionKey.UserRoles) ?? new[] { "" }).ToList();
            var roleCollectionToUpper = roleCollection.Select(role => role.ToUpper()).ToList();
            var isGranted             = false;

            foreach (var role in roles)
            {
                isGranted = roleCollectionToUpper.Contains(role.ToUpper());
                if (isGranted)
                {
                    break;
                }
            }
            return(isGranted);
        }
Esempio n. 53
0
        /// <summary>
        /// Finds the controller action node.
        /// </summary>
        /// <param name="rootNode">The root node.</param>
        /// <param name="values">The values.</param>
        /// <param name="route">The route.</param>
        /// <returns>
        /// A controller action node represented as a <see cref="SiteMapNode"/> instance
        /// </returns>
        protected virtual ISiteMapNode FindSiteMapNodeFromControllerAction(ISiteMapNode rootNode, IDictionary <string, object> values, RouteBase route)
        {
            if (rootNode != null)
            {
                // Get all child nodes
                var childNodes = GetChildNodes(rootNode);

                var routes = mvcContextFactory.GetRoutes();

                // Search current level
                foreach (ISiteMapNode node in childNodes)
                {
                    // Look at the route property
                    if (!string.IsNullOrEmpty(node.Route))
                    {
                        if (routes[node.Route] == route)
                        {
                            // This looks a bit weird, but if i set up a node to a general route ie /Controller/Action/ID
                            // I need to check that the values are the same so that it doesn't swallow all of the nodes that also use that same general route
                            if (node.MatchesRoute(values))
                            {
                                return(node);
                            }
                        }
                    }
                    else if (node.MatchesRoute(values))
                    {
                        return(node);
                    }

                    // Search next level
                    var siteMapNode = FindSiteMapNodeFromControllerAction(node, values, route);
                    if (siteMapNode != null)
                    {
                        return(siteMapNode);
                    }
                }
            }
            return(null);
        }
        //przeciążenie metody
        public override IEnumerable <DynamicNode> GetDynamicNodeCollection(ISiteMapNode nodee)
        {
            //deklaracja zmniennej
            var returnValue = new List <DynamicNode>();

            //do listy dodaję produkty iteruję po wszystkich produktach
            //pobieram wszystkie produkty
            foreach (Kategoria kategoria in db.Kategorie)
            { //Dla każdego produktu tworzę DynamicNodeProvider(deklaruję dynamicnodeprovider)
                DynamicNode node = new DynamicNode();
                //ustawiamy mu wartość Title nazwę produktu
                node.Title = kategoria.nazwa_kat;
                //ustawiam klucz dla noda
                node.Key = "Kategoria_" + kategoria.id_kategoria;

                node.RouteValues.Add("nazwaKategori", kategoria.nazwa_kat);
                //przekazanie node do listy
                returnValue.Add(node);
            }
            //generuje dynamicznie linki (na koniec zwracam liste)
            return(returnValue);
        }
        public override IEnumerable <DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
        {
            foreach (var server in serverManager.Servers.Values)
            {
                DynamicNode dynamicNode = new DynamicNode();
                if (server.Enabled)
                {
                    dynamicNode.Description = string.Format("「{0}」の最新の戦果ランキングです。", server.Name);
                }
                else
                {
                    dynamicNode.Description = "このサーバの情報今はありません。";
                }
                dynamicNode.Title           = "ランキング";
                dynamicNode.ChangeFrequency = ChangeFrequency.Hourly;
                dynamicNode.UpdatePriority  = UpdatePriority.High;
                dynamicNode.RouteValues.Add("serverID", server.ID);
                dynamicNode.ParentKey = "Server" + server.ID.ToString();

                yield return(dynamicNode);
            }
        }
Esempio n. 56
0
        protected virtual bool VerifyController(ISiteMapNode node, RouteData routes, Type controllerType)
        {
            // Get controller factory
            var controllerFactory = controllerBuilder.GetControllerFactory();

            // Create controller context
            bool factoryBuiltController = false;
            var  controllerContext      = this.CreateControllerContext(node, routes, controllerType, controllerFactory, out factoryBuiltController);

            try
            {
                return(this.VerifyControllerAttributes(routes, controllerType, controllerContext));
            }
            finally
            {
                // Release controller
                if (factoryBuiltController)
                {
                    controllerFactory.ReleaseController(controllerContext.Controller);
                }
            }
        }
Esempio n. 57
0
        /// <summary>
        /// Resolves the URL.
        /// </summary>
        /// <param name="node">The MVC site map node.</param>
        /// <param name="area">The area.</param>
        /// <param name="controller">The controller.</param>
        /// <param name="action">The action.</param>
        /// <param name="routeValues">The route values.</param>
        /// <returns>The resolved URL.</returns>
        public override string ResolveUrl(ISiteMapNode node, string area, string controller, string action, IDictionary <string, object> routeValues)
        {
            if (!String.IsNullOrEmpty(node.UnresolvedUrl))
            {
                if (node.UnresolvedUrl.StartsWith("~"))
                {
                    return(VirtualPathUtility.ToAbsolute(node.UnresolvedUrl));
                }
                else
                {
                    return(node.UnresolvedUrl);
                }
            }

            var urlHelper = mvcContextFactory.CreateUrlHelper();

            string returnValue;
            var    routeValueDictionary = new RouteValueDictionary(routeValues);

            if (!string.IsNullOrEmpty(node.Route))
            {
                routeValueDictionary.Remove("route");
                returnValue = urlHelper.RouteUrl(node.Route, routeValueDictionary);
            }
            else
            {
                returnValue = urlHelper.Action(action, controller, routeValueDictionary);
            }

            if (string.IsNullOrEmpty(returnValue))
            {
                // fixes #115 - UrlResolver should not throw exception.
                return(VirtualPathUtility.ToAbsolute("~/") + Guid.NewGuid().ToString());
            }
            else
            {
                return(returnValue);
            }
        }
Esempio n. 58
0
        public void AddNode(ISiteMapNode node, ISiteMapNode parentNode)
        {
            // Avoid issue with url table not clearing correctly.
            if (this.FindSiteMapNode(node.Url) != null)
            {
                this.RemoveNode(node);
            }

            // Add the node
            try
            {
                AddNodeInternal(node, parentNode);
            }
            catch
            {
                if (parentNode != null)
                {
                    this.RemoveNode(parentNode);
                }
                AddNodeInternal(node, parentNode);
            }
        }
        /// <summary>
        /// Ensures all routedata elements are included on the node whenever the mvc action is invoked.
        /// This allows the MVC site map to have route values preserved for breadcrumb trails.
        /// </summary>
        /// <param name="filterContext">The current filter context.</param>
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            ISiteMapNode node    = null;
            var          siteMap = SiteMaps.Current;

            if (Target != AttributeTarget.ParentNode)
            {
                node = siteMap.CurrentNode;
            }
            else
            {
                node = siteMap.CurrentNode.ParentNode;
            }

            if (node != null)
            {
                foreach (var routeitem in filterContext.RouteData.Values)
                {
                    node.RouteValues[routeitem.Key] = routeitem.Value;
                }
            }
        }
 /// <summary>
 /// Generates flat list of SiteMapNode from SiteMap hierarchy.
 /// </summary>
 /// <param name="startingNode">The starting node.</param>
 /// <param name="context">The controller context.</param>
 /// <param name="visibilityAffectsDescendants">A boolean indicating whether visibility of the current node should affect the visibility of descendant nodes.</param>
 /// <returns>A flat list of SiteMapNode.</returns>
 protected virtual IEnumerable <ISiteMapNode> FlattenHierarchy(ISiteMapNode startingNode, ControllerContext context, bool visibilityAffectsDescendants)
 {
     // Inaccessible - don't process current node or any descendant nodes.
     if (startingNode.IsAccessibleToUser() && (visibilityAffectsDescendants ? startingNode.IsVisible(SourceMetadata) : true))
     {
         if (this.ShouldNodeRender(startingNode, context))
         {
             yield return(startingNode);
         }
         if (startingNode.HasChildNodes)
         {
             // Make sure all child nodes are accessible prior to rendering them...
             foreach (ISiteMapNode node in startingNode.ChildNodes)
             {
                 foreach (var childNode in FlattenHierarchy(node, context, visibilityAffectsDescendants))
                 {
                     yield return(childNode);
                 }
             }
         }
     }
 }