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:
@@ -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" />
|
||||
|
Reference in New Issue
Block a user