Add RSS Support to Build Server

This commit is contained in:
Christoph Wille 2013-06-13 12:53:44 +02:00
Родитель 4d87fe5862
Коммит 36c8659c16
5 изменённых файлов: 94 добавлений и 6 удалений

Просмотреть файл

@ -44,6 +44,7 @@
<Reference Include="System.Data" />
<Reference Include="System.Data.Entity" />
<Reference Include="System.Drawing" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Web.DynamicData" />
<Reference Include="System.Web.Entity" />
<Reference Include="System.Web.ApplicationServices" />
@ -135,7 +136,9 @@
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="App_Start\WebApiConfig.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Controllers\RssController.cs" />
<Compile Include="Data\ArtefactRepository.cs" />
<Compile Include="FeedResult.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>

Просмотреть файл

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ArtefactsSite.Data;
@ -33,6 +32,5 @@ namespace ArtefactsSite.Controllers
return View(vm);
}
}
}

Просмотреть файл

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Linq;
using System.ServiceModel.Syndication;
using ArtefactsSite.Data;
namespace ArtefactsSite.Controllers
{
public class RssController : Controller
{
public ActionResult For(string id)
{
var defs = MvcApplication.BuildDefinitions;
var currentDef = defs.FirstOrDefault(d => 0 == String.Compare(d.Anchor, id, StringComparison.InvariantCultureIgnoreCase));
if (null == currentDef)
{
return HttpNotFound();
}
var artefacts = ArtefactRepository.GetFileListing(currentDef.ArtefactQuery);
var leftpart = Request.Url.GetLeftPart(UriPartial.Authority);
var postItems = artefacts.Select(p => new SyndicationItem(p.FileName, "", new Uri(leftpart + Url.Content("~/" + p.FileName))));
var feed = new SyndicationFeed(currentDef.Title, "SharpDevelop Build Server Automated Feed", new Uri(Request.Url.AbsoluteUri), postItems)
{
Copyright = new TextSyndicationContent("(c) SharpDevelop Team"),
Language = "en-US"
};
return new FeedResult(new Rss20FeedFormatter(feed));
}
}
}

Просмотреть файл

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.Syndication;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Xml;
namespace ArtefactsSite
{
// http://damieng.com/blog/2010/04/26/creating-rss-feeds-in-asp-net-mvc
public class FeedResult : ActionResult
{
public Encoding ContentEncoding { get; set; }
public string ContentType { get; set; }
private readonly SyndicationFeedFormatter feed;
public SyndicationFeedFormatter Feed
{
get { return feed; }
}
public FeedResult(SyndicationFeedFormatter feed)
{
this.feed = feed;
}
public override void ExecuteResult(ControllerContext context)
{
if (context == null)
throw new ArgumentNullException("context");
HttpResponseBase response = context.HttpContext.Response;
response.ContentType = !string.IsNullOrEmpty(ContentType) ? ContentType : "application/rss+xml";
if (ContentEncoding != null)
response.ContentEncoding = ContentEncoding;
if (feed != null)
using (var xmlWriter = new XmlTextWriter(response.Output))
{
xmlWriter.Formatting = Formatting.Indented;
feed.WriteTo(xmlWriter);
}
}
}
}

Просмотреть файл

@ -16,13 +16,13 @@ by editing this MSBuild file. In order to learn more about this please visit htt
<publishTime>02/12/2013 13:16:02</publishTime>
</File>
<File Include="bin/App_global.asax.compiled">
<publishTime>05/20/2013 17:22:35</publishTime>
<publishTime>06/13/2013 12:51:38</publishTime>
</File>
<File Include="bin/App_global.asax.dll">
<publishTime>05/20/2013 17:22:35</publishTime>
<publishTime>06/13/2013 12:51:38</publishTime>
</File>
<File Include="bin/ArtefactsSite.dll">
<publishTime>05/20/2013 17:22:31</publishTime>
<publishTime>06/13/2013 12:51:35</publishTime>
</File>
<File Include="bin/EntityFramework.dll">
<publishTime>02/12/2013 13:15:35</publishTime>
@ -283,7 +283,7 @@ by editing this MSBuild file. In order to learn more about this please visit htt
<publishTime>02/12/2013 13:53:26</publishTime>
</File>
<File Include="PrecompiledApp.config">
<publishTime>05/20/2013 17:22:33</publishTime>
<publishTime>06/13/2013 12:51:36</publishTime>
</File>
<File Include="Scripts/bootstrap.js">
<publishTime>02/12/2013 13:53:04</publishTime>