/// <summary> /// Initialize a new instance of <see cref="SeoSiteMapBuilderService"/>. /// </summary> public SeoSiteMapBuilderService() { _rooturl = new SeoUrlInfo("_ROOT_"); _keyIndex = new Dictionary<string, SeoUrlInfo>(); _childurls = new Dictionary<string, List<SeoUrlInfo>>(); _urlPreferredOrder = new Dictionary<string, int>(); _childurls.Add(_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) { SafeAddurl(url); if (!_childurls.ContainsKey(parent.Key)) { _childurls.Add(parent.Key, new List<SeoUrlInfo>()); } 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) { 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) { SafeAddurl(url); AddurlWithOrder(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) { AddUrl(url, int.MaxValue); //_childurls[Rooturl.Key].Add(url); }
private void AddChildurls(XmlWriter writer, SeoUrlInfo parent, ReadOnlyCollection<SeoUrlInfo> children) { if (children.Count > 0) { foreach (var info in children) { WriteSiteMapurlEntry(writer, info); AddChildurls(writer, info, 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(); }
private void AddurlWithOrder(string parentKey, SeoUrlInfo url, int preferredDisplayOrder) { _urlPreferredOrder.Add(url.Key, preferredDisplayOrder); for (int i = 0; i < _childurls[parentKey].Count; i++) { string key = _childurls[parentKey][i].Key; if (_urlPreferredOrder[key] > preferredDisplayOrder) { _childurls[parentKey].Insert(i, url); return; } } _childurls[parentKey].Add(url); }
private void SafeAddurl(SeoUrlInfo url) { Guard.IsNotNull(url, "url"); if (_keyIndex.ContainsKey(url.Key)) { throw new Exception(""); } _keyIndex.Add(url.Key, url); }