/// <devdoc> /// <para>Add single node to provider tree and sets the parent-child relation.</para> /// </devdoc> protected internal override void AddNode(SiteMapNode node, SiteMapNode parentNode) { if (node == null) { throw new ArgumentNullException("node"); } lock (_lock) { bool validUrl = false; string url = node.Url; if (!String.IsNullOrEmpty(url)) { if (HttpRuntime.AppDomainAppVirtualPath != null) { if (!UrlPath.IsAbsolutePhysicalPath(url)) { url = UrlPath.Combine(HttpRuntime.AppDomainAppVirtualPathString, url); // Normalize url url = UrlPath.MakeVirtualPathAppAbsolute(url); } if (UrlTable[url] != null) { throw new InvalidOperationException( SR.GetString(SR.XmlSiteMapProvider_Multiple_Nodes_With_Identical_Url, url)); } } validUrl = true; } String key = node.Key; Debug.Assert(key != null); if (KeyTable.Contains(key)) { throw new InvalidOperationException( SR.GetString(SR.XmlSiteMapProvider_Multiple_Nodes_With_Identical_Key, key)); } KeyTable[key] = node; if (validUrl) { UrlTable[url] = node; } if (parentNode != null) { ParentNodeTable[node] = parentNode; if (ChildNodeCollectionTable[parentNode] == null) { ChildNodeCollectionTable[parentNode] = new SiteMapNodeCollection(); } ((SiteMapNodeCollection)ChildNodeCollectionTable[parentNode]).Add(node); } } }
protected internal override void RemoveNode(SiteMapNode node) { if (node == null) { throw new ArgumentNullException("node"); } lock (_lock) { SiteMapNode oldParent = (SiteMapNode)ParentNodeTable[node]; if (ParentNodeTable.Contains(node)) { ParentNodeTable.Remove(node); } if (oldParent != null) { SiteMapNodeCollection collection = (SiteMapNodeCollection)ChildNodeCollectionTable[oldParent]; if (collection != null && collection.Contains(node)) { collection.Remove(node); } } string url = node.Url; if (url != null && url.Length > 0 && UrlTable.Contains(url)) { UrlTable.Remove(url); } string key = node.Key; if (KeyTable.Contains(key)) { KeyTable.Remove(key); } } }
private void AddNodeInternal(SiteMapNode node, SiteMapNode parentNode, XmlNode xmlNode) { lock (_lock) { String url = node.Url; String key = node.Key; bool isValidUrl = false; // Only add the node to the url table if it's a static node. if (!String.IsNullOrEmpty(url)) { if (UrlTable[url] != null) { if (xmlNode != null) { throw new ConfigurationErrorsException( SR.GetString(SR.XmlSiteMapProvider_Multiple_Nodes_With_Identical_Url, url), xmlNode); } else { throw new InvalidOperationException(SR.GetString( SR.XmlSiteMapProvider_Multiple_Nodes_With_Identical_Url, url)); } } isValidUrl = true; } if (KeyTable.Contains(key)) { if (xmlNode != null) { throw new ConfigurationErrorsException( SR.GetString(SR.XmlSiteMapProvider_Multiple_Nodes_With_Identical_Key, key), xmlNode); } else { throw new InvalidOperationException( SR.GetString(SR.XmlSiteMapProvider_Multiple_Nodes_With_Identical_Key, key)); } } if (isValidUrl) { UrlTable[url] = node; } KeyTable[key] = node; // Add the new node into parentNode collection if (parentNode != null) { ParentNodeTable[node] = parentNode; if (ChildNodeCollectionTable[parentNode] == null) { ChildNodeCollectionTable[parentNode] = new SiteMapNodeCollection(); } ((SiteMapNodeCollection)ChildNodeCollectionTable[parentNode]).Add(node); } } }