protected internal override void RemoveNode(SiteMapNode node) { if (node == null) { throw new ArgumentNullException("node"); } SiteMapProvider provider = node.Provider; if (provider != this) { for (SiteMapProvider provider2 = provider.ParentProvider; provider2 != this; provider2 = provider2.ParentProvider) { if (provider2 == null) { throw new InvalidOperationException(System.Web.SR.GetString("XmlSiteMapProvider_cannot_remove_node", new object[] { node.ToString(), this.Name, provider.Name })); } } } if (node.Equals(provider.GetRootNodeCore())) { throw new InvalidOperationException(System.Web.SR.GetString("SiteMapProvider_cannot_remove_root_node")); } if (provider != this) { provider.RemoveNode(node); } base.RemoveNode(node); }
private SiteMapNode GetNodeFromProvider(string providerName) { SiteMapProvider providerFromName = this.GetProviderFromName(providerName); SiteMapNode rootNodeCore = null; if (providerFromName is XmlSiteMapProvider) { XmlSiteMapProvider provider2 = (XmlSiteMapProvider)providerFromName; StringCollection strings = new StringCollection(); if (this._parentSiteMapFileCollection != null) { foreach (string str in this._parentSiteMapFileCollection) { strings.Add(str); } } provider2.BuildSiteMap(); strings.Add(this._normalizedVirtualPath.VirtualPathString); if (strings.Contains(VirtualPath.GetVirtualPathString(provider2._normalizedVirtualPath))) { throw new InvalidOperationException(System.Web.SR.GetString("XmlSiteMapProvider_FileName_already_in_use", new object[] { provider2._virtualPath })); } provider2._parentSiteMapFileCollection = strings; } rootNodeCore = providerFromName.GetRootNodeCore(); if (rootNodeCore == null) { throw new InvalidOperationException(System.Web.SR.GetString("XmlSiteMapProvider_invalid_GetRootNodeCore", new object[] { providerFromName.Name })); } this.ChildProviderTable.Add(providerFromName, rootNodeCore); this._childProviderList = null; providerFromName.ParentProvider = this; return(rootNodeCore); }
private SiteMapNode GetNodeFromProvider(string providerName) { SiteMapProvider provider = GetProviderFromName(providerName); SiteMapNode node = null; // Check infinite recursive sitemap files if (provider is XmlSiteMapProvider) { XmlSiteMapProvider xmlProvider = (XmlSiteMapProvider)provider; StringCollection parentSiteMapFileCollection = new StringCollection(); if (_parentSiteMapFileCollection != null) { foreach (string filename in _parentSiteMapFileCollection) { parentSiteMapFileCollection.Add(filename); } } // Make sure the provider is initialized before adding to the collection. xmlProvider.BuildSiteMap(); parentSiteMapFileCollection.Add(_normalizedVirtualPath.VirtualPathString); if (parentSiteMapFileCollection.Contains(VirtualPath.GetVirtualPathString(xmlProvider._normalizedVirtualPath))) { throw new InvalidOperationException(SR.GetString(SR.XmlSiteMapProvider_FileName_already_in_use, xmlProvider._virtualPath)); } xmlProvider._parentSiteMapFileCollection = parentSiteMapFileCollection; } node = provider.GetRootNodeCore(); if (node == null) { throw new InvalidOperationException( SR.GetString(SR.XmlSiteMapProvider_invalid_GetRootNodeCore, ((ProviderBase)provider).Name)); } ChildProviderTable.Add(provider, node); _childProviderList = null; provider.ParentProvider = this; return(node); }
protected internal override void RemoveNode(SiteMapNode node) { if (node == null) { throw new ArgumentNullException("node"); } SiteMapProvider ownerProvider = node.Provider; if (ownerProvider != this) { // Only nodes defined in this provider tree can be removed. SiteMapProvider parentProvider = ownerProvider.ParentProvider; while (parentProvider != this) { if (parentProvider == null) { // Cannot remove nodes defined in other providers throw new InvalidOperationException( SR.GetString(SR.XmlSiteMapProvider_cannot_remove_node, node.ToString(), this.Name, ownerProvider.Name)); } parentProvider = parentProvider.ParentProvider; } } if (node.Equals(ownerProvider.GetRootNodeCore())) { throw new InvalidOperationException(SR.GetString(SR.SiteMapProvider_cannot_remove_root_node)); } if (ownerProvider != this) { // Remove node from the owner provider. ownerProvider.RemoveNode(node); } base.RemoveNode(node); }
protected virtual void AddProvider(string providerName, SiteMapNode parentNode) { if (parentNode == null) { throw new ArgumentNullException("parentNode"); } if (parentNode.Provider != this) { throw new ArgumentException("The Provider property of the parentNode does not reference the current provider.", "parentNode"); } SiteMapProvider smp = SiteMap.Providers [providerName]; if (smp == null) { throw new ProviderException("Provider with name [" + providerName + "] was not found."); } AddNode(smp.GetRootNodeCore()); RegisterChildProvider(providerName, smp); }
private void EnsureChildSiteMapProviderUpToDate(SiteMapProvider childProvider) { SiteMapNode oldNode = (SiteMapNode)ChildProviderTable[childProvider]; SiteMapNode newNode = childProvider.GetRootNodeCore(); if (newNode == null) { throw new ProviderException(SR.GetString(SR.XmlSiteMapProvider_invalid_sitemapnode_returned, childProvider.Name)); } // child providers have been updated. if (!oldNode.Equals(newNode)) { // If the child provider table has been updated, simply return null. // This will happen when the current provider's sitemap file is changed or Clear() is called; if (oldNode == null) { return; } lock (_lock) { oldNode = (SiteMapNode)ChildProviderTable[childProvider]; // If the child provider table has been updated, simply return null. See above. if (oldNode == null) { return; } newNode = childProvider.GetRootNodeCore(); if (newNode == null) { throw new ProviderException(SR.GetString(SR.XmlSiteMapProvider_invalid_sitemapnode_returned, childProvider.Name)); } if (!oldNode.Equals(newNode)) { // If the current provider does not contain any nodes but one child provider // ie. _siteMapNode == oldNode // the oldNode needs to be removed from Url table and the new node will be added. if (_siteMapNode.Equals(oldNode)) { UrlTable.Remove(oldNode.Url); KeyTable.Remove(oldNode.Key); UrlTable.Add(newNode.Url, newNode); KeyTable.Add(newNode.Key, newNode); _siteMapNode = newNode; } // First find the parent node SiteMapNode parent = (SiteMapNode)ParentNodeTable[oldNode]; // parent is null when the provider does not contain any static nodes, ie. // it only contains definition to include one child provider. if (parent != null) { // Update the child nodes table SiteMapNodeCollection list = (SiteMapNodeCollection)ChildNodeCollectionTable[parent]; // Add the newNode to where the oldNode is within parent node's collection. int index = list.IndexOf(oldNode); if (index != -1) { list.Remove(oldNode); list.Insert(index, newNode); } else { list.Add(newNode); } // Update the parent table ParentNodeTable[newNode] = parent; ParentNodeTable.Remove(oldNode); // Update the Url table UrlTable.Remove(oldNode.Url); KeyTable.Remove(oldNode.Key); UrlTable.Add(newNode.Url, newNode); KeyTable.Add(newNode.Key, newNode); } else { // Notify the parent provider to update its child provider collection. XmlSiteMapProvider provider = ParentProvider as XmlSiteMapProvider; if (provider != null) { provider.EnsureChildSiteMapProviderUpToDate(this); } } // Update provider nodes; ChildProviderTable[childProvider] = newNode; _childProviderList = null; } } } }
protected static SiteMapNode GetRootNodeCoreFromProvider(SiteMapProvider provider) { return(provider.GetRootNodeCore()); }
void BuildSiteMapRecursive(XmlNode xmlNode, SiteMapNode parent) { if (xmlNode.Name != "siteMapNode") { throw new ConfigurationException("incorrect element name", xmlNode); } string attrValue = GetNonEmptyOptionalAttribute(xmlNode, "provider"); if (attrValue != null) { SiteMapProvider provider = SiteMap.Providers [attrValue]; if (provider == null) { throw new ProviderException("Provider with name [" + attrValue + "] was not found."); } provider.ParentProvider = this; SiteMapNode providerRoot = provider.GetRootNodeCore(); if (parent == null) { root = providerRoot; } else { AddNodeNoCheck(providerRoot, parent); } return; } attrValue = GetNonEmptyOptionalAttribute(xmlNode, "siteMapFile"); if (attrValue != null) { var nvc = new NameValueCollection(); nvc.Add("siteMapFile", attrValue); string description = GetOptionalAttribute(xmlNode, "description"); if (!String.IsNullOrEmpty(description)) { nvc.Add("description", description); } string name = MapUrl(attrValue); var provider = new XmlSiteMapProvider(); provider.Initialize(name, nvc); SiteMapNode providerRoot = provider.GetRootNodeCore(); if (parent == null) { root = providerRoot; } else { AddNodeNoCheck(providerRoot, parent); } return; } SiteMapNode curNode = ConvertToSiteMapNode(xmlNode); if (parent == null) { root = curNode; } else { AddNodeNoCheck(curNode, parent); } XmlNodeList childNodes = xmlNode.ChildNodes; if (childNodes == null || childNodes.Count < 1) { return; } foreach (XmlNode child in childNodes) { if (child.NodeType != XmlNodeType.Element) { continue; } BuildSiteMapRecursive(child, curNode); } }
protected static SiteMapNode GetRootNodeCoreFromProvider (SiteMapProvider provider) { return provider.GetRootNodeCore (); }
private void EnsureChildSiteMapProviderUpToDate(SiteMapProvider childProvider) { SiteMapNode node = (SiteMapNode)this.ChildProviderTable[childProvider]; SiteMapNode rootNodeCore = childProvider.GetRootNodeCore(); if (rootNodeCore == null) { throw new ProviderException(System.Web.SR.GetString("XmlSiteMapProvider_invalid_sitemapnode_returned", new object[] { childProvider.Name })); } if (!node.Equals(rootNodeCore) && (node != null)) { lock (base._lock) { node = (SiteMapNode)this.ChildProviderTable[childProvider]; if (node != null) { rootNodeCore = childProvider.GetRootNodeCore(); if (rootNodeCore == null) { throw new ProviderException(System.Web.SR.GetString("XmlSiteMapProvider_invalid_sitemapnode_returned", new object[] { childProvider.Name })); } if (!node.Equals(rootNodeCore)) { if (this._siteMapNode.Equals(node)) { base.UrlTable.Remove(node.Url); base.KeyTable.Remove(node.Key); base.UrlTable.Add(rootNodeCore.Url, rootNodeCore); base.KeyTable.Add(rootNodeCore.Key, rootNodeCore); this._siteMapNode = rootNodeCore; } SiteMapNode node3 = (SiteMapNode)base.ParentNodeTable[node]; if (node3 != null) { SiteMapNodeCollection nodes = (SiteMapNodeCollection)base.ChildNodeCollectionTable[node3]; int index = nodes.IndexOf(node); if (index != -1) { nodes.Remove(node); nodes.Insert(index, rootNodeCore); } else { nodes.Add(rootNodeCore); } base.ParentNodeTable[rootNodeCore] = node3; base.ParentNodeTable.Remove(node); base.UrlTable.Remove(node.Url); base.KeyTable.Remove(node.Key); base.UrlTable.Add(rootNodeCore.Url, rootNodeCore); base.KeyTable.Add(rootNodeCore.Key, rootNodeCore); } else { XmlSiteMapProvider parentProvider = this.ParentProvider as XmlSiteMapProvider; if (parentProvider != null) { parentProvider.EnsureChildSiteMapProviderUpToDate(this); } } this.ChildProviderTable[childProvider] = rootNodeCore; this._childProviderList = null; } } } } }
private void EnsureChildSiteMapProviderUpToDate(SiteMapProvider childProvider) { SiteMapNode node = (SiteMapNode) this.ChildProviderTable[childProvider]; SiteMapNode rootNodeCore = childProvider.GetRootNodeCore(); if (rootNodeCore == null) { throw new ProviderException(System.Web.SR.GetString("XmlSiteMapProvider_invalid_sitemapnode_returned", new object[] { childProvider.Name })); } if (!node.Equals(rootNodeCore) && (node != null)) { lock (base._lock) { node = (SiteMapNode) this.ChildProviderTable[childProvider]; if (node != null) { rootNodeCore = childProvider.GetRootNodeCore(); if (rootNodeCore == null) { throw new ProviderException(System.Web.SR.GetString("XmlSiteMapProvider_invalid_sitemapnode_returned", new object[] { childProvider.Name })); } if (!node.Equals(rootNodeCore)) { if (this._siteMapNode.Equals(node)) { base.UrlTable.Remove(node.Url); base.KeyTable.Remove(node.Key); base.UrlTable.Add(rootNodeCore.Url, rootNodeCore); base.KeyTable.Add(rootNodeCore.Key, rootNodeCore); this._siteMapNode = rootNodeCore; } SiteMapNode node3 = (SiteMapNode) base.ParentNodeTable[node]; if (node3 != null) { SiteMapNodeCollection nodes = (SiteMapNodeCollection) base.ChildNodeCollectionTable[node3]; int index = nodes.IndexOf(node); if (index != -1) { nodes.Remove(node); nodes.Insert(index, rootNodeCore); } else { nodes.Add(rootNodeCore); } base.ParentNodeTable[rootNodeCore] = node3; base.ParentNodeTable.Remove(node); base.UrlTable.Remove(node.Url); base.KeyTable.Remove(node.Key); base.UrlTable.Add(rootNodeCore.Url, rootNodeCore); base.KeyTable.Add(rootNodeCore.Key, rootNodeCore); } else { XmlSiteMapProvider parentProvider = this.ParentProvider as XmlSiteMapProvider; if (parentProvider != null) { parentProvider.EnsureChildSiteMapProviderUpToDate(this); } } this.ChildProviderTable[childProvider] = rootNodeCore; this._childProviderList = null; } } } } }