mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-23 04:43:35 +08:00
Some renames and cleanup related to feed code
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4045702
This commit is contained in:
@@ -17,7 +17,7 @@ using Orchard.Core.Feeds;
|
||||
using Orchard.Core.Feeds.Controllers;
|
||||
using Orchard.Core.Feeds.Models;
|
||||
using Orchard.Core.Feeds.Rss;
|
||||
using Orchard.Core.Feeds.Services;
|
||||
using Orchard.Core.Feeds.StandardBuilders;
|
||||
using Orchard.Mvc.Results;
|
||||
using Orchard.Tests.Packages;
|
||||
using Orchard.Tests.Stubs;
|
||||
@@ -29,7 +29,7 @@ namespace Orchard.Core.Tests.Feeds.Controllers {
|
||||
public void InvalidFormatShpuldReturnNotFoundResult() {
|
||||
var controller = new FeedController(
|
||||
Enumerable.Empty<IFeedQueryProvider>(),
|
||||
Enumerable.Empty<IFeedFormatterProvider>(),
|
||||
Enumerable.Empty<IFeedBuilderProvider>(),
|
||||
Enumerable.Empty<IFeedItemBuilder>()) {
|
||||
ValueProvider = Values.From(new { })
|
||||
};
|
||||
@@ -41,10 +41,10 @@ namespace Orchard.Core.Tests.Feeds.Controllers {
|
||||
|
||||
[Test]
|
||||
public void ControllerShouldReturnAnActionResult() {
|
||||
var formatProvider = new Mock<IFeedFormatterProvider>();
|
||||
var format = new Mock<IFeedFormatter>();
|
||||
var formatProvider = new Mock<IFeedBuilderProvider>();
|
||||
var format = new Mock<IFeedBuilder>();
|
||||
formatProvider.Setup(x => x.Match(It.IsAny<FeedContext>()))
|
||||
.Returns(new FeedFormatterMatch { FeedFormatter = format.Object, Priority = 10 });
|
||||
.Returns(new FeedBuilderMatch { FeedBuilder = format.Object, Priority = 10 });
|
||||
|
||||
var queryProvider = new Mock<IFeedQueryProvider>();
|
||||
var query = new Mock<IFeedQuery>();
|
||||
@@ -84,7 +84,7 @@ namespace Orchard.Core.Tests.Feeds.Controllers {
|
||||
|
||||
public void Execute(FeedContext context) {
|
||||
foreach (var item in _items) {
|
||||
context.FeedFormatter.AddItem(context, item);
|
||||
context.Builder.AddItem(context, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -96,7 +96,7 @@ namespace Orchard.Core.Tests.Feeds.Controllers {
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterModule(new ImplicitCollectionSupportModule());
|
||||
builder.Register<FeedController>();
|
||||
builder.Register<RssFeedFormatProvider>().As<IFeedFormatterProvider>();
|
||||
builder.Register<RssFeedBuilder>().As<IFeedBuilderProvider>();
|
||||
builder.Register(query).As<IFeedQueryProvider>();
|
||||
var container = builder.Build();
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace Orchard.Core.Tests.Feeds.Controllers {
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterModule(new ImplicitCollectionSupportModule());
|
||||
builder.Register<FeedController>();
|
||||
builder.Register<RssFeedFormatProvider>().As<IFeedFormatterProvider>();
|
||||
builder.Register<RssFeedBuilder>().As<IFeedBuilderProvider>();
|
||||
builder.Register(query).As<IFeedQueryProvider>();
|
||||
var container = builder.Build();
|
||||
|
||||
@@ -168,7 +168,7 @@ namespace Orchard.Core.Tests.Feeds.Controllers {
|
||||
builder.Register<FeedController>();
|
||||
builder.Register(new RouteCollection());
|
||||
builder.Register(mockContentManager.Object).As<IContentManager>();
|
||||
builder.Register<RssFeedFormatProvider>().As<IFeedFormatterProvider>();
|
||||
builder.Register<RssFeedBuilder>().As<IFeedBuilderProvider>();
|
||||
builder.Register<CorePartsFeedItemBuilder>().As<IFeedItemBuilder>();
|
||||
builder.Register(query).As<IFeedQueryProvider>();
|
||||
var container = builder.Build();
|
||||
|
@@ -9,13 +9,13 @@ using Orchard.Mvc.Results;
|
||||
namespace Orchard.Core.Feeds.Controllers {
|
||||
|
||||
public class FeedController : Controller {
|
||||
private readonly IEnumerable<IFeedFormatterProvider> _feedFormatProviders;
|
||||
private readonly IEnumerable<IFeedBuilderProvider> _feedFormatProviders;
|
||||
private readonly IEnumerable<IFeedQueryProvider> _feedQueryProviders;
|
||||
private readonly IEnumerable<IFeedItemBuilder> _feedItemBuilders;
|
||||
|
||||
public FeedController(
|
||||
IEnumerable<IFeedQueryProvider> feedQueryProviders,
|
||||
IEnumerable<IFeedFormatterProvider> feedFormatProviders,
|
||||
IEnumerable<IFeedBuilderProvider> feedFormatProviders,
|
||||
IEnumerable<IFeedItemBuilder> feedItemBuilders) {
|
||||
_feedQueryProviders = feedQueryProviders;
|
||||
_feedFormatProviders = feedFormatProviders;
|
||||
@@ -30,14 +30,14 @@ namespace Orchard.Core.Feeds.Controllers {
|
||||
|
||||
var bestFormatterMatch = _feedFormatProviders
|
||||
.Select(provider => provider.Match(context))
|
||||
.Where(match => match != null && match.FeedFormatter != null)
|
||||
.Where(match => match != null && match.FeedBuilder != null)
|
||||
.OrderByDescending(match => match.Priority)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (bestFormatterMatch == null || bestFormatterMatch.FeedFormatter == null)
|
||||
if (bestFormatterMatch == null || bestFormatterMatch.FeedBuilder == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
context.FeedFormatter = bestFormatterMatch.FeedFormatter;
|
||||
context.Builder = bestFormatterMatch.FeedBuilder;
|
||||
|
||||
var bestQueryMatch = _feedQueryProviders
|
||||
.Select(provider => provider.Match(context))
|
||||
@@ -48,7 +48,7 @@ namespace Orchard.Core.Feeds.Controllers {
|
||||
if (bestQueryMatch == null || bestQueryMatch.FeedQuery == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
return context.FeedFormatter.Process(context, () => {
|
||||
return context.Builder.Process(context, () => {
|
||||
bestQueryMatch.FeedQuery.Execute(context);
|
||||
_feedItemBuilders.Invoke(x => x.Populate(context), Logger);
|
||||
foreach (var contextualizer in context.Response.Contextualizers) {
|
||||
|
@@ -1,10 +1,9 @@
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Feeds.Models;
|
||||
|
||||
namespace Orchard.Core.Feeds {
|
||||
public interface IFeedFormatter {
|
||||
public interface IFeedBuilder {
|
||||
ActionResult Process(FeedContext context, Action populate);
|
||||
|
||||
FeedItem<TItem> AddItem<TItem>(FeedContext context, TItem contentItem);
|
12
src/Orchard.Web/Core/Feeds/IFeedBuilderProvider.cs
Normal file
12
src/Orchard.Web/Core/Feeds/IFeedBuilderProvider.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Orchard.Core.Feeds.Models;
|
||||
|
||||
namespace Orchard.Core.Feeds {
|
||||
public interface IFeedBuilderProvider : IDependency {
|
||||
FeedBuilderMatch Match(FeedContext context);
|
||||
}
|
||||
|
||||
public class FeedBuilderMatch {
|
||||
public int Priority { get; set; }
|
||||
public IFeedBuilder FeedBuilder { get; set; }
|
||||
}
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
using Orchard.Core.Feeds.Models;
|
||||
|
||||
namespace Orchard.Core.Feeds {
|
||||
public interface IFeedFormatterProvider : IDependency {
|
||||
FeedFormatterMatch Match(FeedContext context);
|
||||
}
|
||||
|
||||
public class FeedFormatterMatch {
|
||||
public int Priority { get; set; }
|
||||
public IFeedFormatter FeedFormatter { get; set; }
|
||||
}
|
||||
}
|
@@ -13,6 +13,6 @@ namespace Orchard.Core.Feeds.Models {
|
||||
public string Format { get; set; }
|
||||
public FeedResponse Response { get; set; }
|
||||
|
||||
public IFeedFormatter FeedFormatter { get; set; }
|
||||
public IFeedBuilder Builder { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -1,18 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Mvc;
|
||||
using System.Xml.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Feeds.Models;
|
||||
|
||||
namespace Orchard.Core.Feeds.Rss {
|
||||
[UsedImplicitly]
|
||||
public class RssFeedFormatProvider : IFeedFormatterProvider, IFeedFormatter {
|
||||
public FeedFormatterMatch Match(FeedContext context) {
|
||||
public class RssFeedBuilder : IFeedBuilderProvider, IFeedBuilder {
|
||||
public FeedBuilderMatch Match(FeedContext context) {
|
||||
if (context.Format == "rss") {
|
||||
return new FeedFormatterMatch {
|
||||
FeedFormatter = this,
|
||||
return new FeedBuilderMatch {
|
||||
FeedBuilder = this,
|
||||
Priority = -5
|
||||
};
|
||||
}
|
@@ -1,10 +1,11 @@
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Mvc.Filters;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
||||
|
||||
namespace Orchard.Core.Feeds.Services {
|
||||
[UsedImplicitly]
|
||||
public class FeedFilter : FilterProvider, IResultFilter {
|
||||
private readonly IFeedManager _feedManager;
|
||||
|
||||
|
@@ -3,10 +3,12 @@ using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using System.Xml.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Feeds.Models;
|
||||
|
||||
namespace Orchard.Core.Feeds.Services {
|
||||
namespace Orchard.Core.Feeds.StandardBuilders {
|
||||
[UsedImplicitly]
|
||||
public class CorePartsFeedItemBuilder : IFeedItemBuilder {
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly RouteCollection _routes;
|
||||
@@ -32,30 +34,30 @@ namespace Orchard.Core.Feeds.Services {
|
||||
var link = new XElement("link");
|
||||
var guid = new XElement("guid", new XAttribute("isPermaLink", "true"));
|
||||
|
||||
context.Response.Contextualize(requestContext => {
|
||||
var urlHelper = new UrlHelper(requestContext, _routes);
|
||||
link.Add(urlHelper.RouteUrl(inspector.Link));
|
||||
guid.Add(urlHelper.RouteUrl(inspector.Link));
|
||||
});
|
||||
|
||||
feedItem.Element.SetElementValue("title", inspector.Title);
|
||||
feedItem.Element.Add(link);
|
||||
feedItem.Element.SetElementValue("description", inspector.Description);
|
||||
if (inspector.PublishedUtc != null)
|
||||
feedItem.Element.SetElementValue("pubDate", inspector.PublishedUtc);//TODO: format
|
||||
feedItem.Element.Add(guid);
|
||||
|
||||
context.Response.Contextualize(requestContext => {
|
||||
var urlHelper = new UrlHelper(requestContext, _routes);
|
||||
link.Add(urlHelper.RouteUrl(inspector.Link));
|
||||
guid.Add(urlHelper.RouteUrl(inspector.Link));
|
||||
});
|
||||
}
|
||||
else {
|
||||
var feedItem1 = feedItem;
|
||||
context.Response.Contextualize(requestContext => {
|
||||
var urlHelper = new UrlHelper(requestContext, _routes);
|
||||
context.FeedFormatter.AddProperty(context, feedItem1, "published-date", urlHelper.RouteUrl(inspector.Link));
|
||||
});
|
||||
context.FeedFormatter.AddProperty(context, feedItem, "title", inspector.Title);
|
||||
context.FeedFormatter.AddProperty(context, feedItem, "description", inspector.Description);
|
||||
var urlHelper = new UrlHelper(requestContext, _routes);
|
||||
context.Builder.AddProperty(context, feedItem1, "link", urlHelper.RouteUrl(inspector.Link));
|
||||
});
|
||||
context.Builder.AddProperty(context, feedItem, "title", inspector.Title);
|
||||
context.Builder.AddProperty(context, feedItem, "description", inspector.Description);
|
||||
|
||||
if (inspector.PublishedUtc != null)
|
||||
context.FeedFormatter.AddProperty(context, feedItem, "published-date", Convert.ToString(inspector.PublishedUtc)); // format? cvt to generic T?
|
||||
context.Builder.AddProperty(context, feedItem, "published-date", Convert.ToString(inspector.PublishedUtc)); // format? cvt to generic T?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@ using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Aspects;
|
||||
using Orchard.Core.Common.Models;
|
||||
|
||||
namespace Orchard.Core.Feeds.Services {
|
||||
namespace Orchard.Core.Feeds.StandardBuilders {
|
||||
public class ItemInspector {
|
||||
private readonly IContent _item;
|
||||
private readonly ContentItemMetadata _metadata;
|
||||
|
@@ -5,7 +5,7 @@ using Orchard.ContentManagement;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Core.Common.Records;
|
||||
using Orchard.Core.Feeds.Models;
|
||||
using Orchard.Core.Feeds.Services;
|
||||
using Orchard.Core.Feeds.StandardBuilders;
|
||||
|
||||
namespace Orchard.Core.Feeds.StandardQueries {
|
||||
[UsedImplicitly]
|
||||
@@ -50,11 +50,11 @@ namespace Orchard.Core.Feeds.StandardQueries {
|
||||
});
|
||||
}
|
||||
else {
|
||||
context.FeedFormatter.AddProperty(context, null, "title", inspector.Title);
|
||||
context.FeedFormatter.AddProperty(context, null, "description", inspector.Description);
|
||||
context.Builder.AddProperty(context, null, "title", inspector.Title);
|
||||
context.Builder.AddProperty(context, null, "description", inspector.Description);
|
||||
context.Response.Contextualize(requestContext => {
|
||||
var urlHelper = new UrlHelper(requestContext);
|
||||
context.FeedFormatter.AddProperty(context, null, "link", urlHelper.RouteUrl(inspector.Link));
|
||||
context.Builder.AddProperty(context, null, "link", urlHelper.RouteUrl(inspector.Link));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace Orchard.Core.Feeds.StandardQueries {
|
||||
.Slice(0, limit);
|
||||
|
||||
foreach (var item in items) {
|
||||
context.FeedFormatter.AddItem(context, item);
|
||||
context.Builder.AddItem(context, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -91,15 +91,15 @@
|
||||
<Compile Include="Feeds\StandardBuilders\ItemInspector.cs" />
|
||||
<Compile Include="Feeds\StandardQueries\ContainerFeedQuery.cs" />
|
||||
<Compile Include="Feeds\StandardBuilders\CorePartsFeedItemBuilder.cs" />
|
||||
<Compile Include="Feeds\IFeedFormatter.cs" />
|
||||
<Compile Include="Feeds\IFeedFormatterProvider.cs" />
|
||||
<Compile Include="Feeds\IFeedBuilder.cs" />
|
||||
<Compile Include="Feeds\IFeedBuilderProvider.cs" />
|
||||
<Compile Include="Feeds\IFeedQuery.cs" />
|
||||
<Compile Include="Feeds\IFeedQueryProvider.cs" />
|
||||
<Compile Include="Feeds\IFeedItemBuilder.cs" />
|
||||
<Compile Include="Feeds\Models\FeedContext.cs" />
|
||||
<Compile Include="Feeds\Models\FeedItem.cs" />
|
||||
<Compile Include="Feeds\Models\FeedResponse.cs" />
|
||||
<Compile Include="Feeds\Rss\RssFeedFormat.cs" />
|
||||
<Compile Include="Feeds\Rss\RssFeedBuilder.cs" />
|
||||
<Compile Include="Feeds\Rss\RssResult.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Scheduling\Records\ScheduledTaskRecord.cs" />
|
||||
|
@@ -2,14 +2,16 @@
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using System.Xml.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Comments.Models;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Feeds;
|
||||
using Orchard.Core.Feeds.Models;
|
||||
using Orchard.Core.Feeds.Services;
|
||||
using Orchard.Core.Feeds.StandardBuilders;
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.Comments.Feeds {
|
||||
[UsedImplicitly]
|
||||
public class CommentFeedItemBuilder : IFeedItemBuilder {
|
||||
private readonly IContentManager _contentManager;
|
||||
|
||||
@@ -31,10 +33,7 @@ namespace Orchard.Comments.Feeds {
|
||||
|
||||
var title = T("Comment on {0} by {1}", commentedOnInspector.Title, comment.Author);
|
||||
|
||||
//var inspector = new CommentInspector(
|
||||
// feedItem.Item,
|
||||
// _contentManager.GetItemMetadata(feedItem.Item));
|
||||
|
||||
|
||||
// add to known formats
|
||||
if (context.Format == "rss") {
|
||||
var link = new XElement("link");
|
||||
@@ -55,12 +54,12 @@ namespace Orchard.Comments.Feeds {
|
||||
var feedItem1 = feedItem;
|
||||
context.Response.Contextualize(requestContext => {
|
||||
var urlHelper = new UrlHelper(requestContext);
|
||||
context.FeedFormatter.AddProperty(context, feedItem1, "published-date", urlHelper.RouteUrl(commentedOnInspector.Link));
|
||||
context.Builder.AddProperty(context, feedItem1, "link", urlHelper.RouteUrl(commentedOnInspector.Link));
|
||||
});
|
||||
context.FeedFormatter.AddProperty(context, feedItem, "title", title.ToString());
|
||||
context.FeedFormatter.AddProperty(context, feedItem, "description", comment.CommentText);
|
||||
context.Builder.AddProperty(context, feedItem, "title", title.ToString());
|
||||
context.Builder.AddProperty(context, feedItem, "description", comment.CommentText);
|
||||
|
||||
context.FeedFormatter.AddProperty(context, feedItem, "published-date", Convert.ToString(comment.CommentDate)); // format? cvt to generic T?
|
||||
context.Builder.AddProperty(context, feedItem, "published-date", Convert.ToString(comment.CommentDate)); // format? cvt to generic T?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,35 @@
|
||||
using System.Linq;
|
||||
using Orchard.Comments.Models;
|
||||
using Orchard.Core.Common.Records;
|
||||
using Orchard.Core.Feeds;
|
||||
using Orchard.Core.Feeds.Models;
|
||||
using Orchard.Data;
|
||||
|
||||
namespace Orchard.Comments.Feeds {
|
||||
public class CommentScopeFeedQuery : IFeedQueryProvider, IFeedQuery {
|
||||
private readonly IRepository<CommonRecord> _commonRepository;
|
||||
private readonly IRepository<Comment> _commentRepository;
|
||||
|
||||
public CommentScopeFeedQuery(
|
||||
IRepository<CommonRecord> commonRepository,
|
||||
IRepository<Comment> commentRepository) {
|
||||
_commonRepository = commonRepository;
|
||||
_commentRepository = commentRepository;
|
||||
}
|
||||
|
||||
public FeedQueryMatch Match(FeedContext context) {
|
||||
if (context.ValueProvider.ContainsPrefix("commentscopeid")) {
|
||||
return new FeedQueryMatch { Priority = -1, FeedQuery = this };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Execute(FeedContext context) {
|
||||
var scopeContainerId = (int)context.ValueProvider.GetValue("commentscopeid").ConvertTo(typeof (int));
|
||||
_commonRepository.Fetch(x => x.Container.Id == scopeContainerId).Select(x => x.Id);
|
||||
var comments = _commentRepository.Fetch(x=>x.)
|
||||
context.FeedFormatter.AddItem(context, new Comment());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -15,7 +15,7 @@ namespace Orchard.Comments.Feeds {
|
||||
}
|
||||
|
||||
public FeedQueryMatch Match(FeedContext context) {
|
||||
if (context.ValueProvider.ContainsPrefix("commentedoncontainer")) {
|
||||
if (context.ValueProvider.GetValue("commentedoncontainer") != null) {
|
||||
return new FeedQueryMatch { Priority = -1, FeedQuery = this };
|
||||
}
|
||||
return null;
|
||||
@@ -35,7 +35,7 @@ namespace Orchard.Comments.Feeds {
|
||||
0, limit);
|
||||
|
||||
foreach (var comment in comments) {
|
||||
context.FeedFormatter.AddItem(context, comment);
|
||||
context.Builder.AddItem(context, comment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ namespace Orchard.Comments.Feeds {
|
||||
}
|
||||
|
||||
public FeedQueryMatch Match(FeedContext context) {
|
||||
if (context.ValueProvider.ContainsPrefix("commentedon")) {
|
||||
if (context.ValueProvider.GetValue("commentedon") != null) {
|
||||
return new FeedQueryMatch { Priority = -1, FeedQuery = this };
|
||||
}
|
||||
return null;
|
||||
@@ -35,7 +35,7 @@ namespace Orchard.Comments.Feeds {
|
||||
0, limit);
|
||||
|
||||
foreach (var comment in comments) {
|
||||
context.FeedFormatter.AddItem(context, comment);
|
||||
context.Builder.AddItem(context, comment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user