Skip to content

Instantly share code, notes, and snippets.

Created February 27, 2013 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5047048 to your computer and use it in GitHub Desktop.
Save anonymous/5047048 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0"
xsi:schemaLocation="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0 MvcSiteMapSchema.xsd"
enableLocalization="true">
<mvcSiteMapNode title="Home" controller="Home" action="Index">
<mvcSiteMapNode title="Pages" action="Index" dynamicNodeProvider="Adfero.Kermit.Framework.Web.Utilities.SitemapProviders.LandingPageDynamicNodeProvider, Adfero.Kermit.Framework.Web" />
<mvcSiteMapNode title="Articles" action="Details" dynamicNodeProvider="Adfero.Kermit.Framework.Web.Utilities.SitemapProviders.SectionArticleDetailsDynamicNodeProvider, Adfero.Kermit.Framework.Web" />
<mvcSiteMapNode title="Sections" action="Index" dynamicNodeProvider="Adfero.Kermit.Framework.Web.Utilities.SitemapProviders.SectionsDynamicNodeProvider, Adfero.Kermit.Framework.Web" />
</mvcSiteMapNode>
</mvcSiteMap>
public class SectionsDynamicNodeProvider : IDynamicNodeProvider
{
public IEnumerable<DynamicNode> GetDynamicNodeCollection()
{
// Build value
var returnValue = new List<DynamicNode>();
// Create a node for each section
var kernel = DependencyResolver.Current;
var sectionsClient = kernel.GetService<ISectionDataService>();
foreach (var section in sectionsClient.List())
{
DynamicNode node = new DynamicNode
{
Title = section.Name,
Route = section.UrlSlug,
Controller = "Listing",
Action = "Index",
Key = section.UrlSlug
};
returnValue.Add(node);
}
return returnValue;
}
public CacheDescription GetCacheDescription()
{
return new CacheDescription("SectionsDynamicNodeProvider")
{
AbsoluteExpiration = DateTime.Now.AddMinutes(15)
};
}
}
public class SectionArticleDetailsDynamicNodeProvider : IDynamicNodeProvider
{
public IEnumerable<DynamicNode> GetDynamicNodeCollection()
{
// Build value
var returnValue = new List<DynamicNode>();
// Create a node for each article
var kernel = DependencyResolver.Current;
var articlesClient = kernel.GetService<IArticlePageService>();
var sectionsClient = kernel.GetService<ISectionDataService>();
var sections = sectionsClient.List();
foreach (var section in sections)
{
foreach (var article in articlesClient.Search(0, 100, section.UrlSlug, ).Items)
{
DynamicNode node = new DynamicNode
{
LastModifiedDate = article.PublishedDate,
Title = article.Title,
Route = string.Format("{0}_item", article.Section.UrlSlug),
Controller = "Listing",
Action = "Details"
};
node.RouteValues.Add("urlSlug", article.Section.UrlSlug);
node.RouteValues.Add("id", article.UrlSlug.Replace(article.Section.UrlSlug, ""));
node.Key = article.UrlSlug;
node.ParentKey = article.Section.UrlSlug;
returnValue.Add(node);
}
}
return returnValue;
}
public CacheDescription GetCacheDescription()
{
return new CacheDescription("SectionArticleDetailsDynamicNodeProvider")
{
AbsoluteExpiration = DateTime.Now.AddMinutes(15)
};
}
}
public class PageDynamicNodeProvider : IDynamicNodeProvider
{
public IEnumerable<DynamicNode> GetDynamicNodeCollection()
{
// Build value
var returnValue = new List<DynamicNode>();
// Create a node for each landing page
var kernel = DependencyResolver.Current;
var pagesClient = kernel.GetService<IPageDataService>();
foreach (var page in pagesClient.List())
{
DynamicNode node = new DynamicNode
{
Route = page.Name,
Title = page.Name,
Controller = "Pages",
Action = "Index",
Key = page.UrlSlug
};
returnValue.Add(node);
}
return returnValue;
}
public CacheDescription GetCacheDescription()
{
return new CacheDescription("PageDynamicNodeProvider")
{
AbsoluteExpiration = DateTime.Now.AddHours(5)
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment