- vs2008messageboard_src.zip
- VS2008MessageBoard_src
- MessageBoard
- MessageBoard.Core
- MessageBoard.DataAccess.Linq
- MessageBoard.DataAccess.NonLinq
- MessageBoard.sln
- MessageBoard.vsmdi
- MessageBoard.Web
- MessageBoard.Word
- MessageBoard
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Syndication;
using MessageBoard.Web.Properties;
using System.Web;
using System.Globalization;
namespace MessageBoard.Web
{
// NOTE: If you change the class name "FeedService" here, you must also update the reference to "FeedService" in App.config.
public class FeedService : IFeedService
{
#region IFeedService Members
public SyndicationFeedFormatter GetLatestMessages(FeedFormat format)
{
Uri rootUri = GetRootUri();
SyndicationFeed feed = new SyndicationFeed(Resources.MessageBoard, Resources.MessageBoardDescription, rootUri);
feed.Items = from m in MessageSource.GetRecentMessages(0, 10)
select CreateSyndicationItem(m, rootUri);
if(format == FeedFormat.Atom)
return new Atom10FeedFormatter(feed);
return new Rss20FeedFormatter(feed);
}
#endregion
private SyndicationItem CreateSyndicationItem(Message m, Uri rootUri)
{
UriBuilder uriBuilder = new UriBuilder(rootUri);
uriBuilder.Path += "Message.aspx";
uriBuilder.Query = "id=" + m.Id.ToString(CultureInfo.InvariantCulture);
var item = new SyndicationItem(m.Subject, m.Text, uriBuilder.Uri, m.Id.ToString(), new DateTimeOffset(m.DatePosted, new TimeSpan(0)));
item.Authors.Add(new SyndicationPerson(m.PostedBy));
return item;
}
private Uri GetRootUri()
{
Uri uri = OperationContext.Current.Channel.LocalAddress.Uri;
UriBuilder builder = new UriBuilder(uri);
StringBuilder pathBuilder = new StringBuilder(builder.Path);
int indexOfSlash = builder.Path.LastIndexOf('/');
pathBuilder.Remove(indexOfSlash, builder.Path.Length - indexOfSlash);
builder.Path = pathBuilder.ToString();
return builder.Uri;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.