diff --git a/src/Orchard.Web/Modules/Orchard.Alias/AdminMenu.cs b/src/Orchard.Web/Modules/Orchard.Alias/AdminMenu.cs index 5d524b196..77d3c61bf 100644 --- a/src/Orchard.Web/Modules/Orchard.Alias/AdminMenu.cs +++ b/src/Orchard.Web/Modules/Orchard.Alias/AdminMenu.cs @@ -3,19 +3,21 @@ using Orchard.Localization; using Orchard.Security; using Orchard.UI.Navigation; -namespace Orchard.Alias -{ +namespace Orchard.Alias { [OrchardFeature("Orchard.Alias.UI")] - public class AdminMenu : INavigationProvider - { + public class AdminMenu : INavigationProvider { public Localizer T { get; set; } public string MenuName { get { return "admin"; } } - public void GetNavigation(NavigationBuilder builder) - { - builder - .Add(T("Aliases"), "4", item => item.Action("Index", "Admin", new { area = "Orchard.Alias" }).Permission(StandardPermissions.SiteOwner)); + public void GetNavigation(NavigationBuilder builder) { + builder.AddImageSet("aliases"); + builder.Add(T("Aliases"), "1.4.1", menu => { + menu.LinkToFirstChild(true); + + menu.Add(T("Unmanaged"), "1", item => item.Action("IndexUnmanaged", "Admin", new { area = "Orchard.Alias" }).Permission(StandardPermissions.SiteOwner).LocalNav()); + menu.Add(T("Managed"), "2", item => item.Action("IndexManaged", "Admin", new { area = "Orchard.Alias" }).Permission(StandardPermissions.SiteOwner).LocalNav()); + }); } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Alias/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.Alias/Controllers/AdminController.cs index 79669da3f..500f49dcf 100644 --- a/src/Orchard.Web/Modules/Orchard.Alias/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Alias/Controllers/AdminController.cs @@ -35,7 +35,7 @@ namespace Orchard.Alias.Controllers { public Localizer T { get; set; } public ILogger Logger { get; set; } - public ActionResult Index(AdminIndexOptions options, PagerParameters pagerParameters) { + public ActionResult IndexUnmanaged(AdminIndexOptions options, PagerParameters pagerParameters) { if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage aliases"))) return new HttpUnauthorizedResult(); @@ -45,22 +45,13 @@ namespace Orchard.Alias.Controllers { if (options == null) options = new AdminIndexOptions(); - switch (options.Filter) { - case AliasFilter.All: - break; - default: - throw new ArgumentOutOfRangeException(); - } - - var aliases = _aliasHolder.GetMaps().SelectMany(x => x.GetAliases()); + var aliases = _aliasHolder.GetMaps().SelectMany(x => x.GetAliases()).Where(x => !x.IsManaged); if (!String.IsNullOrWhiteSpace(options.Search)) { var invariantSearch = options.Search.ToLowerInvariant(); aliases = aliases.Where(x => x.Path.ToLowerInvariant().Contains(invariantSearch)); } - aliases = aliases.ToList(); - var pagerShape = Services.New.Pager(pager).TotalItemCount(aliases.Count()); switch (options.Order) { @@ -84,7 +75,7 @@ namespace Orchard.Alias.Controllers { [HttpPost] [FormValueRequired("submit.BulkEdit")] - public ActionResult Index(FormCollection input) { + public ActionResult IndexUnmanaged(FormCollection input) { if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage aliases"))) return new HttpUnauthorizedResult(); @@ -105,8 +96,45 @@ namespace Orchard.Alias.Controllers { default: throw new ArgumentOutOfRangeException(); } + return RedirectToAction("IndexUnmanaged"); + } - return RedirectToAction("Index"); + public ActionResult IndexManaged(AdminIndexOptions options, PagerParameters pagerParameters) { + if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage aliases"))) + return new HttpUnauthorizedResult(); + + var pager = new Pager(Services.WorkContext.CurrentSite, pagerParameters); + + // default options + if (options == null) + options = new AdminIndexOptions(); + + var aliases = _aliasHolder.GetMaps().SelectMany(x => x.GetAliases()).Where(x => x.IsManaged); + + if (!String.IsNullOrWhiteSpace(options.Search)) { + var invariantSearch = options.Search.ToLowerInvariant(); + aliases = aliases.Where(x => x.Path.ToLowerInvariant().Contains(invariantSearch)); + } + + var pagerShape = Services.New.Pager(pager).TotalItemCount(aliases.Count()); + + switch (options.Order) { + case AliasOrder.Path: + aliases = aliases.OrderBy(x => x.Path); + break; + } + + if (pager.PageSize != 0) { + aliases = aliases.Skip(pager.GetStartIndex()).Take(pager.PageSize); + } + + var model = new AdminIndexViewModel { + Options = options, + Pager = pagerShape, + AliasEntries = aliases.Select(x => new AliasEntry() { Alias = x, IsChecked = false }).ToList() + }; + + return View(model); } public ActionResult Add() { @@ -140,9 +168,9 @@ namespace Orchard.Alias.Controllers { } try { - _aliasService.Set(aliasPath, routePath, "Custom"); + _aliasService.Set(aliasPath, routePath, "Custom", false); } - catch(Exception ex) { + catch (Exception ex) { Services.TransactionManager.Cancel(); Services.Notifier.Error(T("An error occured while creating the alias {0}: {1}. Please check the values are correct.", aliasPath, ex.Message)); Logger.Error(ex, T("An error occured while creating the alias {0}", aliasPath).Text); @@ -155,7 +183,7 @@ namespace Orchard.Alias.Controllers { Services.Notifier.Information(T("Alias {0} created", aliasPath)); - return RedirectToAction("Index"); + return RedirectToAction("IndexUnmanaged"); } public ActionResult Edit(string path) { @@ -204,10 +232,9 @@ namespace Orchard.Alias.Controllers { } try { - _aliasService.Set(aliasPath, routePath, "Custom"); + _aliasService.Set(aliasPath, routePath, "Custom", false); } - catch (Exception ex) - { + catch (Exception ex) { Services.TransactionManager.Cancel(); Services.Notifier.Error(T("An error occured while editing the alias '{0}': {1}. Please check the values are correct.", aliasPath, ex.Message)); Logger.Error(ex, T("An error occured while creating the alias '{0}'", aliasPath).Text); @@ -226,7 +253,7 @@ namespace Orchard.Alias.Controllers { Services.Notifier.Information(T("Alias {0} updated", path)); - return RedirectToAction("Index"); + return RedirectToAction("IndexUnmanaged"); } [HttpPost] @@ -242,11 +269,10 @@ namespace Orchard.Alias.Controllers { Services.Notifier.Information(T("Alias {0} deleted", path)); - return this.RedirectLocal(returnUrl, Url.Action("Index")); + return this.RedirectLocal(returnUrl, Url.Action("IndexUnmanaged")); } - private string GetExistingPathForAlias(string aliasPath) - { + private string GetExistingPathForAlias(string aliasPath) { var routeValues = _aliasService.Get(aliasPath.TrimStart('/', '\\')); if (routeValues == null) return null; @@ -255,8 +281,7 @@ namespace Orchard.Alias.Controllers { .FirstOrDefault(); } - private bool CheckAndWarnIfAliasExists(string aliasPath) - { + private bool CheckAndWarnIfAliasExists(string aliasPath) { var routePath = GetExistingPathForAlias(aliasPath); if (routePath == null) return false; @@ -267,8 +292,8 @@ namespace Orchard.Alias.Controllers { var changeLink = T("change", editUrl); var deleteLink = T("delete", deleteUrl); - Services.Notifier.Error(T("Cannot save alias {0}. It conflicts with existing one pointing to {1}. Please {2} or {3} the existing alias first.", - aliasPath, + Services.Notifier.Error(T("Cannot save alias {0}. It conflicts with existing one pointing to {1}. Please {2} or {3} the existing alias first.", + aliasPath, routePathLink, changeLink, deleteLink)); diff --git a/src/Orchard.Web/Modules/Orchard.Alias/IAliasService.cs b/src/Orchard.Web/Modules/Orchard.Alias/IAliasService.cs index 6eb151cf2..0f433eac6 100644 --- a/src/Orchard.Web/Modules/Orchard.Alias/IAliasService.cs +++ b/src/Orchard.Web/Modules/Orchard.Alias/IAliasService.cs @@ -5,8 +5,8 @@ using System.Web.Routing; namespace Orchard.Alias { public interface IAliasService : IDependency { RouteValueDictionary Get(string aliasPath); - void Set(string aliasPath, RouteValueDictionary routeValues, string aliasSource); - void Set(string aliasPath, string routePath, string aliasSource); + void Set(string aliasPath, RouteValueDictionary routeValues, string aliasSource, bool isManaged = false); + void Set(string aliasPath, string routePath, string aliasSource, bool isManaged = false); void Delete(string aliasPath); void Delete(string aliasPath, string aliasSource); /// @@ -18,8 +18,8 @@ namespace Orchard.Alias { IEnumerable Lookup(RouteValueDictionary routeValues); IEnumerable Lookup(string routePath); - void Replace(string aliasPath, RouteValueDictionary routeValues, string aliasSource); - void Replace(string aliasPath, string routePath, string aliasSource); + void Replace(string aliasPath, RouteValueDictionary routeValues, string aliasSource, bool isManaged = false); + void Replace(string aliasPath, string routePath, string aliasSource, bool isManaged = false); IEnumerable> List(); IEnumerable> List(string sourceStartsWith); diff --git a/src/Orchard.Web/Modules/Orchard.Alias/Implementation/AliasRoute.cs b/src/Orchard.Web/Modules/Orchard.Alias/Implementation/AliasRoute.cs index 2e7a3ace7..2be33d808 100644 --- a/src/Orchard.Web/Modules/Orchard.Alias/Implementation/AliasRoute.cs +++ b/src/Orchard.Web/Modules/Orchard.Alias/Implementation/AliasRoute.cs @@ -29,12 +29,13 @@ namespace Orchard.Alias.Implementation { var virtualPath = httpContext.Request.AppRelativeCurrentExecutionFilePath.Substring(2) + httpContext.Request.PathInfo; // Attempt to lookup RouteValues in the alias map - IDictionary routeValues; + //IDictionary routeValues; + AliasInfo aliasInfo; // TODO: Might as well have the lookup in AliasHolder... - if (_aliasMap.TryGetAlias(virtualPath, out routeValues)) { + if (_aliasMap.TryGetAlias(virtualPath, out aliasInfo)) { // Construct RouteData from the route values var data = new RouteData(this, _routeHandler); - foreach (var routeValue in routeValues) { + foreach (var routeValue in aliasInfo.RouteValues) { var key = routeValue.Key; if (key.EndsWith("-")) data.Values.Add(key.Substring(0, key.Length - 1), routeValue.Value); diff --git a/src/Orchard.Web/Modules/Orchard.Alias/Implementation/DefaultAliasService.cs b/src/Orchard.Web/Modules/Orchard.Alias/Implementation/DefaultAliasService.cs index 8e8747de4..23e0043ac 100644 --- a/src/Orchard.Web/Modules/Orchard.Alias/Implementation/DefaultAliasService.cs +++ b/src/Orchard.Web/Modules/Orchard.Alias/Implementation/DefaultAliasService.cs @@ -31,18 +31,20 @@ namespace Orchard.Alias.Implementation { return _aliasStorage.Get(aliasPath).ToRouteValueDictionary(); } - public void Set(string aliasPath, RouteValueDictionary routeValues, string aliasSource) { + public void Set(string aliasPath, RouteValueDictionary routeValues, string aliasSource, bool isManaged) { _aliasStorage.Set( aliasPath, ToDictionary(routeValues), - aliasSource); + aliasSource, + isManaged); } - public void Set(string aliasPath, string routePath, string aliasSource) { + public void Set(string aliasPath, string routePath, string aliasSource, bool isManaged) { _aliasStorage.Set( aliasPath.TrimStart('/'), ToDictionary(routePath), - aliasSource); + aliasSource, + isManaged); } public void Delete(string aliasPath) { @@ -71,15 +73,15 @@ namespace Orchard.Alias.Implementation { return Lookup(ToDictionary(routePath).ToRouteValueDictionary()); } - public void Replace(string aliasPath, RouteValueDictionary routeValues, string aliasSource) { + public void Replace(string aliasPath, RouteValueDictionary routeValues, string aliasSource, bool isManaged) { foreach (var lookup in Lookup(routeValues).Where(path => path != aliasPath)) { Delete(lookup, aliasSource); } - Set(aliasPath, routeValues, aliasSource); + Set(aliasPath, routeValues, aliasSource, isManaged); } - public void Replace(string aliasPath, string routePath, string aliasSource) { - Replace(aliasPath, ToDictionary(routePath).ToRouteValueDictionary(), aliasSource); + public void Replace(string aliasPath, string routePath, string aliasSource, bool isManaged) { + Replace(aliasPath, ToDictionary(routePath).ToRouteValueDictionary(), aliasSource, isManaged); } public IEnumerable Lookup(RouteValueDictionary routeValues) { @@ -89,7 +91,7 @@ namespace Orchard.Alias.Implementation { // the route has an area, lookup in the specific alias map var map = _aliasHolder.GetMap(area.ToString()); - + if (map == null) { return Enumerable.Empty(); } @@ -102,7 +104,7 @@ namespace Orchard.Alias.Implementation { return new[] { locate.Item2 }; } - + // no specific area, lookup in all alias maps var result = new List(); foreach (var map in _aliasHolder.GetMaps()) { @@ -115,7 +117,7 @@ namespace Orchard.Alias.Implementation { return result; } - + public IEnumerable> List() { return _aliasStorage.List().Select(item => Tuple.Create(item.Item1, item.Item3.ToRouteValueDictionary())); } @@ -145,21 +147,20 @@ namespace Orchard.Alias.Implementation { private IEnumerable GetRouteDescriptors() { return _routeProviders .SelectMany(routeProvider => { - var routes = new List(); - routeProvider.GetRoutes(routes); - return routes; - }) + var routes = new List(); + routeProvider.GetRoutes(routes); + return routes; + }) .Where(routeDescriptor => !(routeDescriptor.Route is AliasRoute)) .OrderByDescending(routeDescriptor => routeDescriptor.Priority); } private class StubHttpContext : HttpContextBase { - public override HttpRequestBase Request - { - get{return new StubHttpRequest();} + public override HttpRequestBase Request { + get { return new StubHttpRequest(); } } - private class StubHttpRequest : HttpRequestBase {} + private class StubHttpRequest : HttpRequestBase { } } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Holder/AliasInfo.cs b/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Holder/AliasInfo.cs index a85c4377a..0c3ffed2f 100644 --- a/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Holder/AliasInfo.cs +++ b/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Holder/AliasInfo.cs @@ -5,5 +5,6 @@ namespace Orchard.Alias.Implementation.Holder { public string Area { get; set; } public string Path { get; set; } public IDictionary RouteValues { get; set; } + public bool IsManaged { get; set; } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Holder/IAliasHolder.cs b/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Holder/IAliasHolder.cs index cff41f482..f198c978e 100644 --- a/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Holder/IAliasHolder.cs +++ b/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Holder/IAliasHolder.cs @@ -26,7 +26,7 @@ namespace Orchard.Alias.Implementation.Holder { /// Adds or updates a set of aliases in the tree /// void SetAliases(IEnumerable aliases); - + /// /// Removes an alias from the tree based on its path /// diff --git a/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Map/AliasMap.cs b/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Map/AliasMap.cs index 834da797a..3211768b0 100644 --- a/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Map/AliasMap.cs +++ b/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Map/AliasMap.cs @@ -9,21 +9,21 @@ using System.Collections.Concurrent; namespace Orchard.Alias.Implementation.Map { public class AliasMap { private readonly string _area; - private readonly ConcurrentDictionary> _aliases; + private readonly ConcurrentDictionary _aliases; private readonly Node _root; public AliasMap(string area) { _area = area; - _aliases = new ConcurrentDictionary>(StringComparer.OrdinalIgnoreCase); + _aliases = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); _root = new Node(); } public IEnumerable GetAliases() { - return _aliases.Select(x => new AliasInfo {Area = _area, Path = x.Key, RouteValues = x.Value}); + return _aliases.Select(x => new AliasInfo { Area = _area, Path = x.Key, RouteValues = x.Value.RouteValues, IsManaged = x.Value.IsManaged }); } - - public bool TryGetAlias(string virtualPath, out IDictionary routeValues) { - return _aliases.TryGetValue(virtualPath, out routeValues); + + public bool TryGetAlias(string virtualPath, out AliasInfo aliasInfo) { + return _aliases.TryGetValue(virtualPath, out aliasInfo); } public Tuple, string> Locate(RouteValueDictionary routeValues) { @@ -35,11 +35,10 @@ namespace Orchard.Alias.Implementation.Map { /// /// The intance to add public void Insert(AliasInfo info) { - if(info == null) { + if (info == null) { throw new ArgumentNullException(); } - - _aliases[info.Path] = info.RouteValues; + _aliases[info.Path] = info; ExpandTree(_root, info.Path, info.RouteValues); } @@ -48,8 +47,8 @@ namespace Orchard.Alias.Implementation.Map { /// /// public void Remove(AliasInfo info) { - IDictionary values; - _aliases.TryRemove(info.Path, out values); + AliasInfo aliasInfo; + _aliases.TryRemove(info.Path, out aliasInfo); CollapseTree(_root, info.Path, info.RouteValues); } @@ -73,18 +72,18 @@ namespace Orchard.Alias.Implementation.Map { } // Set the path at the end of the tree object takenPath; - focus.Paths.TryRemove(path,out takenPath); + focus.Paths.TryRemove(path, out takenPath); } } private static void ExpandTree(Node root, string path, IDictionary routeValues) { - foreach(var expanded in Expand(routeValues)) { + foreach (var expanded in Expand(routeValues)) { var focus = root; foreach (var routeValue in expanded.OrderBy(kv => kv.Key, StringComparer.InvariantCultureIgnoreCase)) { // See if we already have a stem for this route key (i.e. "controller") and create if not - var stem = focus.Stems.GetOrAdd(routeValue.Key,key=>new ConcurrentDictionary(StringComparer.InvariantCultureIgnoreCase)); + var stem = focus.Stems.GetOrAdd(routeValue.Key, key => new ConcurrentDictionary(StringComparer.InvariantCultureIgnoreCase)); // See if the stem has a node for this value (i.e. "Item") and create if not - var node = stem.GetOrAdd(routeValue.Value, key=>new Node()); + var node = stem.GetOrAdd(routeValue.Value, key => new Node()); // Keep switching to new node until we reach deepest match // TODO: (PH) Thread safety: at this point something could techincally traverse and find an empty node with a blank path ... not fatal // since it will simply not match and therefore return a default-looking route instead of the aliased one. And the changes of that route @@ -111,23 +110,22 @@ namespace Orchard.Alias.Implementation.Map { // For each key/value pair, we want a list containing a single list with either the term, or the term and the "default" value var termSets = ordered.Select(term => { - if (term.Key.EndsWith("-")) { - var termKey = term.Key.Substring(0, term.Key.Length - 1); - return new[] { + if (term.Key.EndsWith("-")) { + var termKey = term.Key.Substring(0, term.Key.Length - 1); + return new[] { // This entry will auto-match in some cases because it was omitted from the route values new [] { new KeyValuePair(termKey, "\u0000") }, new [] { new KeyValuePair(termKey, term.Value) } }; - } - return new[] {new[] {term}}; - }); + } + return new[] { new[] { term } }; + }); // Run each of those lists through an aggregation function, by taking the product of each set, so producting a tree of possibilities var produced = termSets.Aggregate(new[] { empty }.AsEnumerable(), (coords, termSet) => Product(coords, termSet, (coord, term) => coord.Concat(term))); return produced; } - private static Tuple, string> Traverse(Node focus, RouteValueDictionary routeValues, string areaName) { // Initialize a match variable @@ -191,7 +189,7 @@ namespace Orchard.Alias.Implementation.Map { } public ConcurrentDictionary> Stems { get; set; } - public ConcurrentDictionary Paths { get; set; } + public ConcurrentDictionary Paths { get; set; } } } diff --git a/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Storage/AliasStorage.cs b/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Storage/AliasStorage.cs index 736fcece6..e8d8feb1d 100644 --- a/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Storage/AliasStorage.cs +++ b/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Storage/AliasStorage.cs @@ -10,15 +10,15 @@ using Orchard.Validation; namespace Orchard.Alias.Implementation.Storage { public interface IAliasStorage : IDependency { - void Set(string path, IDictionary routeValues, string source); + void Set(string path, IDictionary routeValues, string source, bool isManaged); IDictionary Get(string aliasPath); void Remove(Expression> filter); void Remove(string path); void Remove(string path, string aliasSource); void RemoveBySource(string aliasSource); - IEnumerable, string, int>> List(Expression> predicate); - IEnumerable, string, int>> List(); - IEnumerable, string, int>> List(string sourceStartsWith); + IEnumerable, string, int, bool>> List(Expression> predicate); + IEnumerable, string, int, bool>> List(); + IEnumerable, string, int, bool>> List(string sourceStartsWith); } public class AliasStorage : IAliasStorage { @@ -31,7 +31,7 @@ namespace Orchard.Alias.Implementation.Storage { _aliasHolder = aliasHolder; } - public void Set(string path, IDictionary routeValues, string source) { + public void Set(string path, IDictionary routeValues, string source, bool isManaged) { if (path == null) { throw new ArgumentNullException("path"); } @@ -66,6 +66,7 @@ namespace Orchard.Alias.Implementation.Storage { aliasRecord.RouteValues = values.ToString(); aliasRecord.Source = source; + aliasRecord.IsManaged = isManaged; if (aliasRecord.Action.Id == 0 || aliasRecord.Id == 0) { if (aliasRecord.Action.Id == 0) { _actionRepository.Create(aliasRecord.Action); @@ -78,7 +79,7 @@ namespace Orchard.Alias.Implementation.Storage { } // Transform and push into AliasHolder var dict = ToDictionary(aliasRecord); - _aliasHolder.SetAlias(new AliasInfo { Path = dict.Item1, Area = dict.Item2, RouteValues = dict.Item3 }); + _aliasHolder.SetAlias(new AliasInfo { Path = dict.Item1, Area = dict.Item2, RouteValues = dict.Item3, IsManaged = dict.Item6 }); } public IDictionary Get(string path) { @@ -90,7 +91,7 @@ namespace Orchard.Alias.Implementation.Storage { } public void Remove(string path) { - Remove(x => x.Path == path && x.Source == path); + Remove(x => x.Path == path); } public void Remove(string path, string aliasSource) { @@ -109,15 +110,15 @@ namespace Orchard.Alias.Implementation.Storage { // Bulk updates might go wrong if we don't flush. _aliasRepository.Flush(); var dict = ToDictionary(aliasRecord); - _aliasHolder.RemoveAlias(new AliasInfo() { Path = dict.Item1, Area = dict.Item2, RouteValues = dict.Item3 }); + _aliasHolder.RemoveAlias(new AliasInfo() { Path = dict.Item1, Area = dict.Item2, RouteValues = dict.Item3, IsManaged = dict.Item6 }); } } - public IEnumerable, string, int>> List() { + public IEnumerable, string, int, bool>> List() { return List((Expression>)null); } - public IEnumerable, string, int>> List(Expression> predicate) { + public IEnumerable, string, int, bool>> List(Expression> predicate) { var table = _aliasRepository.Table; if (predicate != null) { @@ -127,11 +128,11 @@ namespace Orchard.Alias.Implementation.Storage { return table.OrderBy(a => a.Id).Select(ToDictionary).ToList(); } - public IEnumerable, string, int>> List(string sourceStartsWith) { + public IEnumerable, string, int, bool>> List(string sourceStartsWith) { return List(a => a.Source.StartsWith(sourceStartsWith)); } - private static Tuple, string, int> ToDictionary(AliasRecord aliasRecord) { + private static Tuple, string, int, bool> ToDictionary(AliasRecord aliasRecord) { IDictionary routeValues = new Dictionary(); if (aliasRecord.Action.Area != null) { routeValues.Add("area", aliasRecord.Action.Area); @@ -147,7 +148,7 @@ namespace Orchard.Alias.Implementation.Storage { routeValues.Add(attr.Name.LocalName, attr.Value); } } - return Tuple.Create(aliasRecord.Path, aliasRecord.Action.Area, routeValues, aliasRecord.Source, aliasRecord.Id); + return Tuple.Create(aliasRecord.Path, aliasRecord.Action.Area, routeValues, aliasRecord.Source, aliasRecord.Id, aliasRecord.IsManaged); } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Updater/AliasHolderUpdater.cs b/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Updater/AliasHolderUpdater.cs index aec6d63ad..9a3e03322 100644 --- a/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Updater/AliasHolderUpdater.cs +++ b/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Updater/AliasHolderUpdater.cs @@ -34,7 +34,7 @@ namespace Orchard.Alias.Implementation.Updater { // update the last processed id if (aliases.Any()) { _cursor.Cursor = aliases.Last().Item5; - _aliasHolder.SetAliases(aliases.Select(alias => new AliasInfo { Path = alias.Item1, Area = alias.Item2, RouteValues = alias.Item3 })); + _aliasHolder.SetAliases(aliases.Select(alias => new AliasInfo { Path = alias.Item1, Area = alias.Item2, RouteValues = alias.Item3, IsManaged = alias.Item6 })); } } catch (Exception ex) { @@ -44,13 +44,13 @@ namespace Orchard.Alias.Implementation.Updater { } public class AliasUpdaterEvent : IOrchardShellEvents { - + private readonly IAliasHolderUpdater _aliasHolderUpdater; public AliasUpdaterEvent(IAliasHolderUpdater aliasHolderUpdater) { _aliasHolderUpdater = aliasHolderUpdater; } - + void IOrchardShellEvents.Activated() { _aliasHolderUpdater.Refresh(); } diff --git a/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Updater/IAliasUpdateCursor.cs b/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Updater/IAliasUpdateCursor.cs index c80d50678..9fa35b2e7 100644 --- a/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Updater/IAliasUpdateCursor.cs +++ b/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Updater/IAliasUpdateCursor.cs @@ -1,5 +1,5 @@ namespace Orchard.Alias.Implementation.Updater { public interface IAliasUpdateCursor : ISingletonDependency { - int Cursor { get; set; } + int Cursor { get; set; } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Utils.cs b/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Utils.cs index b0551264c..304068a74 100644 --- a/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Utils.cs +++ b/src/Orchard.Web/Modules/Orchard.Alias/Implementation/Utils.cs @@ -65,7 +65,6 @@ namespace Orchard.Alias.Implementation { return key.EndsWith("-", StringComparison.InvariantCulture) ? key.Substring(0, key.Length - 1) : key; } - private static Dictionary ToRouteValues(RouteData routeData, string queryString) { var routeValues = routeData.Values .Select(kv => { diff --git a/src/Orchard.Web/Modules/Orchard.Alias/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Alias/Migrations.cs index 1b36b99ea..563bfa3de 100644 --- a/src/Orchard.Web/Modules/Orchard.Alias/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Alias/Migrations.cs @@ -20,5 +20,13 @@ namespace Orchard.Alias { return 1; } + public int UpdateFrom1() { + SchemaBuilder.AlterTable("AliasRecord", + table => table + .AddColumn("IsManaged", column => column.WithDefault(false)) + ); + return 2; + } + } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Alias/Orchard.Alias.csproj b/src/Orchard.Web/Modules/Orchard.Alias/Orchard.Alias.csproj index 5f56dcfe8..29073c9d5 100644 --- a/src/Orchard.Web/Modules/Orchard.Alias/Orchard.Alias.csproj +++ b/src/Orchard.Web/Modules/Orchard.Alias/Orchard.Alias.csproj @@ -75,7 +75,7 @@ - + @@ -110,12 +110,16 @@ + + - + + + 10.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) @@ -123,20 +127,20 @@ - $(ProjectDir)\..\Manifests - - diff --git a/src/Orchard.Web/Modules/Orchard.Alias/Recipes/Builders/AliasStep.cs b/src/Orchard.Web/Modules/Orchard.Alias/Recipes/Builders/AliasStep.cs new file mode 100644 index 000000000..627ca7d9a --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Alias/Recipes/Builders/AliasStep.cs @@ -0,0 +1,53 @@ +using System.Linq; +using System.Xml.Linq; +using Orchard.Data; +using Orchard.Localization; +using Orchard.Recipes.Services; +using Orchard.Alias.Records; +using Orchard.Alias.Implementation.Holder; + +namespace Orchard.Alias.Recipes.Builders { + public class AliasStep : RecipeBuilderStep { + private readonly IRepository _aliasRecordepository; + private readonly IAliasHolder _aliasHolder; + + public AliasStep(IRepository aliasRecordRepository, IAliasHolder aliasHolder) { + _aliasRecordepository = aliasRecordRepository; + _aliasHolder = aliasHolder; + } + + public override string Name { + get { return "Alias"; } + } + + public override LocalizedString DisplayName { + get { return T("Aliases"); } + } + + public override LocalizedString Description { + get { return T("Exports unmanaged aliases."); } + } + + public override void Build(BuildContext context) { + var aliases = _aliasHolder.GetMaps().SelectMany(m => m.GetAliases()).Where(m => m.IsManaged == false).OrderBy(m => m.Path).ToList(); + + if (!aliases.Any()) + return; + + var root = new XElement("Aliases"); + context.RecipeDocument.Element("Orchard").Add(root); + + foreach (var alias in aliases) { + var aliasElement = new XElement("Alias", new XAttribute("Path", alias.Path)); + + var routeValuesElement = new XElement("RouteValues"); + foreach (var routeValue in alias.RouteValues) { + routeValuesElement.Add(new XElement("Add", new XAttribute("Key", routeValue.Key), new XAttribute("Value", routeValue.Value))); + } + + aliasElement.Add(routeValuesElement); + root.Add(aliasElement); + } + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Alias/Recipes/Executors/AliasStep.cs b/src/Orchard.Web/Modules/Orchard.Alias/Recipes/Executors/AliasStep.cs new file mode 100644 index 000000000..cd17744ab --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Alias/Recipes/Executors/AliasStep.cs @@ -0,0 +1,62 @@ +using System; +using System.Web; +using System.Web.Routing; +using System.Linq; +using Orchard.Alias; +using Orchard.Logging; +using Orchard.Recipes.Models; +using Orchard.Recipes.Services; + +namespace Orchard.Alias.Recipes.Executors { + public class AliasStep : RecipeExecutionStep { + private readonly IAliasService _aliasService; + + public AliasStep( + IAliasService aliasService, + RecipeExecutionLogger logger) : base(logger) { + _aliasService = aliasService; + } + + public override string Name { + get { return "Aliases"; } + } + + /* + + + + + + + + + */ + public override void Execute(RecipeExecutionContext context) { + + foreach (var aliasElement in context.RecipeStep.Step.Elements()) { + var aliasPath = aliasElement.Attribute("Path").Value; + + Logger.Information("Importing alias '{0}'.", aliasPath); + + try { + var rvd = new RouteValueDictionary(); + + var routeValuesElement = aliasElement.Descendants("RouteValues").FirstOrDefault(); + + if (routeValuesElement != null) { + foreach (var routeValue in routeValuesElement.Descendants("Add")) { + rvd.Add(routeValue.Attribute("Key").Value, routeValue.Attribute("Value").Value); + } + } + + _aliasService.Set(aliasPath, rvd, "Custom", false); + } + + catch (Exception ex) { + Logger.Error(ex, "Error while processing alias '{0}'.", aliasPath); + throw; + } + } + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Alias/Records/AliasRecord.cs b/src/Orchard.Web/Modules/Orchard.Alias/Records/AliasRecord.cs index 258667261..e243c7ad5 100644 --- a/src/Orchard.Web/Modules/Orchard.Alias/Records/AliasRecord.cs +++ b/src/Orchard.Web/Modules/Orchard.Alias/Records/AliasRecord.cs @@ -5,5 +5,6 @@ public virtual ActionRecord Action { get; set; } public virtual string RouteValues { get; set; } public virtual string Source { get; set; } + public virtual bool IsManaged { get; set; } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Alias/Routes.cs b/src/Orchard.Web/Modules/Orchard.Alias/Routes.cs index f09bcac46..563516d65 100644 --- a/src/Orchard.Web/Modules/Orchard.Alias/Routes.cs +++ b/src/Orchard.Web/Modules/Orchard.Alias/Routes.cs @@ -10,7 +10,7 @@ namespace Orchard.Alias { public class Routes : IRouteProvider { private readonly ShellBlueprint _blueprint; private readonly IAliasHolder _aliasHolder; - + public Routes(ShellBlueprint blueprint, IAliasHolder aliasHolder) { _blueprint = blueprint; _aliasHolder = aliasHolder; diff --git a/src/Orchard.Web/Modules/Orchard.Alias/ViewModels/AdminIndexViewModel.cs b/src/Orchard.Web/Modules/Orchard.Alias/ViewModels/AdminIndexViewModel.cs index da53408b8..f39737fae 100644 --- a/src/Orchard.Web/Modules/Orchard.Alias/ViewModels/AdminIndexViewModel.cs +++ b/src/Orchard.Web/Modules/Orchard.Alias/ViewModels/AdminIndexViewModel.cs @@ -13,6 +13,7 @@ namespace Orchard.Alias.ViewModels { public AliasInfo Alias { get; set; } public bool IsChecked { get; set; } } + public class AdminIndexOptions { public string Search { get; set; } public AliasOrder Order { get; set; } @@ -25,7 +26,9 @@ namespace Orchard.Alias.ViewModels { } public enum AliasFilter { - All + All, + Managed, + Unmanaged } public enum AliasBulkAction { diff --git a/src/Orchard.Web/Modules/Orchard.Alias/Views/Admin/Add.cshtml b/src/Orchard.Web/Modules/Orchard.Alias/Views/Admin/Add.cshtml index da790c3ad..f94f52ae0 100644 --- a/src/Orchard.Web/Modules/Orchard.Alias/Views/Admin/Add.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Alias/Views/Admin/Add.cshtml @@ -4,25 +4,25 @@ @using (Html.BeginFormAntiForgeryPost()) { @Html.ValidationSummary() -
- @T("Create Alias") -
- - @Html.TextBox("aliasPath", (object)ViewBag.Path, new { @class = "text large" }) - @Html.ValidationMessage("aliasPath") - @T("The path of the alias e.g., my-blog/my-post") -
-
- - @Html.TextBox("routePath", (object)ViewBag.Route, new { @class = "text medium" }) - @Html.ValidationMessage("routePath") - @T("The actual route Orchard should call when the path is requested e.g., Blogs/Blog/Item?blogId=18") -
-
-
-
- - @Html.ActionLink(T("Cancel").ToString(), "Index", new { }, new { @class = "button" }) -
-
- } \ No newline at end of file +
+ @T("Create Alias") +
+ + @Html.TextBox("aliasPath", (object)ViewBag.Path, new { @class = "text large" }) + @Html.ValidationMessage("aliasPath") + @T("The path of the alias e.g., my-blog/my-post") +
+
+ + @Html.TextBox("routePath", (object)ViewBag.Route, new { @class = "text medium" }) + @Html.ValidationMessage("routePath") + @T("The actual route Orchard should call when the path is requested e.g., Blogs/Blog/Item?blogId=18") +
+
+
+
+ + @Html.ActionLink(T("Cancel").ToString(), "IndexUnmanaged", new { }, new { @class = "button" }) +
+
+} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Alias/Views/Admin/Delete.cshtml b/src/Orchard.Web/Modules/Orchard.Alias/Views/Admin/Delete.cshtml index bda927365..1c61a71a5 100644 --- a/src/Orchard.Web/Modules/Orchard.Alias/Views/Admin/Delete.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Alias/Views/Admin/Delete.cshtml @@ -3,11 +3,11 @@ } @using (Html.BeginFormAntiForgeryPost()) { -
- @T("Delete alias") -

@T("Removing alias '{0}'. Are you sure?", ViewBag.Path)

- @Html.Hidden("path") - @Html.Hidden("confirmed", true) - -
+
+ @T("Delete alias") +

@T("Removing alias '{0}'. Are you sure?", ViewBag.Path)

+ @Html.Hidden("path") + @Html.Hidden("confirmed", true) + +
} diff --git a/src/Orchard.Web/Modules/Orchard.Alias/Views/Admin/Edit.cshtml b/src/Orchard.Web/Modules/Orchard.Alias/Views/Admin/Edit.cshtml index 072569b9c..5a8afe8a1 100644 --- a/src/Orchard.Web/Modules/Orchard.Alias/Views/Admin/Edit.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Alias/Views/Admin/Edit.cshtml @@ -4,25 +4,25 @@ @using (Html.BeginFormAntiForgeryPost()) { @Html.ValidationSummary() -
- @T("Edit alias") -
- - @Html.TextBox("aliasPath", null, new { @class = "text large" }) - @Html.ValidationMessage("aliasPath") - @T("The path of the alias e.g., my-blog/my-post") -
-
- - @Html.TextBox("routePath", null, new { @class = "text medium" }) - @Html.ValidationMessage("routePath") - @T("The actual route Orchard should call when the path is requested e.g., Blogs/Blog/Item?blogId=18") -
-
-
-
- - @Html.ActionLink(T("Cancel").ToString(), "Index", new { }, new { @class = "button" }) -
-
- } +
+ @T("Edit alias") +
+ + @Html.TextBox("aliasPath", null, new { @class = "text large" }) + @Html.ValidationMessage("aliasPath") + @T("The path of the alias e.g., my-blog/my-post") +
+
+ + @Html.TextBox("routePath", null, new { @class = "text medium" }) + @Html.ValidationMessage("routePath") + @T("The actual route Orchard should call when the path is requested e.g., Blogs/Blog/Item?blogId=18") +
+
+
+
+ + @Html.ActionLink(T("Cancel").ToString(), "IndexUnmanaged", new { }, new { @class = "button" }) +
+
+} diff --git a/src/Orchard.Web/Modules/Orchard.Alias/Views/Admin/Index.cshtml b/src/Orchard.Web/Modules/Orchard.Alias/Views/Admin/Index.cshtml deleted file mode 100644 index 417632e11..000000000 --- a/src/Orchard.Web/Modules/Orchard.Alias/Views/Admin/Index.cshtml +++ /dev/null @@ -1,92 +0,0 @@ -@model AdminIndexViewModel - -@using Orchard.Alias -@using Orchard.Alias.ViewModels -@using Orchard.Environment.Configuration -@using Orchard.Utility.Extensions - -@{ - var urlPrefix = WorkContext.Resolve().RequestUrlPrefix; - - Layout.Title = T("Manage Aliases").Text; - var aliasService = WorkContext.Resolve(); - AdminIndexOptions options = Model.Options; - int index = -1; - - var pageSizes = new List() { 10, 50, 100 }; - var defaultPageSize = WorkContext.CurrentSite.PageSize; - if (!pageSizes.Contains(defaultPageSize)) { - pageSizes.Add(defaultPageSize); - } -} - -@using (Html.BeginFormAntiForgeryPost()) { - @Html.ValidationSummary() -
@Html.ActionLink(T("Add new Alias").Text, "Add", new { returnurl = HttpContext.Current.Request.RawUrl }, new { @class = "button primaryAction" })
- -
- - - -
-
- - - - - - -
-
- - - - - - - - - - @foreach (var aliasEntry in Model.AliasEntries) { - var alias = aliasEntry.Alias; - index++; - var virtualPathData = aliasService.LookupVirtualPaths(alias.RouteValues.ToRouteValueDictionary(), ViewContext.HttpContext).FirstOrDefault(); - - if (virtualPathData == null) { - continue; - } - - var url = virtualPathData.VirtualPath; - - - - - - - } -
@T("Alias")@T("Route") 
- - - - @Html.Link(alias.Path == String.Empty ? "/" : alias.Path, Href("~/" + urlPrefix + alias.Path)) - - @Html.Link(url, Href("~/" + urlPrefix + "/" + url)) - - @Html.ActionLink(T("Edit").Text, "Edit", new { path = alias.Path == String.Empty ? "/" : alias.Path }) - | - @Html.ActionLink(T("Delete").Text, "Delete", new { path = alias.Path }, new { itemprop = "UnsafeUrl RemoveUrl" }) -
- - @Display(Model.Pager) -
-} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Alias/Views/Admin/IndexManaged.cshtml b/src/Orchard.Web/Modules/Orchard.Alias/Views/Admin/IndexManaged.cshtml new file mode 100644 index 000000000..6404513b8 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Alias/Views/Admin/IndexManaged.cshtml @@ -0,0 +1,74 @@ +@model AdminIndexViewModel + +@using Orchard.Alias +@using Orchard.Alias.ViewModels +@using Orchard.Environment.Configuration +@using Orchard.Utility.Extensions + +@{ + var urlPrefix = WorkContext.Resolve().RequestUrlPrefix; + + Layout.Title = T("Manage Aliases").Text; + var aliasService = WorkContext.Resolve(); + AdminIndexOptions options = Model.Options; + int index = -1; + + var pageSizes = new List() { 10, 50, 100 }; + var defaultPageSize = WorkContext.CurrentSite.PageSize; + if (!pageSizes.Contains(defaultPageSize)) { + pageSizes.Add(defaultPageSize); + } +} + +@using (Html.BeginFormAntiForgeryPost()) { + @Html.ValidationSummary() + +
+ + + + + + +
+
+ + + + + + + + + @foreach (var aliasEntry in Model.AliasEntries) { + var alias = aliasEntry.Alias; + index++; + var virtualPathData = aliasService.LookupVirtualPaths(alias.RouteValues.ToRouteValueDictionary(), ViewContext.HttpContext).FirstOrDefault(); + + if (virtualPathData == null) { + continue; + } + + var url = virtualPathData.VirtualPath; + + + + + } +
@T("Alias")@T("Route") 
+ + @Html.Link(alias.Path == String.Empty ? "/" : alias.Path, Href("~/" + urlPrefix + alias.Path)) + + @Html.Link(url, Href("~/" + urlPrefix + "/" + url)) +
+ + @Display(Model.Pager) +
+} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Alias/Views/Admin/IndexUnmanaged.cshtml b/src/Orchard.Web/Modules/Orchard.Alias/Views/Admin/IndexUnmanaged.cshtml new file mode 100644 index 000000000..22bb3e247 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Alias/Views/Admin/IndexUnmanaged.cshtml @@ -0,0 +1,91 @@ +@model AdminIndexViewModel + +@using Orchard.Alias +@using Orchard.Alias.ViewModels +@using Orchard.Environment.Configuration +@using Orchard.Utility.Extensions + +@{ + var urlPrefix = WorkContext.Resolve().RequestUrlPrefix; + + Layout.Title = T("Manage Aliases").Text; + var aliasService = WorkContext.Resolve(); + AdminIndexOptions options = Model.Options; + int index = -1; + + var pageSizes = new List() { 10, 50, 100 }; + var defaultPageSize = WorkContext.CurrentSite.PageSize; + if (!pageSizes.Contains(defaultPageSize)) { + pageSizes.Add(defaultPageSize); + } +} + +@using (Html.BeginFormAntiForgeryPost()) { + @Html.ValidationSummary() +
@Html.ActionLink(T("Add new Alias").Text, "Add", new { returnurl = HttpContext.Current.Request.RawUrl }, new { @class = "button primaryAction" })
+ +
+ + + +
+
+ + + + + + +
+
+ + + + + + + + + + @foreach (var aliasEntry in Model.AliasEntries) { + var alias = aliasEntry.Alias; + index++; + var virtualPathData = aliasService.LookupVirtualPaths(alias.RouteValues.ToRouteValueDictionary(), ViewContext.HttpContext).FirstOrDefault(); + + if (virtualPathData == null) { + continue; + } + + var url = virtualPathData.VirtualPath; + + + + + + + } +
@T("Alias")@T("Route") 
+ + + + @Html.Link(alias.Path == String.Empty ? "/" : alias.Path, Href("~/" + urlPrefix + alias.Path)) + + @Html.Link(url, Href("~/" + urlPrefix + "/" + url)) + + @Html.ActionLink(T("Edit").Text, "Edit", new { path = alias.Path == String.Empty ? "/" : alias.Path }) + @Html.ActionLink(T("Delete").Text, "Delete", new { path = alias.Path }, new { itemprop = "UnsafeUrl RemoveUrl" }) +
+ + @Display(Model.Pager) +
+} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs index df0f07afc..dfedcf80d 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs @@ -96,7 +96,7 @@ namespace Orchard.Autoroute.Services { public void PublishAlias(AutoroutePart part) { var displayRouteValues = _contentManager.GetItemMetadata(part).DisplayRouteValues; - _aliasService.Replace(part.DisplayAlias, displayRouteValues, AliasSource); + _aliasService.Replace(part.DisplayAlias, displayRouteValues, AliasSource, true); _routeEvents.Routed(part, part.DisplayAlias); } @@ -146,7 +146,8 @@ namespace Orchard.Autoroute.Services { if (String.Equals(culture, _cultureManager.GetSiteCulture(), StringComparison.OrdinalIgnoreCase) && !String.IsNullOrWhiteSpace(patternIndex)) { settings.DefaultPatterns.Add(new DefaultPattern { PatternIndex = patternIndex, Culture = culture }); return settings.Patterns.Where(x => x.Culture == null).ElementAt(Convert.ToInt32(settings.DefaultPatterns.Where(x => x.Culture == culture).FirstOrDefault().PatternIndex)); - } else { + } + else { settings.DefaultPatterns.Add(new DefaultPattern { PatternIndex = "0", Culture = culture }); return new RoutePattern { Name = "Title", Description = "my-title", Pattern = "{Content.Slug}", Culture = culture }; } diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/ArchiveConstraint.CS b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/ArchiveConstraint.CS index 61ade43a1..e740de62a 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/ArchiveConstraint.CS +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/ArchiveConstraint.CS @@ -37,18 +37,18 @@ namespace Orchard.Blogs.Routing { return false; } - IDictionary routeValues; - if (!_aliasHolder.GetMap("Orchard.Blogs").TryGetAlias(path, out routeValues)) { + AliasInfo aliasInfo; + if (!_aliasHolder.GetMap("Orchard.Blogs").TryGetAlias(path, out aliasInfo)) { return false; } - var isBlog = + var isBlog = //routeValues.ContainsKey("area") && //routeValues["area"] == "Orchard.Blogs" && - routeValues.ContainsKey("controller") && - routeValues["controller"] == "Blog" && - routeValues.ContainsKey("action") && - routeValues["action"] == "Item" + aliasInfo.RouteValues.ContainsKey("controller") && + aliasInfo.RouteValues["controller"] == "Blog" && + aliasInfo.RouteValues.ContainsKey("action") && + aliasInfo.RouteValues["action"] == "Item" ; return isBlog; @@ -84,7 +84,7 @@ namespace Orchard.Blogs.Routing { } // archive for blog as homepage ? - if(path.StartsWith("archive/", StringComparison.OrdinalIgnoreCase)) { + if (path.StartsWith("archive/", StringComparison.OrdinalIgnoreCase)) { return String.Empty; } diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/RsdConstraint.CS b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/RsdConstraint.CS index d41b9fde6..c722ec0a7 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/RsdConstraint.CS +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/RsdConstraint.CS @@ -25,18 +25,19 @@ namespace Orchard.Blogs.Routing { return false; } - IDictionary routeValues; - if (!_aliasHolder.GetMap("Orchard.Blogs").TryGetAlias(path, out routeValues)) { + AliasInfo aliasInfo; + if (!_aliasHolder.GetMap("Orchard.Blogs").TryGetAlias(path, out aliasInfo)) + { return false; } var isBlog = //routeValues.ContainsKey("area") && //routeValues["area"] == "Orchard.Blogs" && - routeValues.ContainsKey("controller") && - routeValues["controller"] == "Blog" && - routeValues.ContainsKey("action") && - routeValues["action"] == "Item" + aliasInfo.RouteValues.ContainsKey("controller") && + aliasInfo.RouteValues["controller"] == "Blog" && + aliasInfo.RouteValues.ContainsKey("action") && + aliasInfo.RouteValues["action"] == "Item" ; return isBlog; diff --git a/src/Orchard.Web/Modules/Orchard.Roles/Recipes/Builders/RolesStep.cs b/src/Orchard.Web/Modules/Orchard.Roles/Recipes/Builders/RolesStep.cs index c6a0c2389..577ca085e 100644 --- a/src/Orchard.Web/Modules/Orchard.Roles/Recipes/Builders/RolesStep.cs +++ b/src/Orchard.Web/Modules/Orchard.Roles/Recipes/Builders/RolesStep.cs @@ -22,11 +22,11 @@ namespace Orchard.Roles.Recipes.Builders { } public override LocalizedString Description { - get { return T("Exports the user roles."); } + get { return T("Exports user roles."); } } public override void Build(BuildContext context) { - var roles = _roleRecordepository.Table.ToList(); + var roles = _roleRecordepository.Table.OrderBy(x => x.Name).ToList(); if (!roles.Any()) return; @@ -34,7 +34,7 @@ namespace Orchard.Roles.Recipes.Builders { var root = new XElement("Roles"); context.RecipeDocument.Element("Orchard").Add(root); - foreach (var role in roles.OrderBy(x => x.Name)) { + foreach (var role in roles) { root.Add( new XElement("Role", new XAttribute("Name", role.Name),