mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
@@ -96,6 +96,8 @@
|
||||
<Compile Include="Commands\AutorouteCommands.cs" />
|
||||
<Compile Include="ResourceManifest.cs" />
|
||||
<Compile Include="Services\AliasResolverSelector.cs" />
|
||||
<Compile Include="Services\PathResolutionService.cs" />
|
||||
<Compile Include="Services\IPathResolutionService.cs" />
|
||||
<Compile Include="Services\IRouteEvents.cs" />
|
||||
<Compile Include="Settings\AutorouteSettingsEvents.cs" />
|
||||
<Compile Include="Settings\RoutePattern.cs" />
|
||||
|
||||
@@ -11,9 +11,7 @@ namespace Orchard.Autoroute.Services {
|
||||
|
||||
string GenerateAlias(AutoroutePart part);
|
||||
void PublishAlias(AutoroutePart part);
|
||||
|
||||
void RemoveAliases(AutoroutePart part);
|
||||
|
||||
void CreatePattern(string contentType, string name, string pattern, string description, bool makeDefault);
|
||||
RoutePattern GetDefaultPattern(string contentType);
|
||||
IEnumerable<RoutePattern> GetPatterns(string contentType);
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
using Orchard.Autoroute.Models;
|
||||
|
||||
namespace Orchard.Autoroute.Services {
|
||||
|
||||
public interface IPathResolutionService : IDependency {
|
||||
AutoroutePart GetPath(string path);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System.Linq;
|
||||
using Orchard.Autoroute.Models;
|
||||
using Orchard.ContentManagement;
|
||||
|
||||
namespace Orchard.Autoroute.Services {
|
||||
public class PathResolutionService : IPathResolutionService {
|
||||
private readonly IContentManager _contentManager;
|
||||
|
||||
public PathResolutionService(IContentManager contentManager) {
|
||||
_contentManager = contentManager;
|
||||
}
|
||||
|
||||
public AutoroutePart GetPath(string path) {
|
||||
return _contentManager.Query<AutoroutePart, AutoroutePartRecord>()
|
||||
.Where(part => part.DisplayAlias == path)
|
||||
.Slice(0, 1)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,21 @@
|
||||
using System.Web.Routing;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.Blogs.Routing;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Aspects;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Data;
|
||||
|
||||
namespace Orchard.Blogs.Handlers {
|
||||
[UsedImplicitly]
|
||||
public class BlogPartHandler : ContentHandler {
|
||||
private readonly IBlogPathConstraint _blogPathConstraint;
|
||||
|
||||
public BlogPartHandler(IRepository<BlogPartRecord> repository, IBlogPathConstraint blogPathConstraint) {
|
||||
_blogPathConstraint = blogPathConstraint;
|
||||
public BlogPartHandler(IRepository<BlogPartRecord> repository) {
|
||||
Filters.Add(StorageFilter.For(repository));
|
||||
|
||||
OnGetDisplayShape<BlogPart>((context, blog) => {
|
||||
context.Shape.Description = blog.Description;
|
||||
context.Shape.PostCount = blog.PostCount;
|
||||
});
|
||||
|
||||
OnPublished<BlogPart>((context, blog) => _blogPathConstraint.AddPath(blog.As<IAliasAspect>().Path));
|
||||
OnUnpublished<BlogPart>((context, blog) => _blogPathConstraint.RemovePath(blog.As<IAliasAspect>().Path));
|
||||
}
|
||||
|
||||
protected override void GetItemMetadata(GetContentItemMetadataContext context) {
|
||||
|
||||
@@ -85,13 +85,10 @@
|
||||
<Compile Include="Handlers\BlogPartArchiveHandler.cs" />
|
||||
<Compile Include="Models\BlogPartArchiveRecord.cs" />
|
||||
<Compile Include="Permissions.cs" />
|
||||
<Compile Include="Routing\BlogPathConstraint.cs" />
|
||||
<Compile Include="Routing\BlogPathConstraintUpdator.cs" />
|
||||
<Compile Include="Routing\ArchiveConstraint.cs" />
|
||||
<Compile Include="Routing\IArchiveConstraint.cs" />
|
||||
<Compile Include="Routing\RsdConstraint.cs" />
|
||||
<Compile Include="Routing\IRsdConstraint.cs" />
|
||||
<Compile Include="Routing\IBlogPathConstraint.cs" />
|
||||
<Compile Include="Security\BlogAuthorizationEventHandler.cs" />
|
||||
<Compile Include="Services\ArchiveService.cs" />
|
||||
<Compile Include="Services\BlogService.cs" />
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.Routing;
|
||||
using Orchard.Autoroute.Services;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.ContentManagement;
|
||||
|
||||
namespace Orchard.Blogs.Routing {
|
||||
public class ArchiveConstraint : IArchiveConstraint {
|
||||
private readonly IBlogPathConstraint _blogPathConstraint;
|
||||
private readonly IPathResolutionService _pathResolutionService;
|
||||
|
||||
public ArchiveConstraint(IBlogPathConstraint blogPathConstraint) {
|
||||
_blogPathConstraint = blogPathConstraint;
|
||||
public ArchiveConstraint(IPathResolutionService pathResolutionService) {
|
||||
_pathResolutionService = pathResolutionService;
|
||||
}
|
||||
|
||||
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) {
|
||||
@@ -35,7 +37,9 @@ namespace Orchard.Blogs.Routing {
|
||||
return false;
|
||||
}
|
||||
|
||||
return _blogPathConstraint.FindPath(path) != null;
|
||||
var autoroute = _pathResolutionService.GetPath(path);
|
||||
|
||||
return autoroute != null && autoroute.Is<BlogPart>();
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Routing;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Logging;
|
||||
|
||||
namespace Orchard.Blogs.Routing {
|
||||
[UsedImplicitly]
|
||||
public class BlogPathConstraint : IBlogPathConstraint {
|
||||
private readonly ConcurrentDictionary<string, string> _paths = new ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
public BlogPathConstraint() {
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
public void SetPaths(IEnumerable<string> paths) {
|
||||
_paths.Clear();
|
||||
foreach(var path in paths) {
|
||||
AddPath(path);
|
||||
}
|
||||
|
||||
Logger.Debug("Blog paths: {0}", string.Join(", ", paths.ToArray()));
|
||||
}
|
||||
|
||||
public string FindPath(string path) {
|
||||
string actual;
|
||||
// path can be null for homepage
|
||||
path = path ?? String.Empty;
|
||||
|
||||
return _paths.TryGetValue(path, out actual) ? actual : path;
|
||||
}
|
||||
|
||||
public void AddPath(string path) {
|
||||
// path can be null for homepage
|
||||
path = path ?? String.Empty;
|
||||
|
||||
_paths[path] = path;
|
||||
}
|
||||
|
||||
public void RemovePath(string path) {
|
||||
// path can be null for homepage
|
||||
path = path ?? String.Empty;
|
||||
|
||||
_paths.TryRemove(path, out path);
|
||||
}
|
||||
|
||||
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) {
|
||||
if (routeDirection == RouteDirection.UrlGeneration)
|
||||
return true;
|
||||
|
||||
object value;
|
||||
if (values.TryGetValue(parameterName, out value)) {
|
||||
var parameterValue = Convert.ToString(value);
|
||||
|
||||
return _paths.ContainsKey(parameterValue);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Blogs.Services;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Aspects;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Tasks;
|
||||
|
||||
namespace Orchard.Blogs.Routing {
|
||||
[UsedImplicitly]
|
||||
public class BlogPathConstraintUpdator : IOrchardShellEvents, IBackgroundTask {
|
||||
private readonly IBlogPathConstraint _blogPathConstraint;
|
||||
private readonly IBlogService _blogService;
|
||||
|
||||
public BlogPathConstraintUpdator(IBlogPathConstraint blogPathConstraint, IBlogService blogService) {
|
||||
_blogPathConstraint = blogPathConstraint;
|
||||
_blogService = blogService;
|
||||
}
|
||||
|
||||
void IOrchardShellEvents.Activated() {
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void IOrchardShellEvents.Terminating() {
|
||||
}
|
||||
|
||||
void IBackgroundTask.Sweep() {
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private void Refresh() {
|
||||
_blogPathConstraint.SetPaths(_blogService.Get().Select(b => b.As<IAliasAspect>().Path).ToList());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Routing;
|
||||
|
||||
namespace Orchard.Blogs.Routing {
|
||||
public interface IBlogPathConstraint : IRouteConstraint, ISingletonDependency {
|
||||
void SetPaths(IEnumerable<string> paths);
|
||||
string FindPath(string path);
|
||||
void AddPath(string path);
|
||||
void RemovePath(string path);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,16 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.Routing;
|
||||
using Orchard.Autoroute.Services;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.ContentManagement;
|
||||
|
||||
namespace Orchard.Blogs.Routing {
|
||||
public class RsdConstraint : IRsdConstraint {
|
||||
private readonly IBlogPathConstraint _blogPathConstraint;
|
||||
private readonly IPathResolutionService _pathResolutionService;
|
||||
|
||||
public RsdConstraint(IBlogPathConstraint blogPathConstraint) {
|
||||
_blogPathConstraint = blogPathConstraint;
|
||||
public RsdConstraint(IPathResolutionService pathResolutionService) {
|
||||
_pathResolutionService = pathResolutionService;
|
||||
}
|
||||
|
||||
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) {
|
||||
@@ -23,7 +26,9 @@ namespace Orchard.Blogs.Routing {
|
||||
return false;
|
||||
}
|
||||
|
||||
return _blogPathConstraint.FindPath(path) != null;
|
||||
var autoroute = _pathResolutionService.GetPath(path);
|
||||
|
||||
return autoroute != null && autoroute.Is<BlogPart>();
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Aspects;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Data;
|
||||
using Orchard.Data.Conventions;
|
||||
using Orchard.Tasks.Scheduling;
|
||||
|
||||
namespace Orchard.Blogs.Services {
|
||||
|
||||
@@ -3,20 +3,16 @@ using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Autoroute.Models;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.Blogs.Routing;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Aspects;
|
||||
using Orchard.Core.Title.Models;
|
||||
|
||||
namespace Orchard.Blogs.Services {
|
||||
[UsedImplicitly]
|
||||
public class BlogService : IBlogService {
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IBlogPathConstraint _blogPathConstraint;
|
||||
|
||||
public BlogService(IContentManager contentManager, IBlogPathConstraint blogPathConstraint) {
|
||||
public BlogService(IContentManager contentManager) {
|
||||
_contentManager = contentManager;
|
||||
_blogPathConstraint = blogPathConstraint;
|
||||
}
|
||||
|
||||
public BlogPart Get(string path) {
|
||||
@@ -41,7 +37,6 @@ namespace Orchard.Blogs.Services {
|
||||
|
||||
public void Delete(ContentItem blog) {
|
||||
_contentManager.Remove(blog);
|
||||
_blogPathConstraint.RemovePath(blog.As<IAliasAspect>().Path);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user