Exemplo n.º 1
0
        /// <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>());
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        private void SafeAddurl(SeoUrlInfo url)
        {
            Guard.IsNotNull(url, "url");

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

            this._keyIndex.Add(url.Key, url);
        }
Exemplo n.º 4
0
 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));
         }
     }
 }
Exemplo n.º 5
0
 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();
 }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        public string SeoXml()
        {
            // instantiate the XML Text Writer for writing the SiteMap document
            using (StringWriter stringWriter = new StringWriter())
            {
                using (XmlTextWriter writer = new XmlTextWriter(stringWriter))
                {
                    // write out the header
                    // start off the site map
                    writer.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");
                    writer.WriteStartElement("urlset");
                    writer.WriteAttributeString("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
                    writer.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
                    writer.WriteAttributeString("xsi:schemaLocation", "http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd");

                    SeoUrlInfo rooturl = this.RootUrl;
                    this.AddChildurls(writer, rooturl, this.GetChildren(rooturl.Key));

                    // write the footer and close.
                    writer.WriteEndElement();
                    return(stringWriter.ToString());
                }
            }
        }
Exemplo n.º 8
0
 /// <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);
 }
Exemplo n.º 9
0
 /// <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);
 }
Exemplo n.º 10
0
        /// <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);
        }