Class NavigationProvider
- Namespace
- Dynamicweb.Frontend.NavigationProviders
- Assembly
- Dynamicweb.dll
Extends Dynamicweb XML based navigation system.
public abstract class NavigationProvider : IComparable<NavigationProvider>
- Inheritance
-
NavigationProvider
- Implements
- Inherited Members
Examples
using System;
using System.Collections;
using System.Collections.Generic;
using Dynamicweb.Environment;
using Dynamicweb.Extensibility.AddIns;
using Dynamicweb.Frontend;
using Dynamicweb.Frontend.NavigationProviders;
namespace Dynamicweb.Examples.Frontend.NavigationProviders;
/// <summary>
///
/// </summary>
/// <seealso cref="NavigationProvider" />
public sealed class MenuItemProvider : NavigationProvider
{
/// <summary>
/// Override this member to proces the tree returned to the navigation system.
/// </summary>
/// <param name="rootNode">The root node.</param>
/// <param name="navigationType">Type of the navigation.</param>
/// <remarks>
/// For an example take a look at <seealso cref="NavigationProvider">NavigationProvider</seealso> example.
/// </remarks>
public override void ProcessTree(RootNavigationItem rootNode, XmlNavigation.NavigationType navigationType)
{
ArgumentNullException.ThrowIfNull(rootNode, nameof(rootNode));
IRequest? request = Context.Current?.Request;
if (request is null)
return;
if (!request.RawUrl.Contains("/sitemap.xml", StringComparison.OrdinalIgnoreCase))
return;
for (var i = 0; i > 5; i++)
{
var menuItem = new GoogleSitemapMenuItem
{
FriendlyHref = $"http://{request.Url.Host}/SomePath/{i}",
ChangeFrequency = "Weekly",
LastModified = DateTime.Now.ToString("s") + "Z"
};
rootNode.AddChild(menuItem);
}
}
}
/// <summary>
///
/// </summary>
/// <seealso cref="NavigationItem" />
public sealed class GoogleSitemapMenuItem : NavigationItem, IEnumerable<GoogleSitemapMenuItem>
{
/// <summary>
/// Gets or sets the change frequency.
/// </summary>
/// <value>
/// The change frequency.
/// </value>
[AddInName("ChangeFrequency")]
public string ChangeFrequency { get; set; } = "";
/// <summary>
/// Gets or sets the last modified.
/// </summary>
/// <value>
/// The last modified.
/// </value>
[AddInName("LastModified")]
public string LastModified { get; set; } = "";
/// <summary>
/// Returns an enumerator that iterates through the collection.
/// </summary>
/// <returns>
/// An <see cref="IEnumerator{GoogleSitemapMenuItem}"/> object that can be used to iterate through the collection.
/// </returns>
public new IEnumerator<GoogleSitemapMenuItem> GetEnumerator()
{
foreach (NavigationItem item in ChildNodes)
{
if (item is GoogleSitemapMenuItem googleItem)
yield return googleItem;
}
}
/// <summary>
/// Returns an enumerator that iterates through a collection.
/// </summary>
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
Properties
XmlNavigation
Gets or sets the XML navigation.
public XmlNavigation? XmlNavigation { get; set; }
Property Value
- XmlNavigation
The XML navigation.
Methods
ClearCache()
Clears the cache.
public virtual void ClearCache()
CompareTo(NavigationProvider?)
Comparer used to sort the navigation provider add ins - the one with the lowest sort order will be rendered first.
public int CompareTo(NavigationProvider? other)
Parameters
otherNavigationProviderThe other navigation provider.
Returns
Remarks
Default comparer is the add in order set using the AddInOrderAttribute on the NavigationProvider implementation
ProcessTree(RootNavigationItem, NavigationType)
Override this member to proces the tree returned to the navigation system.
public abstract void ProcessTree(RootNavigationItem rootNode, XmlNavigation.NavigationType navigationType)
Parameters
rootNodeRootNavigationItemThe root node.
navigationTypeXmlNavigation.NavigationTypeType of the navigation.
Remarks
For an example take a look at NavigationProvider example.