private Action<Stream> GetXmlContents(IEnumerable<Post> model) { var items = new List<SyndicationItem>(); foreach (var post in model) { // Replace all relative urls with full urls. var contentHtml = Regex.Replace(post.Content, UrlRegex, m => siteUrl.TrimEnd('/') + "/" + m.Value.TrimStart('/')); var excerptHtml = Regex.Replace(post.ContentExcerpt, UrlRegex, m => siteUrl.TrimEnd('/') + "/" + m.Value.TrimStart('/')); var item = new SyndicationItem( post.Title, contentHtml, new Uri(siteUrl + post.Url) ) { Id = siteUrl + post.Url, LastUpdatedTime = post.Date.ToUniversalTime(), PublishDate = post.Date.ToUniversalTime(), Content = new TextSyndicationContent(contentHtml, TextSyndicationContentKind.Html), Summary = new TextSyndicationContent(excerptHtml, TextSyndicationContentKind.Html), }; items.Add(item); } var feed = new SyndicationFeed( AtomTitle, AtomTitle, /* Using Title also as Description */ new Uri(siteUrl + "/" + feedfileName), items) { Id = siteUrl + "/", LastUpdatedTime = new DateTimeOffset(DateTime.Now), Generator = "Sandra.Snow Atom Generator" }; feed.Authors.Add(new SyndicationPerson(authorEmail, author, siteUrl)); var link = new SyndicationLink(new Uri(siteUrl + "/" + feedfileName)) { RelationshipType = "self", MediaType = "text/html", Title = AtomTitle }; feed.Links.Add(link); var formatter = new Atom10FeedFormatter(feed); return stream => { var encoding = new UTF8Encoding(false); var streamWrapper = new UnclosableStreamWrapper(stream); using (var writer = new XmlTextWriter(streamWrapper, encoding)) { formatter.WriteTo(writer); } }; }
private static SyndicationFeed GetBlogInformation(string pbaseUrl) { var feed = new SyndicationFeed(); // Add basic blog information feed.Id = pbaseUrl; feed.Title = new TextSyndicationContent("Kestrel Blackmore Blog"); feed.Description = new TextSyndicationContent("Hi, I'm Kestrel. I've been a software developer now for 10+ years and I love it!"); feed.Copyright = new TextSyndicationContent("KestrelBlackmore.com"); feed.LastUpdatedTime = new DateTimeOffset(DateTime.Now); feed.Generator = "BlogMatrix 1.0"; feed.ImageUrl = new Uri(pbaseUrl + "/assets/img/blackmore_logo.png"); // Add the URL that will link to your published feed when it's done SyndicationLink link = new SyndicationLink(new Uri(pbaseUrl + "/feed.xml")); link.RelationshipType = "self"; link.MediaType = "text/html"; link.Title = "Kestrel Blackmore Feed"; feed.Links.Add(link); // Add your site link link = new SyndicationLink(new Uri(pbaseUrl)); link.MediaType = "text/html"; link.Title = "Kestrel Blackmore Blog"; feed.Links.Add(link); return feed; }
public ActionResult Rss(string domain="") { var news = NewsProvider.GetSeason(2014, domain).OrderByDescending(n=>n.Date).Take(10); var feedItems = new List<SyndicationItem>(); foreach (var news_item in news) { var item = new SyndicationItem() { Title = TextSyndicationContent.CreatePlaintextContent(news_item.Title), PublishDate = new DateTimeOffset(news_item.Date), Summary = TextSyndicationContent.CreateHtmlContent(CombineBriefWithImage(news_item)), }; string url = "http://afspb.org.ru/news/" + news_item.Slug; var link = new SyndicationLink(new Uri(url)); link.Title = "Перейти к новости"; item.Links.Add(link); feedItems.Add(item); } var feed = new SyndicationFeed( "Новости сайта Автомобильной Федерации Санкт-Петербурга и Ленинградской области", "", new Uri("http://afspb.org.ru/news/Rss"), feedItems); return new RssResult() { Feed = feed }; }
private static SyndicationFeed GetBlogInformation(string pbaseUrl) { var feed = new SyndicationFeed(); // Add basic blog information feed.Id = pbaseUrl; feed.Title = new TextSyndicationContent("제이키의 ASP.NET MVC 이야기"); feed.Description = new TextSyndicationContent("ASP.NET MVC를 공부하면서 테스트 가능한 웹 애플리케이션을 만들어 봅시다. 테스트를 염두에 두면 유연한 아키텍쳐가 필요하고 좋은 아키텍쳐는 코드 재사용성을 높이고 유지보수를 쉽게 해줍니다."); feed.Copyright = new TextSyndicationContent("류지형 (Jake Ryu)"); feed.LastUpdatedTime = new DateTimeOffset(DateTime.Now); feed.Generator = "JakeyMVC.com"; feed.ImageUrl = new Uri(pbaseUrl + "/assets/img/logo_white.gif"); // Add the URL that will link to your published feed when it's done SyndicationLink link = new SyndicationLink(new Uri(pbaseUrl + "/feed")); link.RelationshipType = "self"; link.MediaType = "text/html"; link.Title = "Jakey MVC Feed"; feed.Links.Add(link); // Add your site link link = new SyndicationLink(new Uri(pbaseUrl)); link.MediaType = "text/html"; link.Title = "JakeyMVC.com"; feed.Links.Add(link); return feed; }
public async Task<IHttpActionResult> GetService(string id) { Service service = await db.Services.FindAsync(id); if (service == null) { return NotFound(); } var ServiceFeed = new SyndicationFeed(); ServiceFeed.Id = service.Id; ServiceFeed.LastUpdatedTime = service.Updated; ServiceFeed.Title = new TextSyndicationContent(service.Title); ServiceFeed.Description = new TextSyndicationContent(service.Summary); ServiceFeed.Categories.Add(new SyndicationCategory(service.ServiceCategoryId.ToString(), null, service.Category.Name)); var SelfLink = new SyndicationLink(); SelfLink.RelationshipType = "self"; SelfLink.Uri = new Uri(Url.Content("~/Service/" + service.Id)); SelfLink.MediaType = "application/atom+xml"; ServiceFeed.Links.Add(SelfLink); var HtmlLink = new SyndicationLink(); HtmlLink.RelationshipType = "self"; HtmlLink.Uri = new Uri("http://surreyhillsdc.azurewebsites.net/"); HtmlLink.MediaType = "text/html"; ServiceFeed.Links.Add(HtmlLink); return Ok(ServiceFeed.GetAtom10Formatter()); }
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(); }
public static SyndicationFeed GetPostFeed() { SyndicationFeed postfeed = Feeds.GetFeed(); postfeed.Title = new TextSyndicationContent("Key Mapper Developer Blog"); postfeed.Description = new TextSyndicationContent("Post feed for the Key Mapper Developer Blog"); Collection<Post> posts = Post.GetAllPosts(CommentType.Approved); List<SyndicationItem> items = new List<SyndicationItem>(); foreach (Post p in posts) { SyndicationItem item = new SyndicationItem(); item.Id = p.Id.ToString(); item.Title = new TextSyndicationContent(p.Title); item.Content = new TextSyndicationContent(p.Body); SyndicationLink itemlink = new SyndicationLink(); itemlink.Title = "Key Mapper Blog"; itemlink.Uri = new Uri("http://justkeepswimming.net/keymapper/default.aspx?p=" + p.Id.ToString() + ".aspx"); item.Links.Add(itemlink); SyndicationPerson person = new SyndicationPerson(); person.Name = "Stuart Dunkeld"; person.Email = "*****@*****.**"; item.Authors.Add(person); items.Add(item); } postfeed.Items = items; return postfeed; }
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("*****@*****.**")); 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; }
public void TestUri () { SyndicationLink link = new SyndicationLink (new Uri ("empty.xml", UriKind.Relative)); link.Uri = null; Assert.IsNull (link.Uri, "#1"); Assert.IsNull (link.GetAbsoluteUri (), "#2"); }
public static SyndicationLink ToSyndicationLink(this Link link) { var syndicationLink = new SyndicationLink(new Uri(link.Url)); link.Rel.IfNotNull(x => syndicationLink.RelationshipType = x); link.Title.IfNotNull(x => syndicationLink.Title = x); link.ContentType.IfNotNull(x => syndicationLink.MediaType = x); return syndicationLink; }
protected SyndicationLink(SyndicationLink source) { if (source == null) throw new ArgumentNullException ("source"); base_uri = source.base_uri; href = source.href; length = source.length; rel = source.rel; title = source.title; type = source.type; extensions = source.extensions.Clone (); }
public JsonSyndicationLink(SyndicationLink link) { if (link != null) { this.Length = link.Length; this.MediaType = link.MediaType; this.RelationshipType = link.RelationshipType; this.Title = link.Title; this.Uri = link.BaseUri; this.Uri = link.Uri; } }
public FeedBuilder AddMoreResultsLink(Uri baseUri, string key, int? page) { var moreresultsuri = string.Format("{0}?key={1}&page={2}", "search", key, page); //TODO: Fix this uri this.moreResultsLink = new SyndicationLink(new Uri(baseUri, moreresultsuri)) { RelationshipType = "next-results" }; return this; }
public void Constructor () { // null Uri is allowed SyndicationLink link = new SyndicationLink (null); link = new SyndicationLink (new Uri ("empty.xml", UriKind.Relative)); Assert.AreEqual ("empty.xml", link.Uri.ToString (), "#1-1"); Assert.AreEqual (null, link.BaseUri, "#1-2"); Assert.AreEqual (0, link.Length, "#1-3"); Assert.AreEqual (null, link.MediaType, "#1-4"); link = new SyndicationLink (null, null, null, null, 0); }
public static SyndicationFeed GetFeed() { SyndicationFeed feed = new SyndicationFeed(); feed.Copyright = new TextSyndicationContent("Copyright (C) Stuart Dunkeld 2008. All rights reserved."); feed.Generator = "ASP.Net 3.5 Syndication classes"; SyndicationLink link = new SyndicationLink(); link.Title = "Key Mapper Home"; link.Uri = new Uri("http://justkeepswimming.net/keymapper"); feed.Links.Add(link); return feed; }
public void CanGetAtomLinkFromSyndicationLink() { // Act SyndicationLink slink = new SyndicationLink(new Uri("http://edit"), "edit", "Edit feed", "text/html", 0); AtomLink link = slink.Link(); // Assert Assert.IsNotNull(link); Assert.AreEqual("http://edit/", link.HRef.AbsoluteUri); Assert.AreEqual("Edit feed", link.Title); Assert.AreEqual("edit", link.RelationType); Assert.AreEqual("text/html", (string)link.MediaType); }
protected SyndicationLink(SyndicationLink source) { if (source == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("source"); } this.length = source.length; this.mediaType = source.mediaType; this.relationshipType = source.relationshipType; this.title = source.title; this.baseUri = source.baseUri; this.uri = source.uri; this.extensions = source.extensions.Clone(); }
public Atom10FeedFormatter GetCollectionFeed(string collectionId) { var collectionProvider = ConfigurationReader.Configuration.CollectionProviders.Where(cp => cp.Name.Equals(collectionId)).FirstOrDefault(); if (collectionProvider == null) return null; IList<SyndicationItem> feedItems = new List<SyndicationItem>(); // create snapshotfeed link var item = new SyndicationItem { Title = new TextSyndicationContent("Snapshot feed for " + collectionId), Id = Guid.NewGuid().ToString(), LastUpdatedTime = DateTime.UtcNow }; var sl = new SyndicationLink(new Uri(collectionId + "/snapshots", UriKind.Relative)) { RelationshipType = SdShareNamespace + "snapshotsfeed", MediaType = "application/atom+xml" }; item.Links.Add(sl); item.Links.Add(new SyndicationLink(new Uri(collectionId + "/snapshots", UriKind.Relative)) { RelationshipType = "alternate", MediaType = "application/atom+xml" }); feedItems.Add(item); // create fragments link item = new SyndicationItem { Title = new TextSyndicationContent("Fragments feed for " + collectionId), Id = Guid.NewGuid().ToString(), LastUpdatedTime = DateTime.UtcNow }; var fl = new SyndicationLink(new Uri(collectionId + "/fragments", UriKind.Relative)) { RelationshipType = SdShareNamespace + "fragmentsfeed", MediaType = "application/atom+xml" }; item.Links.Add(fl); item.Links.Add(new SyndicationLink(new Uri(collectionId + "/fragments", UriKind.Relative)) { RelationshipType = "alternate", MediaType = "application/atom+xml" }); feedItems.Add(item); var feed = new SyndicationFeed(feedItems) { Title = new TextSyndicationContent(collectionId + " Feed"), LastUpdatedTime = DateTime.UtcNow }; return new Atom10FeedFormatter(feed); }
public void TestBaseUri () { // relative SyndicationLink link = new SyndicationLink (new Uri ("empty.xml", UriKind.Relative)); Assert.IsNull (link.BaseUri, "#1"); // absolute link = new SyndicationLink (new Uri ("http://mono-project.com/index.rss")); Assert.IsNull (link.BaseUri, "#2"); // absolute #2 link = new SyndicationLink (); link.Uri = new Uri ("http://mono-project.com/index.rss"); Assert.IsNull (link.BaseUri, "#3"); }
protected void LoadLinks(Collection<SyndicationLink> collection, EntitySet<Link> entitySet) { foreach (Link entity in entitySet) { SyndicationLink s = new SyndicationLink() { BaseUri = !string.IsNullOrEmpty(entity.BaseUri) ? null : new Uri(entity.BaseUri), Length = entity.Length.Value, MediaType = entity.MediaType, RelationshipType = entity.RelationshipType, Title = entity.Title, Uri = !string.IsNullOrEmpty(entity.Uri) ? null : new Uri(entity.Uri) }; LoadAttributes(s.AttributeExtensions, entity.Attributes); LoadElements(s.ElementExtensions, entity.Elements); } }
public HttpResponseMessage<SyndicationItem> Get(string id, HttpRequestMessage request) { Room room; try { room = rooms.Get(int.Parse(id)); } catch (KeyNotFoundException) { throw new HttpResponseException(HttpStatusCode.NotFound); } if (room.IsGuarded(encounters)) { var seeOtherResponse = new HttpResponseMessage {StatusCode = HttpStatusCode.SeeOther}; seeOtherResponse.Headers.Location = new Uri(string.Format("http://" + Environment.MachineName + ":8081/encounters/{0}", room.GetEncounter(encounters).Id)); throw new HttpResponseException(seeOtherResponse); } var entry = new SyndicationItem { BaseUri = new Uri("http://" + Environment.MachineName + ":8081"), Title = SyndicationContent.CreatePlaintextContent(room.Title), Summary = SyndicationContent.CreatePlaintextContent(room.Description) }; entry.Authors.Add(new SyndicationPerson {Name = "Dungeon Master", Email = "*****@*****.**"}); entry.Categories.Add(new SyndicationCategory("room")); foreach (var exit in room.Exits) { var link = new SyndicationLink { Uri = new Uri("/rooms/" + exit.RoomId, UriKind.Relative), RelationshipType = exit.Direction.ToString().ToLower() }; entry.Links.Add(link); } var response = new HttpResponseMessage<SyndicationItem>(entry) {StatusCode = HttpStatusCode.OK}; response.Headers.CacheControl = new CacheControlHeaderValue {Public = true, MaxAge = new TimeSpan(0, 0, 0, 10)}; response.Content.Headers.ContentType = AtomMediaType.Entry; return response; }
public List<SyndicationItem> txtgotolv(string namefile) { List<SyndicationItem> items = new List<SyndicationItem>(); var lines = System.IO.File.ReadAllLines(namefile); int count = lines.Length; for (int i = 0; i < count; i = i + 4) { SyndicationItem item = new SyndicationItem(); SyndicationLink link; item.Id = Guid.NewGuid().ToString(); item.Title = new TextSyndicationContent(lines[i]); item.Summary = new TextSyndicationContent(lines[i + 1]); link = new SyndicationLink(new Uri(lines[i + 2])); item.Content = new TextSyndicationContent(lines[i + 3]); item.Links.Add(link); items.Add(item); } return items; }
protected internal static bool TryParseElement(System.Xml.XmlReader reader, SyndicationLink link, string version) { return(default(bool)); }
protected internal void WriteElementExtensions (XmlWriter writer, SyndicationLink link, string version) { if (link == null) throw new ArgumentNullException ("link"); link.WriteElementExtensions (writer, version); }
protected internal static bool TryParseAttribute (string name, string ns, string value, SyndicationLink link, string version) { if (link == null) throw new ArgumentNullException ("link"); return link.TryParseAttribute (name, ns, value, version); }
public SyndicationLink ToSyndicationLink() { SyndicationLink result = new SyndicationLink(this.Uri, this.RelationshipType, this.Title, this.MediaType, this.Length); result.BaseUri = this.BaseUri; return result; }
private void WriteAlternateLink(XmlWriter writer, SyndicationLink link, Uri baseUri) { writer.WriteStartElement("link", ""); Uri baseUriToWrite = FeedUtils.GetBaseUriToWrite(baseUri, link.BaseUri); if (baseUriToWrite != null) { writer.WriteAttributeString("xml", "base", "http://www.w3.org/XML/1998/namespace", FeedUtils.GetUriString(baseUriToWrite)); } link.WriteAttributeExtensions(writer, "Rss20"); writer.WriteString(FeedUtils.GetUriString(link.Uri)); writer.WriteEndElement(); }
private SyndicationLink ReadAlternateLink(XmlReader reader, Uri baseUri) { SyndicationLink link = new SyndicationLink { BaseUri = baseUri, RelationshipType = "alternate" }; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if ((reader.LocalName == "base") && (reader.NamespaceURI == "http://www.w3.org/XML/1998/namespace")) { link.BaseUri = FeedUtils.CombineXmlBase(link.BaseUri, reader.Value); } else if (!FeedUtils.IsXmlns(reader.LocalName, reader.NamespaceURI)) { if (this.PreserveAttributeExtensions) { link.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value); continue; } SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader); } } } reader.ReadStartElement(); link.Uri = new Uri(reader.ReadString(), UriKind.RelativeOrAbsolute); reader.ReadEndElement(); return link; }
protected static void WriteAttributeExtensions(XmlWriter writer, SyndicationLink link, string version) { SyndicationFeedFormatter.WriteAttributeExtensions(writer, link, version); }
internal static protected bool TryParseAttribute(string name, string ns, string value, SyndicationLink link, string version) { if (link == null) { throw new ArgumentNullException(nameof(link)); } if (FeedUtils.IsXmlns(name, ns)) { return(true); } return(link.TryParseAttribute(name, ns, value, version)); }
// read void ReadXml(XmlReader reader, bool fromSerializable) { if (reader == null) { throw new ArgumentNullException("reader"); } SetItem(CreateItemInstance()); reader.MoveToContent(); if (PreserveAttributeExtensions && reader.MoveToFirstAttribute()) { do { if (reader.NamespaceURI == "http://www.w3.org/2000/xmlns/") { continue; } if (!TryParseAttribute(reader.LocalName, reader.NamespaceURI, reader.Value, Item, Version)) { Item.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value); } } while (reader.MoveToNextAttribute()); } reader.ReadStartElement(); for (reader.MoveToContent(); reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent()) { if (reader.NodeType != XmlNodeType.Element) { throw new XmlException("Only element node is expected under 'item' element"); } if (reader.NamespaceURI == String.Empty) { switch (reader.LocalName) { case "title": Item.Title = ReadTextSyndicationContent(reader); continue; case "link": SyndicationLink l = Item.CreateLink(); ReadLink(reader, l); Item.Links.Add(l); continue; case "description": Item.Summary = ReadTextSyndicationContent(reader); continue; case "author": SyndicationPerson p = Item.CreatePerson(); ReadPerson(reader, p); Item.Authors.Add(p); continue; case "category": SyndicationCategory c = Item.CreateCategory(); ReadCategory(reader, c); Item.Categories.Add(c); continue; // case "comments": // treated as extension ... case "enclosure": l = Item.CreateLink(); ReadEnclosure(reader, l); Item.Links.Add(l); continue; case "guid": Item.AddPermalink(CreateUri(reader.ReadElementContentAsString())); continue; case "pubDate": // FIXME: somehow DateTimeOffset causes the runtime crash. reader.ReadElementContentAsString(); // Item.PublishDate = FromRFC822DateString (reader.ReadElementContentAsString ()); continue; case "source": Item.SourceFeed = new SyndicationFeed(); ReadSourceFeed(reader, Item.SourceFeed); continue; } } else if (SerializeExtensionsAsAtom && reader.NamespaceURI == AtomNamespace) { switch (reader.LocalName) { case "contributor": SyndicationPerson p = Item.CreatePerson(); ReadPersonAtom10(reader, p); Item.Contributors.Add(p); continue; case "updated": // FIXME: somehow DateTimeOffset causes the runtime crash. reader.ReadElementContentAsString(); // Item.LastUpdatedTime = XmlConvert.ToDateTimeOffset (reader.ReadElementContentAsString ()); continue; case "rights": Item.Copyright = ReadTextSyndicationContent(reader); continue; case "content": if (reader.GetAttribute("src") != null) { Item.Content = new UrlSyndicationContent(CreateUri(reader.GetAttribute("src")), reader.GetAttribute("type")); reader.Skip(); continue; } switch (reader.GetAttribute("type")) { case "text": case "html": case "xhtml": Item.Content = ReadTextSyndicationContent(reader); continue; default: SyndicationContent content; if (!TryParseContent(reader, Item, reader.GetAttribute("type"), Version, out content)) { Item.Content = new XmlSyndicationContent(reader); } continue; } } } if (!TryParseElement(reader, Item, Version)) { if (PreserveElementExtensions) { // FIXME: what to specify for maxExtensionSize LoadElementExtensions(reader, Item, int.MaxValue); } else { reader.Skip(); } } } reader.ReadEndElement(); // </item> }
protected internal static Task WriteAttributeExtensionsAsync(XmlWriter writer, SyndicationLink link, string version) { if (link == null) { throw new ArgumentNullException(nameof(link)); } return(link.WriteAttributeExtensionsAsync(writer, version)); }
internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, SyndicationLink link) { if (link == null) { throw new ArgumentNullException(nameof(link)); } CloseBuffer(buffer, writer); link.LoadElementExtensions(buffer); }
internal static protected bool TryParseAttribute(string name, string ns, string value, SyndicationLink link, string version) { if (link == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("link"); } if (FeedUtils.IsXmlns(name, ns)) { return(true); } return(link.TryParseAttribute(name, ns, value, version)); }
protected void WriteElementExtensions(XmlWriter writer, SyndicationLink link, string version) { SyndicationFeedFormatter.WriteElementExtensions(writer, link, version); }
protected SyndicationLink(SyndicationLink source !!) {
protected internal static bool TryParseAttribute(string name, string ns, string value, SyndicationLink link, string version) { if (link == null) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("link"); } return(FeedUtils.IsXmlns(name, ns) || link.TryParseAttribute(name, ns, value, version)); }
protected static bool TryParseAttribute(string name, string ns, string value, SyndicationLink link, string version) { return(SyndicationFeedFormatter.TryParseAttribute(name, ns, value, link, version)); }
// read void ReadXml(XmlReader reader, bool fromSerializable) { if (reader == null) { throw new ArgumentNullException("reader"); } SetFeed(CreateFeedInstance()); reader.MoveToContent(); if (reader.MoveToFirstAttribute()) { do { if (reader.NamespaceURI == "http://www.w3.org/2000/xmlns/") { continue; } if (reader.LocalName == "lang" && reader.NamespaceURI == "http://www.w3.org/XML/1998/namespace") { Feed.Language = reader.Value; continue; } if (!TryParseAttribute(reader.LocalName, reader.NamespaceURI, reader.Value, Feed, Version) && PreserveAttributeExtensions) { Feed.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value); } }while (reader.MoveToNextAttribute()); } reader.ReadStartElement(); Collection <SyndicationItem> items = null; for (reader.MoveToContent(); reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent()) { if (reader.NodeType != XmlNodeType.Element) { throw new XmlException("Only element node is expected under 'feed' element"); } if (reader.NamespaceURI == AtomNamespace) { switch (reader.LocalName) { case "author": SyndicationPerson p = Feed.CreatePerson(); ReadPerson(reader, p); Feed.Authors.Add(p); continue; case "category": SyndicationCategory c = Feed.CreateCategory(); ReadCategory(reader, c); Feed.Categories.Add(c); continue; case "contributor": p = Feed.CreatePerson(); ReadPerson(reader, p); Feed.Contributors.Add(p); continue; case "generator": Feed.Generator = reader.ReadElementContentAsString(); continue; // "icon" is an extension case "id": Feed.Generator = reader.ReadElementContentAsString(); continue; case "link": SyndicationLink l = Feed.CreateLink(); ReadLink(reader, l); Feed.Links.Add(l); continue; case "logo": Feed.ImageUrl = CreateUri(reader.ReadElementContentAsString()); continue; case "rights": Feed.Copyright = ReadTextSyndicationContent(reader); continue; case "subtitle": Feed.Description = ReadTextSyndicationContent(reader); continue; case "title": Feed.Title = ReadTextSyndicationContent(reader); continue; case "updated": // FIXME: somehow DateTimeOffset causes the runtime crash. reader.ReadElementContentAsString(); // Feed.LastUpdatedTime = XmlConvert.ToDateTimeOffset (reader.ReadElementContentAsString ()); continue; case "entry": if (items == null) { items = new Collection <SyndicationItem> (); Feed.Items = items; } items.Add(ReadItem(reader, Feed)); continue; } } if (!TryParseElement(reader, Feed, Version)) { if (PreserveElementExtensions) { // FIXME: what to specify for maxExtensionSize LoadElementExtensions(reader, Feed, int.MaxValue); } else { reader.Skip(); } } } reader.ReadEndElement(); }
protected static bool TryParseElement(XmlReader reader, SyndicationLink link, string version) { return(SyndicationFeedFormatter.TryParseElement(reader, link, version)); }
private SyndicationLink ReadMediaEnclosure(XmlReader reader, Uri baseUri) { SyndicationLink link = new SyndicationLink { BaseUri = baseUri, RelationshipType = "enclosure" }; bool isEmptyElement = reader.IsEmptyElement; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { string namespaceURI = reader.NamespaceURI; string localName = reader.LocalName; if ((localName == "base") && (namespaceURI == "http://www.w3.org/XML/1998/namespace")) { link.BaseUri = FeedUtils.CombineXmlBase(link.BaseUri, reader.Value); } else if (!FeedUtils.IsXmlns(localName, namespaceURI)) { string uriString = reader.Value; if ((localName == "url") && (namespaceURI == "")) { link.Uri = new Uri(uriString, UriKind.RelativeOrAbsolute); continue; } if ((localName == "type") && (namespaceURI == "")) { link.MediaType = uriString; continue; } if ((localName == "length") && (namespaceURI == "")) { link.Length = !string.IsNullOrEmpty(uriString) ? Convert.ToInt64(uriString, CultureInfo.InvariantCulture.NumberFormat) : 0L; continue; } if (!FeedUtils.IsXmlns(localName, namespaceURI)) { if (this.preserveAttributeExtensions) { link.AttributeExtensions.Add(new XmlQualifiedName(localName, namespaceURI), uriString); continue; } SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader); } } } } reader.ReadStartElement("enclosure", ""); if (!isEmptyElement) { reader.ReadEndElement(); } return link; }
protected static async Task WriteAttributeExtensionsAsync(XmlWriter writer, SyndicationLink link, string version) { await SyndicationFeedFormatter.WriteAttributeExtensions(writer, link, version); }
protected internal static void LoadElementExtensions(System.Xml.XmlReader reader, SyndicationLink link, int maxExtensionSize) { }
protected Task WriteElementExtensionsAsync(XmlWriter writer, SyndicationLink link, string version) { return(SyndicationFeedFormatter.WriteElementExtensionsAsync(writer, link, version)); }
protected internal static void WriteElementExtensions(System.Xml.XmlWriter writer, SyndicationLink link, string version) { }
internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, SyndicationLink link) { SyndicationFeedFormatter.LoadElementExtensions(buffer, writer, link); }
protected internal static bool TryParseElement (XmlReader reader, SyndicationLink link, string version) { if (link == null) throw new ArgumentNullException ("link"); return link.TryParseElement (reader, version); }
// read void ReadXml(XmlReader reader, bool fromSerializable) { if (reader == null) { throw new ArgumentNullException("reader"); } SetItem(CreateItemInstance()); reader.MoveToContent(); if (reader.MoveToFirstAttribute()) { do { if (reader.NamespaceURI == "http://www.w3.org/2000/xmlns/") { continue; } if (!TryParseAttribute(reader.LocalName, reader.NamespaceURI, reader.Value, Item, Version) && PreserveAttributeExtensions) { Item.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value); } } while (reader.MoveToNextAttribute()); } reader.ReadStartElement(); for (reader.MoveToContent(); reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent()) { if (reader.NodeType != XmlNodeType.Element) { throw new XmlException("Only element node is expected under 'entry' element"); } if (reader.NamespaceURI == AtomNamespace) { switch (reader.LocalName) { case "author": SyndicationPerson p = Item.CreatePerson(); ReadPerson(reader, p); Item.Authors.Add(p); continue; case "category": SyndicationCategory c = Item.CreateCategory(); ReadCategory(reader, c); Item.Categories.Add(c); continue; case "contributor": p = Item.CreatePerson(); ReadPerson(reader, p); Item.Contributors.Add(p); continue; case "id": Item.Id = reader.ReadElementContentAsString(); continue; case "link": SyndicationLink l = Item.CreateLink(); ReadLink(reader, l); Item.Links.Add(l); continue; case "published": Item.PublishDate = XmlConvert.ToDateTimeOffset(reader.ReadElementContentAsString()); continue; case "rights": Item.Copyright = ReadTextSyndicationContent(reader); continue; case "source": Item.SourceFeed = ReadSourceFeed(reader); continue; case "summary": Item.Summary = ReadTextSyndicationContent(reader); continue; case "title": Item.Title = ReadTextSyndicationContent(reader); continue; case "updated": Item.LastUpdatedTime = XmlConvert.ToDateTimeOffset(reader.ReadElementContentAsString()); continue; // Atom 1.0 does not specify "content" element, but it is required to distinguish Content property from extension elements. case "content": if (reader.GetAttribute("src") != null) { Item.Content = new UrlSyndicationContent(CreateUri(reader.GetAttribute("src")), reader.GetAttribute("type")); reader.Skip(); continue; } switch (reader.GetAttribute("type")) { case "text": case "html": case "xhtml": Item.Content = ReadTextSyndicationContent(reader); continue; default: SyndicationContent content; if (!TryParseContent(reader, Item, reader.GetAttribute("type"), Version, out content)) { Item.Content = new XmlSyndicationContent(reader); } continue; } } } if (!TryParseElement(reader, Item, Version)) { if (PreserveElementExtensions) { // FIXME: what to specify for maxExtensionSize LoadElementExtensions(reader, Item, int.MaxValue); } else { reader.Skip(); } } } reader.ReadEndElement(); // </item> }
protected internal static void LoadElementExtensions (XmlReader reader, SyndicationLink link, int maxExtensionSize) { link.ElementExtensions.Add (reader); }
void ReadLink(XmlReader reader, SyndicationLink link) { if (reader.MoveToFirstAttribute()) { do { if (reader.NamespaceURI == "http://www.w3.org/2000/xmlns/") { continue; } if (reader.NamespaceURI == String.Empty) { switch (reader.LocalName) { case "href": link.Uri = CreateUri(reader.Value); continue; case "rel": link.RelationshipType = reader.Value; continue; case "type": link.MediaType = reader.Value; continue; case "length": link.Length = XmlConvert.ToInt64(reader.Value); continue; case "title": link.Title = reader.Value; continue; } } if (!TryParseAttribute(reader.LocalName, reader.NamespaceURI, reader.Value, link, Version) && PreserveAttributeExtensions) { link.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value); } } while (reader.MoveToNextAttribute()); reader.MoveToElement(); } if (!reader.IsEmptyElement) { reader.Read(); for (reader.MoveToContent(); reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent()) { if (!TryParseElement(reader, link, Version)) { if (PreserveElementExtensions) { // FIXME: what should be used for maxExtenswionSize LoadElementExtensions(reader, link, int.MaxValue); } else { reader.Skip(); } } } } reader.Read(); // </link> or <link ... /> }
protected internal static bool TryParseAttribute(string name, string ns, string value, SyndicationLink link, string version) { return(default(bool)); }
protected internal static bool TryParseAttribute(string name, string ns, string value, SyndicationLink link, string version) { if (link == null) { throw new ArgumentNullException("link"); } return(link.TryParseAttribute(name, ns, value, version)); }
// read void ReadXml(XmlReader reader, bool fromSerializable) { if (reader == null) { throw new ArgumentNullException("reader"); } SetFeed(CreateFeedInstance()); reader.MoveToContent(); string ver = reader.GetAttribute("version"); if (ver != "2.0") { throw new NotSupportedException(String.Format("RSS Version '{0}' is not supported", ver)); } if (PreserveAttributeExtensions && reader.MoveToFirstAttribute()) { do { if (reader.NamespaceURI == "http://www.w3.org/2000/xmlns/") { continue; } if (reader.NamespaceURI == String.Empty && reader.LocalName == "version") { continue; } if (!TryParseAttribute(reader.LocalName, reader.NamespaceURI, reader.Value, Feed, Version)) { Feed.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value); } } while (reader.MoveToNextAttribute()); } reader.ReadStartElement(); // <rss> => <channel> reader.MoveToContent(); reader.ReadStartElement("channel", String.Empty); // <channel> => * Collection <SyndicationItem> items = null; for (reader.MoveToContent(); reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent()) { if (reader.NodeType != XmlNodeType.Element) { throw new XmlException("Only element node is expected under 'channel' element"); } if (reader.NamespaceURI == String.Empty) { switch (reader.LocalName) { case "title": Feed.Title = ReadTextSyndicationContent(reader); continue; case "link": SyndicationLink l = Feed.CreateLink(); ReadLink(reader, l); Feed.Links.Add(l); continue; case "description": Feed.Description = ReadTextSyndicationContent(reader); continue; case "language": Feed.Language = reader.ReadElementContentAsString(); continue; case "copyright": Feed.Copyright = ReadTextSyndicationContent(reader); continue; case "managingEditor": SyndicationPerson p = Feed.CreatePerson(); ReadPerson(reader, p); Feed.Authors.Add(p); continue; case "pubDate": // FIXME: somehow DateTimeOffset causes the runtime crash. reader.ReadElementContentAsString(); // Feed.PublishDate = FromRFC822DateString (reader.ReadElementContentAsString ()); continue; case "lastBuildDate": // FIXME: somehow DateTimeOffset causes the runtime crash. reader.ReadElementContentAsString(); // Feed.LastUpdatedTime = FromRFC822DateString (reader.ReadElementContentAsString ()); continue; case "category": SyndicationCategory c = Feed.CreateCategory(); ReadCategory(reader, c); Feed.Categories.Add(c); continue; case "generator": Feed.Generator = reader.ReadElementContentAsString(); continue; // "webMaster" "docs" "cloud" "ttl" "image" "rating" "textInput" "skipHours" "skipDays" are not handled. case "item": if (items == null) { items = new Collection <SyndicationItem> (); Feed.Items = items; } items.Add(ReadItem(reader, Feed)); continue; } } if (!TryParseElement(reader, Feed, Version)) { if (PreserveElementExtensions) { // FIXME: what to specify for maxExtensionSize LoadElementExtensions(reader, Feed, int.MaxValue); } else { reader.Skip(); } } } reader.ReadEndElement(); // </channel> reader.ReadEndElement(); // </rss> }
protected internal static void LoadElementExtensions(XmlReader reader, SyndicationLink link, int maxExtensionSize) { link.ElementExtensions.Add(reader); }
protected static void LoadElementExtensions(XmlReader reader, SyndicationLink link, int maxExtensionSize) { SyndicationFeedFormatter.LoadElementExtensions(reader, link, maxExtensionSize); }
internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, SyndicationLink link) { if (link == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("link"); } CloseBuffer(buffer, writer); link.LoadElementExtensions(buffer); }