Exemple #1
0
 protected virtual void AddNodeInternal(ISiteMapNode node, ISiteMapNode parentNode)
 {
     if (node == null)
     {
         throw new ArgumentNullException("node");
     }
     lock (this.synclock)
     {
         bool   urlPrepared = false;
         bool   urlEncoded  = false;
         string url         = node.Url;
         if (!string.IsNullOrEmpty(url))
         {
             if (node.HasAbsoluteUrl())
             {
                 // This is an external url, so we will encode it
                 url        = urlPath.UrlEncode(url);
                 urlEncoded = true;
             }
             if (urlPath.AppDomainAppVirtualPath != null)
             {
                 if (!urlPath.IsAbsolutePhysicalPath(url))
                 {
                     url = urlPath.MakeVirtualPathAppAbsolute(urlPath.Combine(urlPath.AppDomainAppVirtualPath, url));
                 }
                 if (this.urlTable.ContainsKey(url))
                 {
                     if (urlEncoded)
                     {
                         url = urlPath.UrlDecode(url);
                     }
                     throw new InvalidOperationException(String.Format(Resources.Messages.MultipleNodesWithIdenticalUrl, url));
                 }
             }
             urlPrepared = true;
         }
         string key = node.Key;
         if (this.keyTable.ContainsKey(key))
         {
             throw new InvalidOperationException(String.Format(Resources.Messages.MultipleNodesWithIdenticalKey, key));
         }
         this.keyTable[key] = node;
         if (urlPrepared)
         {
             this.urlTable[url] = node;
         }
         if (parentNode != null)
         {
             this.parentNodeTable[node] = parentNode;
             if (!this.childNodeCollectionTable.ContainsKey(parentNode))
             {
                 this.childNodeCollectionTable[parentNode] = siteMapChildStateFactory.CreateLockableSiteMapNodeCollection(this);
             }
             this.childNodeCollectionTable[parentNode].Add(node);
         }
     }
 }
Exemple #2
0
        protected virtual void AddNodeInternal(ISiteMapNode node, ISiteMapNode parentNode)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            lock (this.synclock)
            {
                IUrlKey url      = null;
                bool    isMvcUrl = string.IsNullOrEmpty(node.UnresolvedUrl) && this.UsesDefaultUrlResolver(node);

                // Only store URLs if they are clickable and are configured using the Url
                // property or provided by a custom URL resolver.
                if (!isMvcUrl && node.Clickable)
                {
                    url = this.siteMapChildStateFactory.CreateUrlKey(node);

                    // Check for duplicates (including matching or empty host names).
                    if (this.urlTable
                        .Where(k => string.Equals(k.Key.RootRelativeUrl, url.RootRelativeUrl, StringComparison.OrdinalIgnoreCase))
                        .Where(k => string.IsNullOrEmpty(k.Key.HostName) || string.IsNullOrEmpty(url.HostName) || string.Equals(k.Key.HostName, url.HostName, StringComparison.OrdinalIgnoreCase))
                        .Count() > 0)
                    {
                        var absoluteUrl = this.urlPath.ResolveUrl(node.UnresolvedUrl, string.IsNullOrEmpty(node.Protocol) ? Uri.UriSchemeHttp : node.Protocol, node.HostName);
                        throw new InvalidOperationException(string.Format(Resources.Messages.MultipleNodesWithIdenticalUrl, absoluteUrl));
                    }
                }

                // Add the key
                string key = node.Key;
                if (this.keyTable.ContainsKey(key))
                {
                    throw new InvalidOperationException(string.Format(Resources.Messages.MultipleNodesWithIdenticalKey, key));
                }
                this.keyTable[key] = node;

                // Add the URL
                if (url != null)
                {
                    this.urlTable[url] = node;
                }

                // Add the parent-child relationship
                if (parentNode != null)
                {
                    this.parentNodeTable[node] = parentNode;
                    if (!this.childNodeCollectionTable.ContainsKey(parentNode))
                    {
                        this.childNodeCollectionTable[parentNode] = siteMapChildStateFactory.CreateLockableSiteMapNodeCollection(this);
                    }
                    this.childNodeCollectionTable[parentNode].Add(node);
                }
            }
        }