本文整理汇总了C#中ISiteMap.AddNode方法的典型用法代码示例。如果您正苦于以下问题:C# ISiteMap.AddNode方法的具体用法?C# ISiteMap.AddNode怎么用?C# ISiteMap.AddNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISiteMap
的用法示例。
在下文中一共展示了ISiteMap.AddNode方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: AddAndTrackNode
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);
}
示例3: BuildSiteMap
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;
}
示例4: LoadSiteMapFromXml
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;
}
示例5: BuildSiteMap
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;
}
示例6: ProcessNodes
protected virtual void ProcessNodes(ISiteMap siteMap, ISiteMapNode rootNode, System.Web.SiteMapNode providerRootNode)
{
foreach (System.Web.SiteMapNode node in providerRootNode.ChildNodes)
{
var childNode = GetSiteMapNodeFromProviderNode(siteMap, node, rootNode);
ISiteMapNode parentNode = rootNode;
siteMap.AddNode(childNode, parentNode);
// Continue recursively processing
ProcessNodes(siteMap, childNode, node);
}
}
示例7: CreateNodesFromMvcSiteMapNodeAttributeDefinitions
/// <summary>
/// Creates the nodes from MVC site map node attribute definitions.
/// </summary>
/// <param name="definitions">The definitions.</param>
protected virtual ISiteMapNode CreateNodesFromMvcSiteMapNodeAttributeDefinitions(ISiteMap siteMap, ISiteMapNode parentNode, IEnumerable<IMvcSiteMapNodeAttributeDefinition> definitions)
{
// A dictionary of nodes to process later (node, parentKey)
var nodesToProcessLater = new Dictionary<ISiteMapNode, string>();
var emptyParentKeyCount = definitions.Where(t => string.IsNullOrEmpty(t.SiteMapNodeAttribute.ParentKey)).Count();
// Throw a sensible exception if the configuration has more than 1 empty parent key (#179).
if (emptyParentKeyCount > 1)
{
throw new MvcSiteMapException(Resources.Messages.ReflectionSiteMapBuilderRootKeyAmbiguous);
}
// Find root node
if (parentNode == null)
{
if (emptyParentKeyCount == 1)
{
ISiteMapNode attributedRootNode = null;
var item = definitions.Where(t => string.IsNullOrEmpty(t.SiteMapNodeAttribute.ParentKey)).Single();
var actionNode = item as MvcSiteMapNodeAttributeDefinitionForAction;
if (actionNode != null)
{
// Create node for action
attributedRootNode = GetSiteMapNodeFromMvcSiteMapNodeAttribute(
siteMap, actionNode.SiteMapNodeAttribute, actionNode.ControllerType, actionNode.ActionMethodInfo);
}
else
{
var controllerNode = item as MvcSiteMapNodeAttributeDefinitionForController;
if (controllerNode != null)
{
// Create node for controller
attributedRootNode = GetSiteMapNodeFromMvcSiteMapNodeAttribute(
siteMap, controllerNode.SiteMapNodeAttribute, controllerNode.ControllerType, null);
}
}
if (attributedRootNode.Attributes.ContainsKey("parentKey"))
{
attributedRootNode.Attributes.Remove("parentKey");
}
parentNode = attributedRootNode;
}
}
// Fixes #192 root node not added to sitemap
if (siteMap.FindSiteMapNodeFromKey(parentNode.Key) == null)
{
// Add the root node to the sitemap
siteMap.AddNode(parentNode);
}
// Create nodes
foreach (var assemblyNode in definitions.Where(t => !string.IsNullOrEmpty(t.SiteMapNodeAttribute.ParentKey)))
{
ISiteMapNode nodeToAdd = null;
// Create node
var actionNode = assemblyNode as MvcSiteMapNodeAttributeDefinitionForAction;
if (actionNode != null)
{
// Create node for action
nodeToAdd = GetSiteMapNodeFromMvcSiteMapNodeAttribute(
siteMap, actionNode.SiteMapNodeAttribute, actionNode.ControllerType, actionNode.ActionMethodInfo);
}
else
{
var controllerNode = assemblyNode as MvcSiteMapNodeAttributeDefinitionForController;
if (controllerNode != null)
{
// Create node for controller
nodeToAdd = GetSiteMapNodeFromMvcSiteMapNodeAttribute(
siteMap, controllerNode.SiteMapNodeAttribute, controllerNode.ControllerType, null);
}
}
// Add node
if (nodeToAdd != null)
{
if (string.IsNullOrEmpty(assemblyNode.SiteMapNodeAttribute.ParentKey))
{
throw new MvcSiteMapException(string.Format(Resources.Messages.NoParentKeyDefined, nodeToAdd.Controller, nodeToAdd.Action));
}
var parentForNode = parentNode != null ? siteMap.FindSiteMapNodeFromKey(assemblyNode.SiteMapNodeAttribute.ParentKey) : null;
if (parentForNode != null)
{
if (nodeToAdd.HasDynamicNodeProvider)
{
var dynamicNodesForChildNode = dynamicNodeBuilder.BuildDynamicNodesFor(siteMap, nodeToAdd, parentForNode);
foreach (var dynamicNode in dynamicNodesForChildNode)
{
// Verify parent/child relation
//.........这里部分代码省略.........
示例8: ProcessXmlNodes
/// <summary>
/// Recursively processes our XML document, parsing our siteMapNodes and dynamicNode(s).
/// </summary>
/// <param name="rootNode">The main root sitemap node.</param>
/// <param name="rootElement">The main root XML element.</param>
protected virtual void ProcessXmlNodes(ISiteMap siteMap, ISiteMapNode rootNode, XElement rootElement)
{
// Loop through each element below the current root element.
foreach (XElement node in rootElement.Elements())
{
ISiteMapNode childNode;
if (node.Name == xmlNameProvider.NodeName)
{
// If this is a normal mvcSiteMapNode then map the xml element
// to an MvcSiteMapNode, and add the node to the current root.
childNode = GetSiteMapNodeFromXmlElement(siteMap, node, rootNode);
ISiteMapNode parentNode = rootNode;
if (!childNode.HasDynamicNodeProvider)
{
siteMap.AddNode(childNode, parentNode);
}
else
{
var dynamicNodesCreated = dynamicNodeBuilder.BuildDynamicNodesFor(siteMap, childNode, parentNode);
// Add non-dynamic children for every dynamic node
foreach (var dynamicNodeCreated in dynamicNodesCreated)
{
ProcessXmlNodes(siteMap, dynamicNodeCreated, node);
}
}
}
else
{
// If the current node is not one of the known node types throw and exception
throw new Exception(Resources.Messages.InvalidSiteMapElement);
}
// Continue recursively processing the XML file.
ProcessXmlNodes(siteMap, childNode, node);
}
}
示例9: ProcessTreeNodes
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);
}
}