Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for building a sitemap using a fluent api. #259

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using System;
// uncomment this to demonstrace the fluent api demo using StoreFluentSiteMapProvider
//#define FluentDemo
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Web.Hosting;
using System.Web.Mvc;
using MvcMusicStore.Code;
using MvcSiteMapProvider;
using MvcSiteMapProvider.Builder;
using MvcSiteMapProvider.Caching;
Expand Down Expand Up @@ -63,7 +66,11 @@ public static void SetUp(Container container)

// Added 2013-11-11 by NightOwl888 for SimpleInjector.Verify method:
typeof(SiteMapNodeCreator),
typeof(DynamicSiteMapNodeBuilder)
typeof(DynamicSiteMapNodeBuilder),

// Added 2013-12-26 by theonlylawislove for fluent sitemapnode building
typeof(FluentSiteMapNodeBuilder),
typeof(FluentSiteMapNodeFactory)
};
var multipleImplementationTypes = new Type[]
{
Expand Down Expand Up @@ -139,14 +146,23 @@ public static void SetUp(Container container)


// Register the sitemap node providers
#if !FluentDemo
container.RegisterSingle<XmlSiteMapNodeProvider>(() => container.GetInstance<XmlSiteMapNodeProviderFactory>()
.Create(container.GetInstance<IXmlSource>()));
#else
container.RegisterSingle<StoreFluentSiteMapProvider>();
#endif
container.RegisterSingle<ReflectionSiteMapNodeProvider>(() => container.GetInstance<ReflectionSiteMapNodeProviderFactory>()
.Create(includeAssembliesForScan));

// Register the sitemap builders
#if !FluentDemo
container.RegisterSingle<ISiteMapBuilder>(() => container.GetInstance<SiteMapBuilderFactory>()
.Create(new CompositeSiteMapNodeProvider(container.GetInstance<XmlSiteMapNodeProvider>(), container.GetInstance<ReflectionSiteMapNodeProvider>())));
#else
container.RegisterSingle<ISiteMapBuilder>(() => container.GetInstance<SiteMapBuilderFactory>()
.Create(new CompositeSiteMapNodeProvider(container.GetInstance<StoreFluentSiteMapProvider>(), container.GetInstance<ReflectionSiteMapNodeProvider>())));
#endif

container.RegisterAll<ISiteMapBuilderSet>(ResolveISiteMapBuilderSets(container, securityTrimmingEnabled, enableLocalization));
container.RegisterSingle<ISiteMapBuilderSetStrategy>(() => new SiteMapBuilderSetStrategy(container.GetAllInstances<ISiteMapBuilderSet>().ToArray()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcSiteMapProvider;
using MvcSiteMapProvider.Builder;

namespace MvcMusicStore.Code
{
/// <summary>
/// This is an example FluentSiteMapNodeProvider that is a mirror of the ~/Mvc.sitemap.
/// </summary>
public class StoreFluentSiteMapProvider : FluentSiteMapNodeProvider
{
public StoreFluentSiteMapProvider(IFluentFactory fluentFactory)
: base(fluentFactory)
{

}

public override void BuildSitemapNodes(IFluentSiteMapNodeFactory fluentSiteMapNodeFactory)
{
fluentSiteMapNodeFactory.Add()
.Title("$resources:SiteMapLocalizations,HomeTitle")
.Description("This is the home page")
.Controller("Home")
.Action("Index")
.ChangeFrequency(ChangeFrequency.Always)
.UpdatePriority(UpdatePriority.Normal)
.LastModifiedDate(DateTime.Parse("2002-05-30T09:00:00"))
.Items(homeChildren =>
{
homeChildren.Add()
.Title("$resources:SiteMapLocalizations,BrowseGenresTitle")
.Controller("Store")
.Action("Index")
.Items(genresChildren => genresChildren.Add()
.Title("Browse")
.Action("Browse")
.DynamicNodeProvider("MvcMusicStore.Code.StoreBrowseDynamicNodeProvider, Mvc Music Store")
.PreservedRouteValues(new[] { "browse" })
.Items(browseChildren => browseChildren.Add()
.Title("Details")
.Action("Details")
.DynamicNodeProvider("MvcMusicStore.Code.StoreDetailsDynamicNodeProvider, Mvc Music Store")));
homeChildren.Add()
.Title("$resources:SiteMapLocalizations,ReviewCartTitle")
.Controller("ShoppingCart")
.Action("Index");
homeChildren.Add()
.Key("Checkout")
.Title("$resources:SiteMapLocalizations,CheckoutTitle")
.Controller("Checkout")
.Clickable(false);
homeChildren.Add()
.Title("$resources:SiteMapLocalizations,AccountTitle")
.Controller("Account")
.Clickable(false)
.Items(accountChildren =>
{
accountChildren.Add()
.Title("$resources:SiteMapLocalizations,LogOnTitle")
.Action("LogOn")
.VisibilityProvider("MvcMusicStore.Code.NonAuthenticatedVisibilityProvider, Mvc Music Store");
accountChildren.Add()
.Title("$resources:SiteMapLocalizations,LogOffTitle")
.Action("LogOff")
.VisibilityProvider("MvcMusicStore.Code.AuthenticatedVisibilityProvider, Mvc Music Store");
accountChildren.Add()
.Title("$resources:SiteMapLocalizations,RegisterTitle")
.Action("Register")
.VisibilityProvider("MvcMusicStore.Code.NonAuthenticatedVisibilityProvider, Mvc Music Store");
accountChildren.Add()
.Title("$resources:SiteMapLocalizations,ChangePasswordTitle")
.Action("ChangePassword")
.VisibilityProvider("MvcMusicStore.Code.AuthenticatedVisibilityProvider, Mvc Music Store");
});
homeChildren.Add()
.Title("$resources:SiteMapLocalizations,AdministrationTitle")
.Area("Admin")
.Controller("Home")
.Action("Index")
.Attribute("visibility", "SiteMapPathHelper,!*")
.VisibilityProvider("MvcSiteMapProvider.FilteredSiteMapNodeVisibilityProvider, MvcSiteMapProvider")
.Items(administrationChildren => administrationChildren.Add()
.Title("$resources:SiteMapLocalizations,StoreManagerTitle")
.Area("Admin")
.Controller("StoreManager")
.Action("Index")
.Items(storeManagerChildren =>
{
storeManagerChildren.Add()
.Title("$resources:SiteMapLocalizations,CreateAlbumTitle")
.Action("Create");
storeManagerChildren.Add()
.Title("$resources:SiteMapLocalizations,EditAlbumTitle")
.Action("Edit");
storeManagerChildren.Add()
.Title("$resources:SiteMapLocalizations,DeleteAlbumTitle")
.Action("Delete");
}));
homeChildren.Add()
.Title("$resources:SiteMapLocalizations,SitemapTitle")
.Action("SiteMap")
.UrlResolver("MvcMusicStore.Code.UpperCaseSiteMapNodeUrlResolver, Mvc Music Store");
});
}

public override bool UseNestedDynamicNodeRecursion
{
get { return true; }
}
}
}
1 change: 1 addition & 0 deletions src/MvcSiteMapProvider/MvcMusicStore/MvcMusicStore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ configured in the compilation constants -->
<Compile Include="Code\NonAuthenticatedVisibilityProvider.cs" />
<Compile Include="Code\StoreBrowseDynamicNodeProvider.cs" />
<Compile Include="Code\StoreDetailsDynamicNodeProvider.cs" />
<Compile Include="Code\StoreFluentSiteMapProvider.cs" />
<Compile Include="Code\UpperCaseSiteMapNodeUrlResolver.cs" />
<Compile Include="Controllers\AccountController.cs" />
<Compile Include="Controllers\CheckoutController.cs" />
Expand Down
36 changes: 36 additions & 0 deletions src/MvcSiteMapProvider/MvcSiteMapProvider/Builder/FluentFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvcSiteMapProvider.Linq;

namespace MvcSiteMapProvider.Builder
{
/// <summary>
/// The default implementation of IFluentFactory
/// </summary>
public class FluentFactory
: IFluentFactory
{
/// <summary>
/// Create a IFluentSiteMapNodeFactory.
/// </summary>
/// <param name="result">This should an existing collection. All nodes created using Add() will be added to this collection.</param>
/// <param name="siteMapNodeHelper">The ISiteMapNodeHelper that will internally create the ISiteMapNodes</param>
/// <returns></returns>
public IFluentSiteMapNodeFactory CreateSiteMapNodeFactory(IList<IFluentSiteMapNodeBuilder> result, ISiteMapNodeHelper siteMapNodeHelper)
{
return new FluentSiteMapNodeFactory(this, result, siteMapNodeHelper);
}

/// <summary>
/// Create a IFluentSiteMapNodeBuilder.
/// </summary>
/// <param name="siteMapNodeHelper">The site map node helper.</param>
/// <returns></returns>
public IFluentSiteMapNodeBuilder CreateSiteMapNodeBuilder(ISiteMapNodeHelper siteMapNodeHelper)
{
return new FluentSiteMapNodeBuilder(this, siteMapNodeHelper);
}
}
}
Loading