本文整理汇总了C#中ISiteMap类的典型用法代码示例。如果您正苦于以下问题:C# ISiteMap类的具体用法?C# ISiteMap怎么用?C# ISiteMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ISiteMap类属于命名空间,在下文中一共展示了ISiteMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SeoRouteValueDictionary
public SeoRouteValueDictionary(string siteMapNodeKey, string memberName, ISiteMap siteMap,
IReservedAttributeNameProvider reservedAttributeNameProvider,
IJsonToDictionaryDeserializer jsonToDictionaryDeserializer, ICache cache)
: base(
siteMapNodeKey, memberName, siteMap, reservedAttributeNameProvider, jsonToDictionaryDeserializer, cache)
{
}
示例2: SiteMapNodeHelper
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;
}
示例3: IsAccessibleToUser
/// <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;
}
示例4: BuildHierarchy
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;
}
示例5: AddDescendantNodes
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);
}
}
示例6: SiteMapNodeHelper
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;
}
示例7: GetCurrentNode
/// <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;
}
示例8: Create
public ISiteMapNodeCreator Create(ISiteMap siteMap)
{
return new SiteMapNodeCreator(
siteMap,
this.siteMapNodeFactory,
this.nodeKeyGenerator,
this.siteMapNodeToParentRelationFactory);
}
示例9: BuildSiteMap
public ISiteMapNode BuildSiteMap(ISiteMap siteMap, ISiteMapNode rootNode)
{
ISiteMapNode result = rootNode;
foreach (var builder in this.siteMapBuilders)
{
result = builder.BuildSiteMap(siteMap, result);
}
return result;
}
示例10: BuildDynamicNodesFor
/// <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;
}
示例11: Create
public ISiteMapNodeHelper Create(ISiteMap siteMap, string siteMapCacheKey)
{
return new SiteMapNodeHelper(
siteMapCacheKey,
siteMap,
this.siteMapNodeCreatorFactory,
this.dynamicSiteMapNodeBuilderFactory,
this.reservedAttributeNameProvider);
}
示例12: BuildSiteMap
public virtual ISiteMapNode BuildSiteMap(ISiteMap siteMap, ISiteMapNode rootNode)
{
if (rootNode == null)
{
throw new ArgumentNullException("rootNode", Resources.Messages.VisitingSiteMapBuilderRequiresRootNode);
}
VisitNodes(rootNode);
return rootNode;
}
示例13: Create
public ISiteMapNodeHelper Create(ISiteMap siteMap, ICultureContext cultureContext)
{
return new SiteMapNodeHelper(
siteMap,
cultureContext,
this.siteMapNodeCreatorFactory,
this.dynamicSiteMapNodeBuilderFactory,
this.reservedAttributeNameProvider,
this.cultureContextFactory);
}
示例14: BuildSiteMap
public virtual ISiteMapNode BuildSiteMap(ISiteMap siteMap, ISiteMapNode rootNode)
{
var xml = xmlSource.GetXml();
if (xml != null)
{
rootNode = LoadSiteMapFromXml(siteMap, xml);
}
// Done!
return rootNode;
}
示例15: IsAccessibleToUser
/// <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;
}