本文整理汇总了C#中System.ServiceModel.Syndication.Rss20FeedFormatter类的典型用法代码示例。如果您正苦于以下问题:C# Rss20FeedFormatter类的具体用法?C# Rss20FeedFormatter怎么用?C# Rss20FeedFormatter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Rss20FeedFormatter类属于System.ServiceModel.Syndication命名空间,在下文中一共展示了Rss20FeedFormatter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFeeds
public static IList<Feed> GetFeeds()
{
var urls = new[]
{
"http://www.simplyvinay.com/GetBlogRss.aspx", "http://www.bbc.co.uk/blogs/formula1/rss.xml",
"http://feeds.feedburner.com/AyendeRahien"
};
var list = new List<Feed>();
foreach (var url in urls)
{
using (var reader = new CustomXmlReader(url))
{
if (reader.ReadState == ReadState.Initial)
reader.MoveToContent();
var atom = new Atom10FeedFormatter();
if (atom.CanRead(reader))
{
atom.ReadFrom(reader);
list.AddRange(GenerateFeed(atom.Feed, true));
}
var rss = new Rss20FeedFormatter();
if (rss.CanRead(reader))
{
rss.ReadFrom(reader);
list.AddRange(GenerateFeed(rss.Feed, false));
}
}
}
return list;
}
示例2: WriteFile
protected override void WriteFile(System.Web.HttpResponseBase response)
{
var items = new List<SyndicationItem>();
foreach (Dinner d in this.Dinners)
{
string contentString = String.Format("{0} with {1} on {2:MMM dd, yyyy} at {3}. Where: {4}, {5}",
d.Description, d.HostedBy, d.EventDate, d.EventDate.ToShortTimeString(), d.Address, d.Country);
var item = new SyndicationItem(
title: d.Title,
content: contentString,
itemAlternateLink: new Uri("http://nrddnr.com/" + d.DinnerID),
id: "http://nrddnr.com/" + d.DinnerID,
lastUpdatedTime: d.EventDate.ToUniversalTime()
);
item.PublishDate = d.EventDate.ToUniversalTime();
item.Summary = new TextSyndicationContent(contentString, TextSyndicationContentKind.Plaintext);
items.Add(item);
}
SyndicationFeed feed = new SyndicationFeed(
this.Title,
this.Title, /* Using Title also as Description */
currentUrl,
items);
Rss20FeedFormatter formatter = new Rss20FeedFormatter(feed);
using (XmlWriter writer = XmlWriter.Create(response.Output))
{
formatter.WriteTo(writer);
}
}
示例3: CreateFeed
public SyndicationFeedFormatter CreateFeed()
{
// Créez un flux RSS.
SyndicationFeed feed = new SyndicationFeed("Bug Track", "Flux rss du bug track", null);
List<SyndicationItem> items = new List<SyndicationItem>();
// Créez un article RSS.
List<DBO.Bug> bugs = DataAccess.Bug.GetLastBug(10);
bugs.ForEach(bug => items.Add(new SyndicationItem(bug.Title, bug.Details, null)));
feed.Items = items;
// Renvoie ATOM ou RSS en fonction de la chaîne de requête
// rss -> http://localhost:8733/Design_Time_Addresses/SyndicationServiceBugTrack/Feed1/
// atom -> http://localhost:8733/Design_Time_Addresses/SyndicationServiceBugTrack/Feed1/?format=atom
string query = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["format"];
SyndicationFeedFormatter formatter = null;
if (query == "atom")
{
formatter = new Atom10FeedFormatter(feed);
}
else
{
formatter = new Rss20FeedFormatter(feed);
}
return formatter;
}
示例4: GetJobs
public SyndicationFeedFormatter GetJobs(string format)
{
var groups = _Scheduler.GetJobGroupNames();
SyndicationFeed feed = new SyndicationFeed();
List<SyndicationItem> items = new List<SyndicationItem>();
foreach (var group in groups)
{
var jobKeys = _Scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupEquals(group));
foreach (var jobKey in jobKeys)
{
var job = _Scheduler.GetJobDetail(jobKey);
SyndicationItem item = new SyndicationItem();
item.Id = job.Key.ToString();
item.LastUpdatedTime = DateTime.UtcNow;
item.Title = new TextSyndicationContent(string.Format("{0} - {1}", job.Key.Group, job.Key.Name), TextSyndicationContentKind.Plaintext);
item.Summary = new TextSyndicationContent(string.Format("Job {0} for group {1}.", job.Key.Name, job.Key.Group), TextSyndicationContentKind.Plaintext);
items.Add(item);
}
}
feed.Items = items;
SyndicationFeedFormatter formatter = new Rss20FeedFormatter(feed);
return formatter;
}
示例5: Index
public async Task<ActionResult> Index()
{
var posts = await Task.Run(() => MvcApplication.Posts);
var feed = new SyndicationFeed("invokecommand.net", "All blog posts", new Uri(this.ServerUrl("/rss.xml")), "1", DateTime.Now)
{
Items = posts.Select(
post => new SyndicationItem(
post.Title,
post.Summary,
new Uri(this.ServerUrl(post.Url.ToString())),
post.Name,
post.Published))
.ToList()
};
var formatter = new Rss20FeedFormatter(feed);
var content = new StringBuilder();
using (var writer = XmlWriter.Create(content))
{
formatter.WriteTo(writer);
writer.Flush();
}
return Content(content.ToString(), "text/xml");
}
示例6: ExecuteResult
public override void ExecuteResult(ControllerContext context)
{
SyndicationFeedFormatter formatter;
string contentType;
switch (_feedType)
{
case FeedType.Atom:
formatter = new Atom10FeedFormatter(_syndicationFeed);
contentType = "application/atom+xml";
break;
case FeedType.Rss:
formatter = new Rss20FeedFormatter(_syndicationFeed);
contentType = "application/rss+xml";
break;
default:
throw new NotImplementedException("Feed type not accounted for");
}
context.HttpContext.Response.ContentType = contentType;
using (var writer = XmlWriter.Create(context.HttpContext.Response.Output))
{
formatter.WriteTo(writer);
}
}
示例7: Page_Load
protected void Page_Load(object sender, System.EventArgs e)
{
List<SyndicationItem> syndicationItems = new List<SyndicationItem>();
IList<Card> cards = uWiMP.TVServer.Cards.GetCards();
foreach (Card card in cards)
{
if (card.Enabled & card.Name.ToLower().Contains("builtin"))
{
uWiMP.TVServer.Cards.Status status = uWiMP.TVServer.Cards.GetCardStatus(card);
SyndicationItem si = new SyndicationItem();
si.Title = new TextSyndicationContent("Recording");
}
}
SyndicationFeed feed = new SyndicationFeed(syndicationItems);
StringWriter output = new StringWriter();
XmlTextWriter writer = new XmlTextWriter(output);
Rss20FeedFormatter f = new Rss20FeedFormatter(feed);
f.WriteTo(writer);
Context.Response.ContentType = "application/rss+xml";
Context.Response.Write(output.ToString());
}
示例8: ExecuteResult
public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.ContentType = "application/atom+xml";
//check request is for Atom or RSS
if (context.HttpContext.Request.QueryString["type"] != null && context.HttpContext.Request.QueryString["type"].ToString().ToLower() == "atom")
{
//Atom Feed
context.HttpContext.Response.ContentType = "application/atom+xml";
var rssFormatter = new Atom10FeedFormatter(FeedData);
using (XmlWriter writer = XmlWriter.Create(context.HttpContext.Response.Output, new XmlWriterSettings { Indent = true }))
{
rssFormatter.WriteTo(writer);
}
}
else
{
//RSS Feed
context.HttpContext.Response.ContentType = "application/rss+xml";
var rssFormatter = new Rss20FeedFormatter(FeedData);
using (XmlWriter writer = XmlWriter.Create(context.HttpContext.Response.Output, new XmlWriterSettings { Indent = true }))
{
rssFormatter.WriteTo(writer);
}
}
}
示例9: CreateFeed
public SyndicationFeedFormatter CreateFeed()
{
// Create a new Syndication Feed.
SyndicationFeed feed = new SyndicationFeed("Feed Title", "A WCF Syndication Feed", null);
List<SyndicationItem> items = new List<SyndicationItem>();
// Create a new Syndication Item.
SyndicationItem item = new SyndicationItem("An item", "Item content", null);
items.Add(item);
feed.Items = items;
// Return ATOM or RSS based on query string
// rss -> http://localhost:8733/Design_Time_Addresses/SyndicationServiceLibrary1/Feed1/
// atom -> http://localhost:8733/Design_Time_Addresses/SyndicationServiceLibrary1/Feed1/?format=atom
string query = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["format"];
SyndicationFeedFormatter formatter = null;
if (query == "atom")
{
formatter = new Atom10FeedFormatter(feed);
}
else
{
formatter = new Rss20FeedFormatter(feed);
}
return formatter;
}
示例10: getXmlContent
private Action<Stream> getXmlContent(IEnumerable<BlogPost> model)
{
var items = model.Select(post =>
new SyndicationItem(
title: post.Title,
content: post.Content,
itemAlternateLink: new Uri(BaseUrl + post.GetLink().TrimStart('/')),
id: post.Id,
lastUpdatedTime: post.PubDate)
{
PublishDate = post.PubDate,
Summary = new TextSyndicationContent(post.Content, TextSyndicationContentKind.Html)
})
.ToList();
var feed = new SyndicationFeed(RssTitle, RssTitle, BaseUrl, items);
var formatter = new Rss20FeedFormatter(feed);
return stream =>
{
using (var writer = XmlWriter.Create(stream))
{
formatter.WriteTo(writer);
}
};
}
示例11: ParseXml
/// <summary>
/// Wybiera stronę na podstawie adresu url i zapisuje wszystkie wiadomości w kolekcji
/// </summary>
/// <param name="lineNews">Lista wiadomości</param>
/// <param name="category">Kategoria źródłowa do odczytu</param>
public void ParseXml(ObservableCollection<News> lineNews, Category category)
{
try
{
using (XmlReader reader = XmlReader.Create(category.Url))
{
var formatter = new Rss20FeedFormatter();
formatter.ReadFrom(reader);
foreach (var item in formatter.Feed.Items)
{
lineNews.Add(new News
{
Title = item.Title.Text,
Date = item.PublishDate.DateTime.ToString(),
UrlNews = item.Links.First().Uri.ToString(),
Description = item.Summary.Text,
Category = category.Name,
Id = item.Id
});
if (item.Links.Count > 1 && item.Links.Any(n => n.Uri.ToString().Contains(".jpg")))
lineNews.Last().UrlImage = item.Links[1].Uri.ToString();
ParseId(lineNews.Last());
ParseDescription(lineNews.Last());
}
}
}
catch (WebException ex)
{
MessageBox.Show(ex.Message, "Syndication Reader");
}
}
示例12: GetRssFeedItems
public static List<SyndicationItem> GetRssFeedItems(string url)
{
Rss20FeedFormatter formatter = new Rss20FeedFormatter();
XmlReader reader;
try
{
reader = XmlReader.Create(url);
formatter.ReadFrom(reader);
}
catch(XmlException xexp)
{
string xml;
using (WebClient webClient = new WebClient())
{
xml = Encoding.UTF8.GetString(webClient.DownloadData(url));
}
xml = xml.Replace("BST", "+0100");
xml = xml.Replace("GMT", "+0000");
byte[] bytes = System.Text.UTF8Encoding.ASCII.GetBytes(xml);
reader = XmlReader.Create(new MemoryStream(bytes));
formatter.ReadFrom(reader);
}
reader.Close();
return formatter.Feed == null ? null : formatter.Feed.Items.ToList();
}
示例13: CreateFeed
public SyndicationFeedFormatter CreateFeed()
{
string serverUrl = ConfigurationManager.AppSettings["CatMyVideoUrl"];
// Create a new Syndication Feed.
SyndicationFeed feed = new SyndicationFeed();
feed.Id = "#CatMyVideo URL";
List<SyndicationItem> items = new List<SyndicationItem>();
feed.Title = new TextSyndicationContent("Last trends on CatMyVideo");
feed.Description = new TextSyndicationContent(String.Format("Todays' top {0} hottest videos on CatMyVideo", MAXVIDEO));
feed.Copyright = new TextSyndicationContent("Copy/Paste rights CatMyVideo");
feed.Generator = "CatMyVideo RSS Feeder 1.0";
feed.Authors.Add(new SyndicationPerson("[email protected]"));
feed.LastUpdatedTime = new DateTimeOffset(DateTime.Now);
var trendingVideos = Engine.BusinessManagement.Video.ListVideos(Engine.Dbo.Video.Order.UploadDate, false, MAXVIDEO, 0, true);
for (int i = 0; i < trendingVideos.Count; i++)
{
SyndicationItem item = new SyndicationItem();
string itemUrl = serverUrl + "/Video/Display/" + trendingVideos[i].Id;
item.Id = itemUrl;
var itemLink = new SyndicationLink(new Uri(itemUrl));
itemLink.MediaType = "text/html";
itemLink.Title = "Watch me !";
item.Links.Add(itemLink);
string htmlContent = String.Format("<!DOCTYPE html><html><head></head><body><h1>{0}</h1><p>{1}</p><a href=\"{2}\">Check this out !</a></body></html>",
trendingVideos[i].Title,
trendingVideos[i].Description,
itemUrl);
TextSyndicationContent content = new TextSyndicationContent(htmlContent, TextSyndicationContentKind.Html);
// Fill some properties for the item
item.Title = new TextSyndicationContent("#" + (i + 1));
item.LastUpdatedTime = DateTime.Now;
item.PublishDate = trendingVideos[i].UploadDate;
item.Content = content;
items.Add(item);
}
feed.Items = items;
string query = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["format"];
SyndicationFeedFormatter formatter = null;
if (query == "atom")
{
formatter = new Atom10FeedFormatter(feed);
}
else
{
formatter = new Rss20FeedFormatter(feed);
}
return formatter;
}
示例14: FilterFeed
public Rss20FeedFormatter FilterFeed(Rss20FeedFormatter formatterFeed, IEnumerable<string> tags)
{
var feed = new SyndicationFeed() {Title = new TextSyndicationContent("Service Feed")};
var result = new Rss20FeedFormatter(feed);
result.Feed.Items = FilterItemsInFeedByTags(formatterFeed.Feed.Items, tags);
return result;
}
示例15: fload
public void fload(string namefile)
{
var lines = System.IO.File.ReadAllLines(namefile);
feed.Title = new TextSyndicationContent(lines[1]);
feed.Copyright = new TextSyndicationContent(lines[2]);
feed.Description = new TextSyndicationContent(lines[3]);
feed.Generator = lines[4];
SyndicationLink link = new SyndicationLink();
link.Uri = new Uri(lines[5]);
feed.Links.Add(link);
feed.Items = txtgotolv("feedinfo.txt");
Response.Clear();
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "text/xml";
XmlWriter Writer = XmlWriter.Create
(Response.Output);
if (lines[0] == "rss")
{
Rss20FeedFormatter Formatter = new Rss20FeedFormatter(feed);
Formatter.WriteTo(Writer);
}
else
{
if (lines[0] == "atom")
{
Atom10FeedFormatter Formatter = new Atom10FeedFormatter(feed);
Formatter.WriteTo(Writer);
}
}
Writer.Close();
Response.End();
}