Exemplo n.º 1
0
        protected virtual void AddDescendantNodes(ISiteMap siteMap, ISiteMapNode currentNode, IList <ISiteMapNodeToParentRelation> sourceNodes, IList <string> nodesAlreadyAdded)
        {
            if (sourceNodes.Count == 0)
            {
                return;
            }
            var children = sourceNodes.Where(x => x.ParentKey == 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, nodesAlreadyAdded);
            }
        }
        /// <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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// This determines the deepest node matching the current HTTP context, so if the current URL describes a location
        /// deeper than the site map designates, it will determine the closest parent to the current URL and return that 
        /// as the current node. This allows menu relevence when navigating deeper than the sitemap structure designates, such
        /// as when navigating to MVC actions, which are not shown in the menus
        /// </summary>
        /// <param name="selectedSiteMapProvider">the current MVC Site Map Provider</param>
        /// <returns></returns>
        public static ISiteMapNode GetCurrentNode(ISiteMap selectedSiteMap)
        {
            // get the node matching the current URL location
            var currentNode = selectedSiteMap.CurrentNode;

            // if there is no node matching the current URL path,
            // remove parts until we get a hit
            if (currentNode == null)
            {
                var url = HttpContext.Current.Request.Url.LocalPath;

                while (url.Length > 0)
                {
                    // see if we can find a matching node
                    currentNode = selectedSiteMap.FindSiteMapNode(url);

                    // if we get a hit, stop
                    if (currentNode != null) break;

                    // if not, remove the last path item
                    var lastSlashlocation = url.LastIndexOf("/");
                    if (lastSlashlocation < 0) break; // protects us from malformed URLs
                    url = url.Remove(lastSlashlocation);
                }
            }

            return currentNode;
        }
        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 SiteMapNodeHelper(
            ISiteMap siteMap,
            ICultureContext cultureContext,
            ISiteMapNodeCreatorFactory siteMapNodeCreatorFactory,
            IDynamicSiteMapNodeBuilderFactory dynamicSiteMapNodeBuilderFactory,
            IReservedAttributeNameProvider reservedAttributeNameProvider,
            ICultureContextFactory cultureContextFactory
            )
        {
            if (siteMap == null)
                throw new ArgumentNullException("siteMap");
            if (cultureContext == null)
                throw new ArgumentNullException("cultureContext");
            if (siteMapNodeCreatorFactory == null)
                throw new ArgumentNullException("siteMapNodeCreatorFactory");
            if (dynamicSiteMapNodeBuilderFactory == null)
                throw new ArgumentNullException("dynamicSiteMapNodeBuilderFactory");
            if (reservedAttributeNameProvider == null)
                throw new ArgumentNullException("reservedAttributeNameProvider");
            if (cultureContextFactory == null)
                throw new ArgumentNullException("cultureContextFactory");

            this.siteMap = siteMap;
            this.cultureContext = cultureContext;
            this.siteMapNodeCreatorFactory = siteMapNodeCreatorFactory;
            this.dynamicSiteMapNodeBuilderFactory = dynamicSiteMapNodeBuilderFactory;
            this.reservedAttributeNameProvider = reservedAttributeNameProvider;
            this.cultureContextFactory = cultureContextFactory;
        }
Exemplo n.º 6
0
 public SeoRouteValueDictionary(string siteMapNodeKey, string memberName, ISiteMap siteMap,
                                IReservedAttributeNameProvider reservedAttributeNameProvider,
                                IJsonToDictionaryDeserializer jsonToDictionaryDeserializer, ICache cache)
     : base(
         siteMapNodeKey, memberName, siteMap, reservedAttributeNameProvider, jsonToDictionaryDeserializer, cache)
 {
 }
 public SeoRouteValueDictionary(string siteMapNodeKey, string memberName, ISiteMap siteMap,
     IReservedAttributeNameProvider reservedAttributeNameProvider,
     IJsonToDictionaryDeserializer jsonToDictionaryDeserializer, ICache cache)
     : base(
         siteMapNodeKey, memberName, siteMap, reservedAttributeNameProvider, jsonToDictionaryDeserializer, cache)
 {
 }
        public RequestCacheableSiteMapNode(
            ISiteMap siteMap,
            string key,
            bool isDynamic,
            ISiteMapNodePluginProvider pluginProvider,
            IMvcContextFactory mvcContextFactory,
            ISiteMapNodeChildStateFactory siteMapNodeChildStateFactory,
            ILocalizationService localizationService,
            IUrlPath urlPath
            )
            : base(
                siteMap,
                key,
                isDynamic,
                pluginProvider,
                mvcContextFactory,
                siteMapNodeChildStateFactory,
                localizationService,
                urlPath
                )
        {
            if (mvcContextFactory == null)
            {
                throw new ArgumentNullException("mvcContextFactory");
            }

            this.requestCache = mvcContextFactory.GetRequestCache();
        }
Exemplo n.º 9
0
        private static Uri GetLoginUri_(Maybe <Uri> targetUrl, ISiteMap siteMap)
        {
            Contract.Requires(targetUrl != null);
            Contract.Requires(siteMap != null);

            return(targetUrl.Select(_ => siteMap.Login(_)).ValueOrElse(siteMap.Login()));
        }
Exemplo n.º 10
0
        /// <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;
        }
Exemplo n.º 11
0
        private static Uri GetNextUri_(Maybe <Uri> targetUrl, ISiteMap siteMap, ChiffonEnvironment environment)
        {
            Contract.Requires(targetUrl != null);
            Contract.Requires(siteMap != null);

            return(targetUrl.Select(_ => environment.MakeAbsoluteUri(_)).ValueOrElse(siteMap.Home()));
        }
        public SiteMapNodeHelper(
            string siteMapCacheKey,
            ISiteMap siteMap,
            ISiteMapNodeCreatorFactory siteMapNodeCreatorFactory,
            IDynamicSiteMapNodeBuilderFactory dynamicSiteMapNodeBuilderFactory,
            ISiteMapXmlReservedAttributeNameProvider reservedAttributeNameProvider
            )
        {
            if (String.IsNullOrEmpty(siteMapCacheKey))
                throw new ArgumentNullException("siteMapCacheKey");
            if (siteMap == null)
                throw new ArgumentNullException("siteMap");
            if (siteMapNodeCreatorFactory == null)
                throw new ArgumentNullException("siteMapNodeCreatorFactory");
            if (dynamicSiteMapNodeBuilderFactory == null)
                throw new ArgumentNullException("dynamicSiteMapNodeBuilderFactory");
            if (reservedAttributeNameProvider == null)
                throw new ArgumentNullException("reservedAttributeNameProvider");

            this.siteMapCacheKey = siteMapCacheKey;
            this.siteMap = siteMap;
            this.siteMapNodeCreatorFactory = siteMapNodeCreatorFactory;
            this.dynamicSiteMapNodeBuilderFactory = dynamicSiteMapNodeBuilderFactory;
            this.reservedAttributeNameProvider = reservedAttributeNameProvider;
        }
Exemplo n.º 13
0
        private static async Task <ContactItem> GetContactItem(ILogger _logger, ISiteMap siteMap, UserService userService,
                                                               BoxId fromBoxId, ChatDbModel chatDbModel = null)
        {
            var contact = new ContactItem();

            if (!string.IsNullOrEmpty(fromBoxId?.Id))
            {
                if (fromBoxId.Type == TypeBox.User)
                {
                    var userDb = await userService.FindApplicationUserByIdAsync(fromBoxId.Id);

                    contact.FullName = userDb.FullName;
                    contact.Id       = fromBoxId.Id;
                    contact.Type     = TypeBox.User;
                }
                else if (fromBoxId.Type == TypeBox.Site)
                {
                    contact.FullName = await siteMap.GetSiteNameAsync(fromBoxId.Id);

                    contact.Id   = fromBoxId.Id;
                    contact.Type = TypeBox.Site;
                }
                else if (fromBoxId.Type == TypeBox.UserNotAuthenticated)
                {
                    InitContactNotAUthenticated(_logger, chatDbModel, contact);
                }
            }
            else
            {
                InitContactNotAUthenticated(_logger, chatDbModel, contact);
            }
            return(contact);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Called by the MVC framework after the action method executes.
        /// </summary>
        /// <param name="filterContext">The filter context.</param>
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            ViewResult result = filterContext.Result as ViewResult;

            if (result != null)
            {
                var target = (ResolveTarget(result.ViewData.Model, PropertyName) ??
                              ResolveTarget(result.ViewData, PropertyName)) ??
                             result.ViewData[PropertyName];

                if (target != null)
                {
                    ISiteMap siteMap = SiteMaps.GetSiteMap(this.SiteMapCacheKey);
                    if (siteMap != null && siteMap.CurrentNode != null)
                    {
                        if (Target == AttributeTarget.ParentNode && siteMap.CurrentNode.ParentNode != null)
                        {
                            siteMap.CurrentNode.ParentNode.Title = target.ToString();
                        }
                        else
                        {
                            siteMap.CurrentNode.Title = target.ToString();
                        }
                    }
                }
            }
        }
Exemplo n.º 15
0
        public IEnumerable <ISiteMapNodeToParentRelation> BuildHierarchy(ISiteMap siteMap, IEnumerable <ISiteMapNodeToParentRelation> nodes)
        {
            var sourceNodesByParent     = nodes.ToLookup(n => n.ParentKey);
            var sourceNodes             = new List <ISiteMapNodeToParentRelation>(nodes);
            var nodesAddedThisIteration = 0;

            do
            {
                var nodesAlreadyAdded = new HashSet <string>();
                nodesAddedThisIteration = 0;
                foreach (var node in sourceNodes.OrderBy(x => x.Node.Order).ToArray())
                {
                    if (nodesAlreadyAdded.Contains(node.Node.Key))
                    {
                        continue;
                    }

                    var parentNode = siteMap.FindSiteMapNodeFromKey(node.ParentKey);
                    if (parentNode != null)
                    {
                        this.AddAndTrackNode(siteMap, node, parentNode, sourceNodes, nodesAlreadyAdded);
                        nodesAddedThisIteration += 1;

                        // Add the rest of the tree branch below the current node
                        this.AddDescendantNodes(siteMap, node.Node, sourceNodes, sourceNodesByParent, nodesAlreadyAdded);
                    }
                }
            }while (nodesAddedThisIteration > 0 && sourceNodes.Count > 0);

            return(sourceNodes);
        }
        protected virtual bool VerifyNode(ISiteMap siteMap, ISiteMapNode node, HttpContextBase httpContext)
        {
            // Time to delve into the AuthorizeAttribute defined on the node.
            // Let's start by getting all metadata for the controller...
            var controllerType = siteMap.ResolveControllerType(node.Area, node.Controller);

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

            var originalPath = httpContext.Request.Path;

            // Find routes for the sitemap node's url
            var routes = this.FindRoutesForNode(node, originalPath, httpContext);

            try
            {
                if (routes == null)
                {
                    return(true); // Static URL's will have no route data, therefore return true.
                }
                return(this.VerifyController(node, routes, controllerType));
            }
            finally
            {
                // Restore HttpContext
                httpContext.RewritePath(originalPath, true);
            }
        }
Exemplo n.º 17
0
        public SiteMapNodeHelper(
            string siteMapCacheKey,
            ISiteMap siteMap,
            ISiteMapNodeCreatorFactory siteMapNodeCreatorFactory,
            IDynamicSiteMapNodeBuilderFactory dynamicSiteMapNodeBuilderFactory,
            ISiteMapXmlReservedAttributeNameProvider reservedAttributeNameProvider
            )
        {
            if (String.IsNullOrEmpty(siteMapCacheKey))
            {
                throw new ArgumentNullException("siteMapCacheKey");
            }
            if (siteMap == null)
            {
                throw new ArgumentNullException("siteMap");
            }
            if (siteMapNodeCreatorFactory == null)
            {
                throw new ArgumentNullException("siteMapNodeCreatorFactory");
            }
            if (dynamicSiteMapNodeBuilderFactory == null)
            {
                throw new ArgumentNullException("dynamicSiteMapNodeBuilderFactory");
            }
            if (reservedAttributeNameProvider == null)
            {
                throw new ArgumentNullException("reservedAttributeNameProvider");
            }

            this.siteMapCacheKey                  = siteMapCacheKey;
            this.siteMap                          = siteMap;
            this.siteMapNodeCreatorFactory        = siteMapNodeCreatorFactory;
            this.dynamicSiteMapNodeBuilderFactory = dynamicSiteMapNodeBuilderFactory;
            this.reservedAttributeNameProvider    = reservedAttributeNameProvider;
        }
Exemplo n.º 18
0
 public CatalogSiteMapCacheInvalidationHook(
     ISiteMapService siteMapService,
     IDbContext dbContext)
 {
     _siteMap   = siteMapService.GetSiteMap("catalog");
     _dbContext = dbContext;
 }
Exemplo n.º 19
0
 public ListMessageCommand(ILogger <ListMessageCommand> logger, UserService userService, IMessageService messageService, ISiteMap sitemap)
 {
     _logger         = logger;
     _userService    = userService;
     _messageService = messageService;
     _sitemap        = sitemap;
 }
Exemplo n.º 20
0
        public SiteMapNodeCreator(
            ISiteMap siteMap,
            ISiteMapNodeFactory siteMapNodeFactory,
            INodeKeyGenerator nodeKeyGenerator,
            ISiteMapNodeToParentRelationFactory siteMapNodeToParentRelationFactory)
        {
            if (siteMap == null)
            {
                throw new ArgumentNullException("siteMap");
            }
            if (siteMapNodeFactory == null)
            {
                throw new ArgumentNullException("siteMapNodeFactory");
            }
            if (nodeKeyGenerator == null)
            {
                throw new ArgumentNullException("nodeKeyGenerator");
            }
            if (siteMapNodeToParentRelationFactory == null)
            {
                throw new ArgumentNullException("siteMapNodeToParentRelationFactory");
            }

            this.siteMap            = siteMap;
            this.siteMapNodeFactory = siteMapNodeFactory;
            this.nodeKeyGenerator   = nodeKeyGenerator;
            this.siteMapNodeToParentRelationFactory = siteMapNodeToParentRelationFactory;
        }
        public IEnumerable<ISiteMapNodeToParentRelation> BuildHierarchy(ISiteMap siteMap, IEnumerable<ISiteMapNodeToParentRelation> nodes)
        {
            var sourceNodesByParent = nodes.ToLookup(n => n.ParentKey);
            var sourceNodes = new List<ISiteMapNodeToParentRelation>(nodes);
            var nodesAddedThisIteration = 0;
            do
            {
                var nodesAlreadyAdded = new HashSet<string>();
                nodesAddedThisIteration = 0;
                foreach (var node in sourceNodes.OrderBy(x => x.Node.Order).ToArray())
                {
                    if (nodesAlreadyAdded.Contains(node.Node.Key))
                    {
                        continue;
                    }

                    var parentNode = siteMap.FindSiteMapNodeFromKey(node.ParentKey);
                    if (parentNode != null)
                    {
                        this.AddAndTrackNode(siteMap, node, parentNode, sourceNodes, nodesAlreadyAdded);
                        nodesAddedThisIteration += 1;

                        // Add the rest of the tree branch below the current node
                        this.AddDescendantNodes(siteMap, node.Node, sourceNodes, sourceNodesByParent, nodesAlreadyAdded);
                    }
                }
            }
            while (nodesAddedThisIteration > 0 && sourceNodes.Count > 0);

            return sourceNodes;
        }
Exemplo n.º 22
0
        public RouteValueDictionary(
            string siteMapNodeKey,
            string memberName,
            ISiteMap siteMap,
            IReservedAttributeNameProvider reservedAttributeNameProvider,
            IJsonToDictionaryDeserializer jsonToDictionaryDeserializer,
            ICache cache
            ) : base(siteMap, cache)
        {
            if (string.IsNullOrEmpty(siteMapNodeKey))
            {
                throw new ArgumentNullException("siteMapNodeKey");
            }
            if (string.IsNullOrEmpty(memberName))
            {
                throw new ArgumentNullException("memberName");
            }
            if (reservedAttributeNameProvider == null)
            {
                throw new ArgumentNullException("reservedAttributeNameProvider");
            }
            if (jsonToDictionaryDeserializer == null)
            {
                throw new ArgumentNullException("jsonToDictionaryDeserializer");
            }

            this.siteMapNodeKey = siteMapNodeKey;
            this.memberName     = memberName;
            this.reservedAttributeNameProvider = reservedAttributeNameProvider;
            this.jsonToDictionaryDeserializer  = jsonToDictionaryDeserializer;

            // An area route value must always exist, so we add it here to ensure it does.
            this["area"] = string.Empty;
        }
Exemplo n.º 23
0
 public GetMessageCommand(UserService userService, IMessageService messageService, ISiteMap siteMap, ILoggerFactory loggerFactory)
 {
     _userService    = userService;
     _messageService = messageService;
     _siteMap        = siteMap;
     this._logger    = loggerFactory.CreateLogger("GetMessageCommand");
 }
Exemplo n.º 24
0
 public SendMessageCommand(UserService userService, IMessageService messageService, IEmailService emailService, ISiteMap siteMap, ILoggerFactory loggerFactory)
 {
     _userService    = userService;
     _messageService = messageService;
     _emailService   = emailService;
     _siteMap        = siteMap;
     _logger         = loggerFactory.CreateLogger("SendMessageCommand");
 }
 public ISiteMapNodeCreator Create(ISiteMap siteMap)
 {
     return new SiteMapNodeCreator(
         siteMap, 
         this.siteMapNodeFactory, 
         this.nodeKeyGenerator, 
         this.siteMapNodeToParentRelationFactory);
 }
Exemplo n.º 27
0
 public ListMessageCommand(ILogger <ListMessageCommand> logger, IDataFactory dataFactory, UserService userService, IMessageService messageService, ISiteMap sitemap)
 {
     _logger         = logger;
     _userService    = userService;
     _messageService = messageService;
     _sitemap        = sitemap;
     _dataFactory    = dataFactory;
 }
Exemplo n.º 28
0
        public AccountController(ChiffonEnvironment environment, ISiteMap siteMap, IMemberService memberService)
            : base(environment, siteMap)
        {
            Require.NotNull(memberService, "memberService");
            Contract.Requires(siteMap != null);

            _memberService = memberService;
        }
Exemplo n.º 29
0
 public CatalogSiteMapInvalidationConsumer(
     ISiteMapService siteMapService,
     ICommonServices services,
     CatalogSettings catalogSettings)
 {
     _siteMap         = siteMapService.GetSiteMap("catalog");
     _services        = services;
     _catalogSettings = catalogSettings;
 }
Exemplo n.º 30
0
 public ISiteMapNodeHelper Create(ISiteMap siteMap, string siteMapCacheKey)
 {
     return(new SiteMapNodeHelper(
                siteMapCacheKey,
                siteMap,
                this.siteMapNodeCreatorFactory,
                this.dynamicSiteMapNodeBuilderFactory,
                this.reservedAttributeNameProvider));
 }
Exemplo n.º 31
0
        public LockableList(ISiteMap siteMap)
        {
            if (siteMap == null)
            {
                throw new ArgumentNullException("siteMap");
            }

            this.siteMap = siteMap;
        }
 public ISiteMapNode BuildSiteMap(ISiteMap siteMap, ISiteMapNode rootNode)
 {
     ISiteMapNode result = rootNode;
     foreach (var builder in this.siteMapBuilders)
     {
         result = builder.BuildSiteMap(siteMap, result);
     }
     return result;
 }
 public ISiteMapNodeHelper Create(ISiteMap siteMap, string siteMapCacheKey)
 {
     return new SiteMapNodeHelper(
         siteMapCacheKey,
         siteMap,
         this.siteMapNodeCreatorFactory,
         this.dynamicSiteMapNodeBuilderFactory,
         this.reservedAttributeNameProvider);
 }
        /// <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);
        }
        /// <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 virtual ISiteMapNode BuildSiteMap(ISiteMap siteMap, ISiteMapNode rootNode)
        {
            if (rootNode == null)
            {
                throw new ArgumentNullException("rootNode", Resources.Messages.VisitingSiteMapBuilderRequiresRootNode);
            }

            VisitNodes(rootNode);
            return rootNode;
        }
 protected virtual void LoadSourceNodes(ISiteMap siteMap, List <ISiteMapNodeToParentRelation> sourceNodes)
 {
     // Temporarily override the current thread's culture with the invariant culture
     // while running the ISiteMapNodeProvider instances.
     using (var cultureContext = this.cultureContextFactory.CreateInvariant())
     {
         var siteMapNodeHelper = this.siteMapNodeHelperFactory.Create(siteMap, cultureContext);
         sourceNodes.AddRange(this.siteMapNodeProvider.GetSiteMapNodes(siteMapNodeHelper));
     }
 }
        public virtual ISiteMapNode BuildSiteMap(ISiteMap siteMap, ISiteMapNode rootNode)
        {
            if (rootNode == null)
            {
                throw new ArgumentNullException("rootNode", Resources.Messages.VisitingSiteMapBuilderRequiresRootNode);
            }

            VisitNodes(rootNode);
            return(rootNode);
        }
Exemplo n.º 39
0
        public HomeController(ChiffonEnvironment environment, ISiteMap siteMap, IMessenger messenger, IDbQueries queries)
            : base(environment, siteMap)
        {
            Require.NotNull(messenger, "messenger");
            Require.NotNull(queries, "queries");
            Contract.Requires(siteMap != null);

            _messenger = messenger;
            _queries   = queries;
        }
Exemplo n.º 40
0

        
 public ISiteMapNodeHelper Create(ISiteMap siteMap, ICultureContext cultureContext)
 {
     return(new SiteMapNodeHelper(
                siteMap,
                cultureContext,
                this.siteMapNodeCreatorFactory,
                this.dynamicSiteMapNodeBuilderFactory,
                this.reservedAttributeNameProvider,
                this.cultureContextFactory));
 }
        /// <summary>
        /// Creates a new MvcSiteMapProvider HtmlHelper.
        /// </summary>
        /// <param name="helper">The helper.</param>
        /// <param name="siteMapCacheKey">The SiteMap Cache Key.</param>
        /// <returns>
        /// A <see cref="MvcSiteMapHtmlHelper"/> instance
        /// </returns>
        public static MvcSiteMapHtmlHelper MvcSiteMap(this HtmlHelper helper, string siteMapCacheKey)
        {
            ISiteMap siteMap = SiteMaps.GetSiteMap(siteMapCacheKey);

            if (siteMap == null)
            {
                throw new UnknownSiteMapException();
            }
            return(MvcSiteMap(helper, siteMap));
        }
 public ISiteMapNodeHelper Create(ISiteMap siteMap, ICultureContext cultureContext)
 {
     return new SiteMapNodeHelper(
         siteMap,
         cultureContext,
         this.siteMapNodeCreatorFactory,
         this.dynamicSiteMapNodeBuilderFactory,
         this.reservedAttributeNameProvider,
         this.cultureContextFactory);
 }
 /// <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;
 }
 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);
 }
Exemplo n.º 46
0
        public virtual ISiteMapNode BuildSiteMap(ISiteMap siteMap, ISiteMapNode rootNode)
        {
            var xml = xmlSource.GetXml();
            if (xml != null)
            {
                rootNode = LoadSiteMapFromXml(siteMap, xml);
            }

            // Done!
            return rootNode;
        }
Exemplo n.º 47
0
        /// <summary>
        /// Removes items from the provided site map.
        /// Note: The items are retrieved by the GetSiteMapItems() function.
        /// </summary>
        /// <param name="siteMap"></param>
        public virtual void Remove(ISiteMap siteMap)
        {
            using (LogGroup logGroup = LogGroup.StartDebug("Removing items from the provided site map."))
            {
                foreach (ISiteMapNode item in GetSiteMapItems())
                {
                    LogWriter.Debug("Action: " + item.Action + " | Type name: " + item.TypeName + " | Category: " + item.Category + " | Title: " + item.Title);

                    siteMap.Remove(item);
                }
            }
        }
        protected virtual void AddDescendantNodes(ISiteMap siteMap, ISiteMapNode currentNode, IList<ISiteMapNodeToParentRelation> sourceNodes, IList<string> nodesAlreadyAdded)
        {
            if (sourceNodes.Count == 0) return;
            var children = sourceNodes.Where(x => x.ParentKey == 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, nodesAlreadyAdded);
            }
        }
        /// <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)
        {
            // Not Clickable? Always accessible.
            if (!node.Clickable)
                return true;

            var httpContext = mvcContextFactory.CreateHttpContext();

            // Is it an external Url?
            if (node.HasExternalUrl(httpContext))
                return true;

            return this.VerifyNode(siteMap, node, httpContext);
        }
Exemplo n.º 50
0
        public ISiteMapNode BuildSiteMap(ISiteMap siteMap, ISiteMapNode rootNode)
        {
            // Set Properties
            siteMap.EnableLocalization = false;
            siteMap.SecurityTrimmingEnabled = true;

            var tree = siteMapPageTreeFactory.GetSiteMapPageTree();

            // Get the root node
            var root = GetRootNode(siteMap, tree);

            ProcessTreeNodes(siteMap, root, tree);

            return root;
        }
        protected ISiteMapNode CreateInternal(ISiteMap siteMap, string key, string implicitResourceKey, bool isDynamic)
        {
            // IMPORTANT: we must create one localization service per node because the service contains its own state that applies to the node
            var localizationService = localizationServiceFactory.Create(implicitResourceKey);

            return new RequestCacheableSiteMapNode(
                siteMap,
                key,
                isDynamic,
                pluginProvider,
                mvcContextFactory,
                siteMapNodeChildStateFactory,
                localizationService,
                urlPath);
        }
        public ISiteMapNode BuildSiteMap(ISiteMap siteMap, ISiteMapNode rootNode)
        {
            var provider = siteMapProvider.GetProvider();

            rootNode = GetRootNode(siteMap, provider);
            // Fixes #192 root node not added to sitemap
            if (siteMap.FindSiteMapNodeFromKey(rootNode.Key) == null)
            {
                // Add the root node to the sitemap
                siteMap.AddNode(rootNode);
            }

            ProcessNodes(siteMap, rootNode, provider.RootNode);

            return rootNode;
        }
Exemplo n.º 53
0
        private ISiteMapNode GetSiteMapNodeFromProductInfo(ISiteMap siteMap, SiteMapProductInfo productInfo)
        {
            var key = productInfo.CategoryXProductId.ToString();
            var node = siteMapNodeFactory.Create(siteMap, key, "");

            // Assign values
            node.Title = productInfo.Name;
            node.Url = productInfo.UrlPath;

            // Setup visibility
            node.Attributes.Add("isVisibleOnMainMenu", "false");
            node.VisibilityProvider = typeof(VisibilityProvider).ShortAssemblyQualifiedName();
            node.CanonicalUrl = productInfo.CanonicalUrlPath;

            AcquireMetaRobotsValuesFrom(productInfo.MetaRobots, node.MetaRobotsValues);

            return node;
        }
 public LockableSiteMapNode(
     ISiteMap siteMap,
     string key,
     bool isDynamic,
     ISiteMapNodePluginProvider pluginProvider,
     IMvcContextFactory mvcContextFactory,
     ISiteMapNodeChildStateFactory siteMapNodeChildStateFactory,
     ILocalizationService localizationService,
     IUrlPath urlPath
     )
     : base(siteMap, 
         key, 
         isDynamic,
         pluginProvider,
         mvcContextFactory,
         siteMapNodeChildStateFactory, 
         localizationService, 
         urlPath)
 {
 }
        public SiteMapNodeCreator(
            ISiteMap siteMap,
            ISiteMapNodeFactory siteMapNodeFactory,
            INodeKeyGenerator nodeKeyGenerator,
            ISiteMapNodeToParentRelationFactory siteMapNodeToParentRelationFactory)
        {
            if (siteMap == null)
                throw new ArgumentNullException("siteMap");
            if (siteMapNodeFactory == null)
                throw new ArgumentNullException("siteMapNodeFactory");
            if (nodeKeyGenerator == null)
                throw new ArgumentNullException("nodeKeyGenerator");
            if (siteMapNodeToParentRelationFactory == null)
                throw new ArgumentNullException("siteMapNodeToParentRelationFactory");

            this.siteMap = siteMap;
            this.siteMapNodeFactory = siteMapNodeFactory;
            this.nodeKeyGenerator = nodeKeyGenerator;
            this.siteMapNodeToParentRelationFactory = siteMapNodeToParentRelationFactory;
        }
Exemplo n.º 56
0
        public SiteMapNode(
            ISiteMap siteMap, 
            string key,
            bool isDynamic,
            ISiteMapNodePluginProvider pluginProvider,
            IMvcContextFactory mvcContextFactory,
            ISiteMapNodeChildStateFactory siteMapNodeChildStateFactory,
            ILocalizationService localizationService,
            IUrlPath urlPath
            )
        {
            if (siteMap == null)
                throw new ArgumentNullException("siteMap");
            if (string.IsNullOrEmpty(key))
                throw new ArgumentNullException("key");
            if (pluginProvider == null)
                throw new ArgumentNullException("pluginProvider");
            if (mvcContextFactory == null)
                throw new ArgumentNullException("mvcContextFactory");
            if (siteMapNodeChildStateFactory == null)
                throw new ArgumentNullException("siteMapNodeChildStateFactory");
            if (localizationService == null)
                throw new ArgumentNullException("localizationService");
            if (urlPath == null)
                throw new ArgumentNullException("urlPath");

            this.siteMap = siteMap;
            this.key = key;
            this.isDynamic = isDynamic;
            this.pluginProvider = pluginProvider;
            this.mvcContextFactory = mvcContextFactory;
            this.localizationService = localizationService;
            this.urlPath = urlPath;

            // Initialize child collections
            this.attributes = siteMapNodeChildStateFactory.CreateAttributeDictionary(key, "Attributes", siteMap, localizationService);
            this.routeValues = siteMapNodeChildStateFactory.CreateRouteValueDictionary(key, "RouteValues", siteMap);
            this.preservedRouteParameters = siteMapNodeChildStateFactory.CreatePreservedRouteParameterCollection(siteMap);
            this.roles = siteMapNodeChildStateFactory.CreateRoleCollection(siteMap);
            this.metaRobotsValues = siteMapNodeChildStateFactory.CreateMetaRobotsValueCollection(siteMap);
        }
Exemplo n.º 57
0
        protected virtual ISiteMapNode LoadSiteMapFromXml(ISiteMap siteMap, XDocument xml)
        {
            xmlNameProvider.FixXmlNamespaces(xml);

            // Get the root mvcSiteMapNode element, and map this to an MvcSiteMapNode
            var rootElement = GetRootElement(xml);
            var root = GetRootNode(siteMap, xml, rootElement);

            // Fixes #192 root node not added to sitemap
            if (siteMap.FindSiteMapNodeFromKey(root.Key) == null)
            {
                // Add the root node to the sitemap
                siteMap.AddNode(root);
            }

            // Process our XML, passing in the main root sitemap node and XML element.
            ProcessXmlNodes(siteMap, root, rootElement);

            // Done!
            return root;
        }
        /// <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)
        {
            // Use child modules
            bool result = true;
            foreach (var module in aclModules)
            {
                try
                {
                    result &= module.IsAccessibleToUser(siteMap, node);
                }
                catch (AclModuleNotSupportedException)
                {
                    result &= true; // Convention throughout the provider: if the IAclModule can not authenticate a user, true is returned.
                }
                if (result == false)
                {
                    return false;
                }
            }

            // Return
            return result;
        }
Exemplo n.º 59
0
        public ISiteMapNode BuildSiteMap(ISiteMap siteMap, ISiteMapNode rootNode)
        {
            // Load the source nodes
            var sourceNodes = new List<ISiteMapNodeToParentRelation>();
            LoadSourceNodes(siteMap, sourceNodes);

            // Add the root node to the sitemap
            var root = GetRootNode(siteMap, sourceNodes);
            if (root != null)
            {
                siteMap.AddNode(root);
            }

            var orphans = this.siteMapHierarchyBuilder.BuildHierarchy(siteMap, sourceNodes);

            if (orphans.Count() > 0)
            {
                // We have orphaned nodes - filter to remove the matching descendants of the mismatched keys.
                var mismatched = from parent in orphans
                                 where !(from child in orphans
                                         select child.Node.Key)
                                         .Contains(parent.ParentKey)
                                 select parent;

                var names = string.Join(Environment.NewLine + Environment.NewLine, mismatched.Select(x =>
                    string.Format(Resources.Messages.SiteMapNodeFormatWithParentKey, x.ParentKey, x.Node.Controller,
                    x.Node.Action, x.Node.Area, x.Node.Url, x.Node.Key, x.SourceName)).ToArray());
                throw new MvcSiteMapException(string.Format(Resources.Messages.SiteMapBuilderOrphanedNodes, siteMap.CacheKey, names));
            }

            // Run our visitors
            VisitNodes(root);

            // Done!
            return root;
        }
Exemplo n.º 60
0
        /// <summary>
        /// This determines the deepest node matching the current HTTP context, so if the current URL describes a location
        /// deeper than the site map designates, it will determine the closest parent to the current URL and return that 
        /// as the current node. This allows menu relevance when navigating deeper than the sitemap structure designates, such
        /// as when navigating to MVC actions, which are not shown in the menus
        /// </summary>
        /// <param name="selectedSiteMapProvider">the current MVC Site Map Provider</param>
        /// <param name="returnRootNodeIfNotFound">whether to return the root node if the current node is null</param>
        /// <returns></returns>
        public static ISiteMapNode GetCurrentNode(ISiteMap selectedSiteMap, bool returnRootNodeIfNotFound)
        {
            // get the node matching the current URL location
            var currentNode = selectedSiteMap.CurrentNode;

            // if there is no node matching the current URL path,
            // remove parts until we get a hit
            if (currentNode == null)
            {
                var url = HttpContext.Current.Request.Url.LocalPath;
                var queryString = HttpContext.Current.Request.Url.Query;

                while (url.Length > 0)
                {
                    // see if we can find a matching node
                    currentNode = selectedSiteMap.FindSiteMapNode(url + queryString);

                    // if we get a hit, stop
                    if (currentNode != null) break;

                    // if not, remove the last path item
                    var lastSlashlocation = url.LastIndexOf("/");
                    if (lastSlashlocation < 0) break; // protects us from malformed URLs
                    url = url.Remove(lastSlashlocation);
                }
            }

            // If the current node is still null, return the root node.
            // This is the same way the SiteMap.FindSiteMapNode(rawUrl) method worked in v3.
            if (currentNode == null && returnRootNodeIfNotFound)
            {
                currentNode = selectedSiteMap.RootNode;
            }

            return currentNode;
        }