/// <summary>
        /// Initialize a new instance of <see cref="SeoSiteMapBuilderService"/>.
        /// </summary>
        public SeoSiteMapBuilderService()
        {
            this._rooturl = new SeoUrlInfo("_ROOT_");
            this._keyIndex = new Dictionary<string, SeoUrlInfo>();
            this._childurls = new Dictionary<string, List<SeoUrlInfo>>();
            this._urlPreferredOrder = new Dictionary<string, int>();

            this._childurls.Add(this._rooturl.Key, new List<SeoUrlInfo>());
        }
        /// <summary>
        /// Adds a url as a child of another url, and sets the order with which to display the url.
        /// </summary>
        /// <param name="url">The url to add.</param>
        /// <param name="parent">The url under which to add the new url.</param>
        /// <param name="preferredDisplayOrder">The url display order.</param>
        public void AddUrl(SeoUrlInfo url, SeoUrlInfo parent, int preferredDisplayOrder)
        {
            this.SafeAddurl(url);

            if (!this._childurls.ContainsKey(parent.Key))
            {
                this._childurls.Add(parent.Key, new List<SeoUrlInfo>());
            }

            this.AddurlWithOrder(parent.Key, url, preferredDisplayOrder);
        }
 /// <summary>
 /// Adds a url as a child of another url.
 /// </summary>
 /// <param name="url">The url to add.</param>
 /// <param name="parent">The url under which to add the new url.</param>
 public void AddUrl(SeoUrlInfo url, SeoUrlInfo parent)
 {
     this.AddUrl(url, parent, int.MaxValue);
 }
 /// <summary>
 /// Adds a url as a child of the root url and sets the order with which the url should be displayed.
 /// </summary>
 /// <param name="url">The url to add.</param>
 /// <param name="preferredDisplayOrder">The url display order.</param>
 public void AddUrl(SeoUrlInfo url, int preferredDisplayOrder)
 {
     this.SafeAddurl(url);
     this.AddurlWithOrder(this.RootUrl.Key, url, preferredDisplayOrder);
 }
        /// <summary>
        /// Adds a url as child of the root url.
        /// </summary>
        /// <param name="url">The url to add.</param>
        public void AddUrl(SeoUrlInfo url)
        {
            this.AddUrl(url, int.MaxValue);

            // this._childurls[Rooturl.Key].Add(url);
        }
        private void SafeAddurl(SeoUrlInfo url)
        {
            Guard.IsNotNull(url, "url");

            if (this._keyIndex.ContainsKey(url.Key))
            {
                throw new Exception("");
            }

            this._keyIndex.Add(url.Key, url);
        }
        private void AddurlWithOrder(string parentKey, SeoUrlInfo url, int preferredDisplayOrder)
        {
            this._urlPreferredOrder.Add(url.Key, preferredDisplayOrder);
            for (int i = 0; i < this._childurls[parentKey].Count; i++)
            {
                string key = this._childurls[parentKey][i].Key;
                if (this._urlPreferredOrder[key] > preferredDisplayOrder)
                {
                    this._childurls[parentKey].Insert(i, url);
                    return;
                }
            }

            this._childurls[parentKey].Add(url);
        }
 private void AddChildurls(XmlWriter writer, SeoUrlInfo parent, ReadOnlyCollection<SeoUrlInfo> children)
 {
     if (children.Count > 0)
     {
         foreach (SeoUrlInfo info in children)
         {
             WriteSiteMapurlEntry(writer, info);
             this.AddChildurls(writer, info, this.GetChildren(info.Key));
         }
     }
 }
 internal static void WriteSiteMapurlEntry(XmlWriter writer, SeoUrlInfo url)
 {
     writer.WriteStartElement("url");
     byte[] locBytes;
     locBytes = Encoding.UTF8.GetBytes(url.Url);
     writer.WriteElementString("loc", Encoding.UTF8.GetString(locBytes));
     writer.WriteElementString("lastmod", FormatISODate(DateTime.Today));
     writer.WriteElementString("changefreq", url.ChangeFrequency);
     writer.WriteElementString("priority", url.Priority);
     writer.WriteEndElement();
 }