public void CommonSetCoreItemPropertiesUsingObjects(RssItem itm) { itm.title = "Item One Title"; itm.description = "Item ONe Description Is a dandy"; itm.link = "http://something.com/item1"; itm.pubDate = DateTime.Now; itm.author = "*****@*****.**"; RssItemCategory ctg = new RssItemCategory(); ctg.category = "ITEM_CTG1"; itm.categories.Add(ctg); ctg = new RssItemCategory(); ctg.category = "ITEM_CTG2"; ctg.domain = "something.com"; itm.categories.Add(ctg); RssItemEnclosure enc = new RssItemEnclosure(); enc.url = "http://something.com/crazy.mp4"; enc.length = 0; enc.type = "video/mp4"; itm.AddEnclosure(enc); RssItemGuid guid = new RssItemGuid(); guid.guid = "http://something.com/item1"; guid.isPermalink = true; itm.guid = guid; itm.comments = "http://something.com/item1/comments"; RssItemSource src = new RssItemSource(); src.source = "Blabbermouth Inc."; src.url = "http://blabbermouth.com/item1"; itm.source = src; }
// ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- /// <summary> /// Adds a guid object to the item /// </summary> /// <param name="obj">RssItemGuid </param> // ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- public void AddGuid(RssItemGuid obj) { base.AddGuid(obj); }
public async Task <IActionResult> Rss() { rss rss = new rss(); RssChannel rssChannel = new RssChannel(); rss.channel = rssChannel; Image feedImage = new Image(); feedImage.link = WeblogUri.AbsoluteUri; feedImage.title = WeblogTitle; feedImage.width = WeblogImageWidth.ToString(RssLocFormat); feedImage.height = WeblogImageHeight.ToString(RssLocFormat); feedImage.url = WeblogImageUri.AbsoluteUri; rssChannel.ItemsElementName = new ItemsChoiceType[] { // Ordering must correspond to the contents of rssChannel.Items ItemsChoiceType.title, ItemsChoiceType.link, ItemsChoiceType.language, ItemsChoiceType.image }; rssChannel.Items = new object[] { WeblogTitle, WeblogUri.AbsoluteUri, // Must be a string value WeblogLanguage.ToString(), // Must be a string value feedImage }; // Gets all the blog post items from repo. var json = await(await this.httpClient.GetAsync($"blogPosts/paginate/{this.pageSize}/1")).Content.ReadAsStringAsync(); dynamic blogPosts = JsonConvert.DeserializeObject(json); var rssItemList = new List <RssItem>(); foreach (dynamic post in blogPosts.data) { var rssItem = new RssItem(); rssItem.ItemsElementName = new ItemsChoiceType1[] { ItemsChoiceType1.link, ItemsChoiceType1.pubDate, ItemsChoiceType1.guid, ItemsChoiceType1.title, ItemsChoiceType1.description, ItemsChoiceType1.category }; var itemGuid = new RssItemGuid { isPermaLink = false, Value = ((int)post.id).ToString() }; var link = Url.Action("Post", "BlogPosts", new { id = (int)post.id }, Url.ActionContext.HttpContext.Request.Scheme); var itemUri = new Uri(link); var itemPubDate = (DateTime)post.datePublished; var itemTitle = (string)post.title; var itemBody = (string)post.content; var itemCategory = new Category { Value = ItemCategoryName }; rssItem.Items = new object[] { itemUri.AbsoluteUri, // Must be a string value itemPubDate.ToString( // Format data value DateTimeFormatInfo.InvariantInfo.RFC1123Pattern, RssLocFormat), itemGuid, itemTitle, itemBody, itemCategory }; rssItemList.Add(rssItem); } rssChannel.item = rssItemList.ToArray(); XmlSerializer serializer = new XmlSerializer(typeof(rss)); using (var ms = new MemoryStream()) { serializer.Serialize(ms, rss); return(Content(Encoding.UTF8.GetString(ms.ToArray()), "application/xml")); } }