/// <summary> /// Initializes the supplied <see cref="RssEnclosure"/> using the specified <see cref="XPathNavigator"/> and <see cref="XmlNamespaceManager"/>. /// </summary> /// <param name="enclosure">The <see cref="RssEnclosure"/> to be filled.</param> /// <param name="navigator">The <see cref="XPathNavigator"/> used to navigate the enclosure XML data.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the load operation.</param> /// <exception cref="ArgumentNullException">The <paramref name="enclosure"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="navigator"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception> private static void FillEnclosure(RssEnclosure enclosure, XPathNavigator navigator, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { Guard.ArgumentNotNull(enclosure, "enclosure"); Guard.ArgumentNotNull(navigator, "navigator"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); if (navigator.HasAttributes) { string urlAttribute = navigator.GetAttribute("url", String.Empty); string lengthAttribute = navigator.GetAttribute("length", String.Empty); string typeAttribute = navigator.GetAttribute("type", String.Empty); Uri url; if (Uri.TryCreate(urlAttribute, UriKind.RelativeOrAbsolute, out url)) { enclosure.Url = url; } long length; if (Int64.TryParse(lengthAttribute, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out length)) { enclosure.Length = length; } if (!String.IsNullOrEmpty(typeAttribute)) { enclosure.ContentType = typeAttribute; } } SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(navigator, settings); adapter.Fill(enclosure); }
/// <summary>Creates an instance from a RSS Enclosure.</summary> /// <param name="enclosure">RSS Enclosure.</param> /// <returns>Attachment Information.</returns> public static InfoAttach Create(RssEnclosure enclosure) { InfoAttach attach = new InfoAttach(); attach._type = enclosure.Type; attach._url = enclosure.Url.AbsoluteUri; attach._length = enclosure.Length; attach._id = enclosure.Id; attach._name = enclosure.Name; attach._title = enclosure.Title; attach._timestamp = enclosure.Timestamp; attach._digestMd5 = enclosure.DigestMd5; return(attach); }
/// <summary> /// Closes connection to file. /// </summary> /// <remarks> /// This method also releases any resources held while reading. /// </remarks> public void Close() { this.textInput = null; this.image = null; this.cloud = null; this.channel = null; this.source = null; this.enclosure = null; this.category = null; this.item = null; if (this.reader != null) { this.reader.Close(); this.reader = null; } this.elementText = null; this.xmlNodeStack = null; }
public static List <IVideoInfo> GetMediaFromFeed(string url) { RssFeed feed = new RssFeed(); using (XmlReader reader = XmlReader.Create(url)) { feed.Load(reader); } List <IVideoInfo> media = new List <IVideoInfo>(); foreach (RssItem item in feed.Channel.Items) { RssEnclosure enclosure = item.Enclosures.Where(x => x.ContentType != null).FirstOrDefault(); if (enclosure == null) { continue; } var durationElement = item.FindExtension(x => x is Argotic.Extensions.Core.ITunesSyndicationExtension && ((Argotic.Extensions.Core.ITunesSyndicationExtension)x).Context.Duration != null); TimeSpan duration = durationElement != null ? ((Argotic.Extensions.Core.ITunesSyndicationExtension)durationElement).Context.Duration : TimeSpan.Zero; GenericVideoInfo info = new GenericVideoInfo { Service = StreamService.RawUrl, VideoTitle = item.Title, VideoGame = item.Description, VideoTimestamp = item.PublicationDate, VideoType = VideoFileType.Unknown, VideoRecordingState = RecordingState.Recorded, Username = feed.Channel.Title, VideoId = enclosure.Url.AbsoluteUri, VideoLength = duration }; media.Add(info); } return(media); }
/// <summary> /// Initializes the supplied <see cref="RssItem"/> using the specified <see cref="XPathNavigator"/> and <see cref="XmlNamespaceManager"/>. /// </summary> /// <param name="item">The <see cref="RssItem"/> to be filled.</param> /// <param name="navigator">The <see cref="XPathNavigator"/> used to navigate the item XML data.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the load operation.</param> /// <exception cref="ArgumentNullException">The <paramref name="item"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="navigator"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception> private static void FillItem(RssItem item, XPathNavigator navigator, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { Guard.ArgumentNotNull(item, "item"); Guard.ArgumentNotNull(navigator, "navigator"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); XPathNavigator titleNavigator = navigator.SelectSingleNode("title", manager); XPathNavigator linkNavigator = navigator.SelectSingleNode("link", manager); XPathNavigator descriptionNavigator = navigator.SelectSingleNode("description", manager); XPathNavigator sourceNavigator = navigator.SelectSingleNode("source", manager); XPathNodeIterator enclosureIterator = navigator.Select("enclosure", manager); XPathNodeIterator categoryIterator = navigator.Select("category", manager); if (titleNavigator != null) { item.Title = titleNavigator.Value; } if (descriptionNavigator != null) { item.Description = descriptionNavigator.Value; } if (linkNavigator != null) { Uri link; if (Uri.TryCreate(linkNavigator.Value, UriKind.RelativeOrAbsolute, out link)) { item.Link = link; } } if (sourceNavigator != null) { item.Source = new RssSource(); if (sourceNavigator.HasAttributes) { string urlAttribute = sourceNavigator.GetAttribute("url", String.Empty); Uri url; if (Uri.TryCreate(urlAttribute, UriKind.RelativeOrAbsolute, out url)) { item.Source.Url = url; } } if (!String.IsNullOrEmpty(sourceNavigator.Value)) { item.Source.Title = sourceNavigator.Value; } } if (enclosureIterator != null && enclosureIterator.Count > 0) { while (enclosureIterator.MoveNext()) { RssEnclosure enclosure = new RssEnclosure(); Rss092SyndicationResourceAdapter.FillEnclosure(enclosure, enclosureIterator.Current, manager, settings); item.Enclosures.Add(enclosure); } } if (categoryIterator != null && categoryIterator.Count > 0) { while (categoryIterator.MoveNext()) { RssCategory category = new RssCategory(); Rss092SyndicationResourceAdapter.FillCategory(category, categoryIterator.Current, manager, settings); item.Categories.Add(category); } } SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(navigator, settings); adapter.Fill(item); }
private void RenderRss() { Argotic.Syndication.RssFeed feed = new Argotic.Syndication.RssFeed(); RssChannel channel = new RssChannel(); channel.Generator = "mojoPortal Blog Module"; channel.Language = SiteUtils.GetDefaultCulture(); feed.Channel = channel; if (module.ModuleTitle.Length > 0) { channel.Title = module.ModuleTitle; } else { channel.Title = "Blog"; // it will cause an error if this is left blank so we must populate it if the module title is an emty string. } // this became broken when we combined query string params, since pageid is not one of the params this always returns the home page url // instead of the blog page url //string pu = WebUtils.ResolveServerUrl(SiteUtils.GetCurrentPageUrl()); string pu = WebUtils.ResolveServerUrl(SiteUtils.GetPageUrl(pageSettings)); channel.Link = new System.Uri(pu); channel.SelfLink = Request.Url; if (config.ChannelDescription.Length > 0) { channel.Description = config.ChannelDescription; } if (config.Copyright.Length > 0) { channel.Copyright = config.Copyright; } channel.ManagingEditor = config.ManagingEditorEmail; if (config.ManagingEditorName.Length > 0) { channel.ManagingEditor += " (" + config.ManagingEditorName + ")"; } if (config.FeedTimeToLive > -1) { channel.TimeToLive = config.FeedTimeToLive; } // Create and add iTunes information to feed channel ITunesSyndicationExtension channelExtension = new ITunesSyndicationExtension(); channelExtension.Context.Subtitle = config.ChannelDescription; if (config.HasExplicitContent) { channelExtension.Context.ExplicitMaterial = ITunesExplicitMaterial.Yes; } else { channelExtension.Context.ExplicitMaterial = ITunesExplicitMaterial.No; } channelExtension.Context.Author = config.ManagingEditorEmail; if (config.ManagingEditorName.Length > 0) { channelExtension.Context.Author += " (" + config.ManagingEditorName + ")"; } channelExtension.Context.Summary = config.ChannelDescription; channelExtension.Context.Owner = new ITunesOwner(config.ManagingEditorEmail, config.ManagingEditorName); if (config.FeedLogoUrl.Length > 0) { try { channelExtension.Context.Image = new Uri(config.FeedLogoUrl); } catch (ArgumentNullException) { } catch (UriFormatException) { } } if (config.FeedMainCategory.Length > 0) { ITunesCategory mainCat = new ITunesCategory(config.FeedMainCategory); if (config.FeedSubCategory.Length > 0) { mainCat.Categories.Add(new ITunesCategory(config.FeedSubCategory)); } channelExtension.Context.Categories.Add(mainCat); } feed.Channel.AddExtension(channelExtension); DataSet dsBlogPosts = GetData(); DataTable posts = dsBlogPosts.Tables["Posts"]; foreach (DataRow dr in posts.Rows) { bool inFeed = Convert.ToBoolean(dr["IncludeInFeed"]); if (!inFeed) { continue; } RssItem item = new RssItem(); int itemId = Convert.ToInt32(dr["ItemID"]); string blogItemUrl = FormatBlogUrl(dr["ItemUrl"].ToString(), itemId); item.Link = new Uri(Request.Url, blogItemUrl); item.Guid = new RssGuid(blogItemUrl); item.Title = dr["Heading"].ToString(); item.PublicationDate = Convert.ToDateTime(dr["StartDate"]); bool showAuthor = Convert.ToBoolean(dr["ShowAuthorName"]); if (showAuthor) { // techically this is supposed to be an email address // but wouldn't that lead to a lot of spam? string authorEmail = dr["Email"].ToString(); string authorName = dr["Name"].ToString(); if (BlogConfiguration.IncludeAuthorEmailInFeed) { item.Author = authorEmail + " (" + authorName + ")"; } else { item.Author = authorName; } } else if (config.ManagingEditorEmail.Length > 0) { item.Author = config.ManagingEditorEmail; } item.Comments = new Uri(blogItemUrl); string signature = string.Empty; if (config.AddSignature) { signature = "<br /><a href='" + blogItemUrl + "'>" + dr["Name"].ToString() + "</a>"; } if ((config.AddCommentsLinkToFeed) && (config.AllowComments)) { signature += " " + "<a href='" + blogItemUrl + "'>...</a>"; } if (config.AddTweetThisToFeed) { signature += GenerateTweetThisLink(item.Title, blogItemUrl); } if (config.AddFacebookLikeToFeed) { signature += GenerateFacebookLikeButton(blogItemUrl); } string blogPost = SiteUtils.ChangeRelativeUrlsToFullyQualifiedUrls(navigationSiteRoot, imageSiteRoot, dr["Description"].ToString().RemoveCDataTags()); string staticMapLink = BuildStaticMapMarkup(dr); if (staticMapLink.Length > 0) { // add a google static map blogPost += staticMapLink; } if ((!config.UseExcerptInFeed) || (blogPost.Length <= config.ExcerptLength)) { item.Description = blogPost + signature; } else { string excerpt = SiteUtils.ChangeRelativeUrlsToFullyQualifiedUrls(navigationSiteRoot, imageSiteRoot, dr["Abstract"].ToString().RemoveCDataTags()); if ((excerpt.Length > 0) && (excerpt != "<p> </p>")) { excerpt = excerpt + config.ExcerptSuffix + " <a href='" + blogItemUrl + "'>" + config.MoreLinkText + "</a><div class='excerptspacer'> </div>"; } else { excerpt = UIHelper.CreateExcerpt(dr["Description"].ToString(), config.ExcerptLength, config.ExcerptSuffix) + " <a href='" + blogItemUrl + "'>" + config.MoreLinkText + "</a><div class='excerptspacer'> </div>";; } item.Description = excerpt; } // how to add media enclosures for podcasting //http://www.podcast411.com/howto_1.html //http://argotic.codeplex.com/wikipage?title=Generating%20an%20extended%20RSS%20feed //http://techwhimsy.com/stream-mp3s-with-google-mp3-player //Uri url = new Uri("http://media.libsyn.com/media/podcast411/411_060325.mp3"); //string type = "audio/mpeg"; //long length = 11779397; string blogGuid = dr["BlogGuid"].ToString(); string whereClause = string.Format("ItemGuid = '{0}'", blogGuid); if (!config.UseExcerptInFeed) { DataView dv = new DataView(dsBlogPosts.Tables["Attachments"], whereClause, "", DataViewRowState.CurrentRows); foreach (DataRowView rowView in dv) { DataRow row = rowView.Row; Uri mediaUrl = new Uri(WebUtils.ResolveServerUrl(attachmentBaseUrl + row["ServerFileName"].ToString())); long contentLength = Convert.ToInt64(row["ContentLength"]); string contentType = row["ContentType"].ToString(); RssEnclosure enclosure = new RssEnclosure(contentLength, contentType, mediaUrl); item.Enclosures.Add(enclosure); //http://argotic.codeplex.com/wikipage?title=Generating%20an%20extended%20RSS%20feed ITunesSyndicationExtension itemExtension = new ITunesSyndicationExtension(); itemExtension.Context.Author = dr["Name"].ToString(); itemExtension.Context.Subtitle = dr["SubTitle"].ToString(); //itemExtension.Context.Summary = "The iTunes syndication extension properties that are used vary based on whether extending the channel or an item"; //itemExtension.Context.Duration = new TimeSpan(1, 2, 13); //itemExtension.Context.Keywords.Add("Podcast"); //itemExtension.Context.Keywords.Add("iTunes"); whereClause = string.Format("ItemID = '{0}'", itemId); DataView dvCat = new DataView(dsBlogPosts.Tables["Categories"], whereClause, "", DataViewRowState.CurrentRows); foreach (DataRowView rView in dvCat) { DataRow r = rView.Row; item.Categories.Add(new RssCategory(r["Category"].ToString())); itemExtension.Context.Keywords.Add(r["Category"].ToString()); } item.AddExtension(itemExtension); } } channel.AddItem(item); } if ((config.FeedburnerFeedUrl.Length > 0) || (Request.Url.AbsolutePath.Contains("localhost"))) { Response.Cache.SetExpires(DateTime.Now.AddMinutes(-30)); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.VaryByParams["r"] = true; } else { Response.Cache.SetExpires(DateTime.Now.AddMinutes(30)); Response.Cache.SetCacheability(HttpCacheability.Public); } Response.ContentType = "application/xml"; Encoding encoding = new UTF8Encoding(); Response.ContentEncoding = encoding; using (XmlTextWriter xmlTextWriter = new XmlTextWriter(Response.OutputStream, encoding)) { xmlTextWriter.Formatting = Formatting.Indented; ////////////////// // style for RSS Feed viewed in browsers if (ConfigurationManager.AppSettings["RSSCSS"] != null) { string rssCss = ConfigurationManager.AppSettings["RSSCSS"].ToString(); xmlTextWriter.WriteWhitespace(" "); xmlTextWriter.WriteRaw("<?xml-stylesheet type=\"text/css\" href=\"" + cssBaseUrl + rssCss + "\" ?>"); } if (ConfigurationManager.AppSettings["RSSXsl"] != null) { string rssXsl = ConfigurationManager.AppSettings["RSSXsl"].ToString(); xmlTextWriter.WriteWhitespace(" "); xmlTextWriter.WriteRaw("<?xml-stylesheet type=\"text/xsl\" href=\"" + cssBaseUrl + rssXsl + "\" ?>"); } /////////////////////////// feed.Save(xmlTextWriter); } }
/// <summary> /// Reads the next RssElement from the stream. /// </summary> /// <returns> An RSS Element </returns> /// <exception cref="InvalidOperationException">RssReader has been closed, and can not be read.</exception> /// <exception cref="System.IO.FileNotFoundException">RSS file not found.</exception> /// <exception cref="System.Xml.XmlException">Invalid XML syntax in RSS file.</exception> /// <exception cref="System.IO.EndOfStreamException">Unable to read an RssElement. Reached the end of the stream.</exception> public RssElement Read() { bool readData = false; RssElement rssElement = null; int lineNumber = -1; int linePosition = -1; if (this.reader == null) { throw new InvalidOperationException("RssReader has been closed, and can not be read."); } do { bool pushElement = true; try { readData = this.reader.Read(); } catch (EndOfStreamException e) { throw new EndOfStreamException("Unable to read an RssElement. Reached the end of the stream.", e); } catch (XmlException e) { if (lineNumber != -1 || linePosition != -1) { if (this.reader.LineNumber == lineNumber && this.reader.LinePosition == linePosition) { throw this.exceptions.LastException; } } lineNumber = this.reader.LineNumber; linePosition = this.reader.LinePosition; this.exceptions.Add(e); // just add to list of exceptions and continue :) } if (readData) { string readerName = this.reader.Name.ToLower(); switch (this.reader.NodeType) { case XmlNodeType.Element: { //if (reader.IsEmptyElement) // break; // doesnt take empty elements into account :/ this.elementText = new StringBuilder(); switch (readerName) { case "item": // is this the end of the channel element? (absence of </channel> before <item>) if (!this.wroteChannel) { this.wroteChannel = true; rssElement = this.channel; // return RssChannel readData = false; } this.item = new RssItem.RssItem(); // create new RssItem this.channel.Items.Add(this.item); break; case "source": this.source = new RssSource(); this.item.Source = this.source; for (int i = 0; i < this.reader.AttributeCount; i++) { this.reader.MoveToAttribute(i); switch (this.reader.Name.ToLower()) { case "url": try { this.source.Url = new Uri(this.reader.Value); } catch (Exception e) { this.exceptions.Add(e); } break; } } break; case "enclosure": this.enclosure = new RssEnclosure(); this.item.Enclosure = this.enclosure; for (int i = 0; i < this.reader.AttributeCount; i++) { this.reader.MoveToAttribute(i); switch (this.reader.Name.ToLower()) { case "url": try { this.enclosure.Url = new Uri(this.reader.Value); } catch (Exception e) { this.exceptions.Add(e); } break; case "length": try { this.enclosure.Length = int.Parse(this.reader.Value); } catch (Exception e) { this.exceptions.Add(e); } break; case "type": this.enclosure.Type = this.reader.Value; break; } } break; case "guid": this.guid = new RssGuid(); this.item.Guid = this.guid; for (int i = 0; i < this.reader.AttributeCount; i++) { this.reader.MoveToAttribute(i); switch (this.reader.Name.ToLower()) { case "ispermalink": try { this.guid.PermaLink = bool.Parse(this.reader.Value); } catch (Exception e) { this.exceptions.Add(e); } break; } } break; case "category": this.category = new RssCategory(); if ((string)this.xmlNodeStack.Peek() == "channel") { this.channel.Categories.Add(this.category); } else { this.item.Categories.Add(this.category); } for (int i = 0; i < this.reader.AttributeCount; i++) { this.reader.MoveToAttribute(i); switch (this.reader.Name.ToLower()) { case "url": goto case "domain"; case "domain": this.category.Domain = this.reader.Value; break; } } break; case "channel": this.channel = new RssChannel.RssChannel(); this.textInput = null; this.image = null; this.cloud = null; this.source = null; this.enclosure = null; this.category = null; this.item = null; break; case "image": this.image = new RssImage(); this.channel.Image = this.image; break; case "textinput": this.textInput = new RssTextInput(); this.channel.TextInput = this.textInput; break; case "cloud": pushElement = false; this.cloud = new RssCloud(); this.channel.Cloud = this.cloud; for (int i = 0; i < this.reader.AttributeCount; i++) { this.reader.MoveToAttribute(i); switch (this.reader.Name.ToLower()) { case "domain": this.cloud.Domain = this.reader.Value; break; case "port": try { this.cloud.Port = ushort.Parse(this.reader.Value); } catch (Exception e) { this.exceptions.Add(e); } break; case "path": this.cloud.Path = this.reader.Value; break; case "registerprocedure": this.cloud.RegisterProcedure = this.reader.Value; break; case "protocol": switch (this.reader.Value.ToLower()) { case "xml-rpc": this.cloud.Protocol = RssCloudProtocol.XmlRpc; break; case "soap": this.cloud.Protocol = RssCloudProtocol.Soap; break; case "http-post": this.cloud.Protocol = RssCloudProtocol.HttpPost; break; default: this.cloud.Protocol = RssCloudProtocol.Empty; break; } break; } } break; case "rss": for (int i = 0; i < this.reader.AttributeCount; i++) { this.reader.MoveToAttribute(i); if (this.reader.Name.ToLower() == "version") { switch (this.reader.Value) { case "0.91": this.rssVersion = RssVersion.RSS091; break; case "0.92": this.rssVersion = RssVersion.RSS092; break; case "2.0": this.rssVersion = RssVersion.RSS20; break; default: this.rssVersion = RssVersion.NotSupported; break; } } } break; case "rdf": for (int i = 0; i < this.reader.AttributeCount; i++) { this.reader.MoveToAttribute(i); if (this.reader.Name.ToLower() == "version") { switch (this.reader.Value) { case "0.90": this.rssVersion = RssVersion.RSS090; break; case "1.0": this.rssVersion = RssVersion.RSS10; break; default: this.rssVersion = RssVersion.NotSupported; break; } } } break; } if (pushElement) { this.xmlNodeStack.Push(readerName); } break; } case XmlNodeType.EndElement: { if (this.xmlNodeStack.Count == 1) { break; } string childElementName = (string)this.xmlNodeStack.Pop(); string parentElementName = (string)this.xmlNodeStack.Peek(); switch (childElementName) // current element { // item classes case "item": rssElement = this.item; readData = false; break; case "source": this.source.Name = this.elementText.ToString(); rssElement = this.source; readData = false; break; case "enclosure": rssElement = this.enclosure; readData = false; break; case "guid": this.guid.Name = this.elementText.ToString(); rssElement = this.guid; readData = false; break; case "category": // parent is either item or channel this.category.Name = this.elementText.ToString(); rssElement = this.category; readData = false; break; // channel classes case "channel": if (this.wroteChannel) { this.wroteChannel = false; } else { this.wroteChannel = true; rssElement = this.channel; readData = false; } break; case "textinput": rssElement = this.textInput; readData = false; break; case "image": rssElement = this.image; readData = false; break; case "cloud": rssElement = this.cloud; readData = false; break; } switch (parentElementName) // parent element { case "item": switch (childElementName) { case "title": this.item.Title = this.elementText.ToString(); break; case "link": this.item.Link = new Uri(this.elementText.ToString()); break; case "description": this.item.Description = this.elementText.ToString(); break; case "author": this.item.Author = this.elementText.ToString(); break; case "comments": this.item.Comments = this.elementText.ToString(); break; case "pubdate": try { this.item.PubDate = DateTime.Parse(this.elementText.ToString()); } catch (Exception e) { try { string tmp = this.elementText.ToString(); tmp = tmp.Substring(0, tmp.Length - 5); tmp += "GMT"; this.item.PubDate = DateTime.Parse(tmp); } catch { this.exceptions.Add(e); } } break; } break; case "channel": switch (childElementName) { case "title": this.channel.Title = this.elementText.ToString(); break; case "link": try { this.channel.Link = new Uri(this.elementText.ToString()); } catch (Exception e) { this.exceptions.Add(e); } break; case "description": this.channel.Description = this.elementText.ToString(); break; case "language": this.channel.Language = this.elementText.ToString(); break; case "copyright": this.channel.Copyright = this.elementText.ToString(); break; case "managingeditor": this.channel.ManagingEditor = this.elementText.ToString(); break; case "webmaster": this.channel.WebMaster = this.elementText.ToString(); break; case "rating": this.channel.Rating = this.elementText.ToString(); break; case "pubdate": try { this.channel.PubDate = DateTime.Parse(this.elementText.ToString()); } catch (Exception e) { this.exceptions.Add(e); } break; case "lastbuilddate": try { this.channel.LastBuildDate = DateTime.Parse(this.elementText.ToString()); } catch (Exception e) { this.exceptions.Add(e); } break; case "generator": this.channel.Generator = this.elementText.ToString(); break; case "docs": this.channel.Docs = this.elementText.ToString(); break; case "ttl": try { this.channel.TimeToLive = int.Parse(this.elementText.ToString()); } catch (Exception e) { this.exceptions.Add(e); } break; } break; case "image": switch (childElementName) { case "url": try { this.image.Url = new Uri(this.elementText.ToString()); } catch (Exception e) { this.exceptions.Add(e); } break; case "title": this.image.Title = this.elementText.ToString(); break; case "link": try { this.image.Link = new Uri(this.elementText.ToString()); } catch (Exception e) { this.exceptions.Add(e); } break; case "description": this.image.Description = this.elementText.ToString(); break; case "width": try { this.image.Width = Byte.Parse(this.elementText.ToString()); } catch (Exception e) { this.exceptions.Add(e); } break; case "height": try { this.image.Height = Byte.Parse(this.elementText.ToString()); } catch (Exception e) { this.exceptions.Add(e); } break; } break; case "textinput": switch (childElementName) { case "title": this.textInput.Title = this.elementText.ToString(); break; case "description": this.textInput.Description = this.elementText.ToString(); break; case "name": this.textInput.Name = this.elementText.ToString(); break; case "link": try { this.textInput.Link = new Uri(this.elementText.ToString()); } catch (Exception e) { this.exceptions.Add(e); } break; } break; case "skipdays": if (childElementName == "day") { switch (this.elementText.ToString().ToLower()) { case "monday": this.channel.SkipDays[0] = true; break; case "tuesday": this.channel.SkipDays[1] = true; break; case "wednesday": this.channel.SkipDays[2] = true; break; case "thursday": this.channel.SkipDays[3] = true; break; case "friday": this.channel.SkipDays[4] = true; break; case "saturday": this.channel.SkipDays[5] = true; break; case "sunday": this.channel.SkipDays[6] = true; break; } } break; case "skiphours": if (childElementName == "hour") { this.channel.SkipHours[Byte.Parse(this.elementText.ToString().ToLower())] = true; } break; } break; } case XmlNodeType.Text: this.elementText.Append(this.reader.Value); break; case XmlNodeType.CDATA: this.elementText.Append(this.reader.Value); break; } } } while (readData); return(rssElement); }
// Get basic data for Item private void SetBasicItemData(AdvancedRssItem RssItemSource, RssItem RssItemDest) { //Title if (RssItemSource.Title != null) { RssItemDest.Title = RssItemSource.Title; } //Author if (RssItemSource.Author != "" && RssItemSource.Author != "") { RssItemDest.Author = RssItemSource.Author; } //Category if (RssItemSource.Category != null) { foreach (String item in RssItemSource.Category) { RssItemDest.Categories.Add(new RssCategory(item)); } } //Content of the RSS if (RssItemSource.Description != null) { RssItemDest.Description = RssItemSource.Description; } //Link of info if (RssItemSource.Link != null && RssItemSource.Link != "") { try { RssItemDest.Link = new Uri(RssItemSource.Link); } catch { } } //Publiched date if (RssItemSource.PubDate != null) { RssItemDest.PublicationDate = RssItemSource.PubDate; } //Enclosure (attachment) if (RssItemSource.Enclosureurl != null && RssItemSource.Enclosureurl != "") { try { string enclosMimeType = ""; if (RssItemSource.Enclosuretype != null) { enclosMimeType = RssItemSource.Enclosuretype; } RssEnclosure newEnclosure = new RssEnclosure(RssItemSource.Enclosurelength, enclosMimeType, new Uri(RssItemSource.Enclosureurl)); RssItemDest.Enclosures.Add(newEnclosure); } catch { } } //Comment info (number isn't a correct rss tag but maybe util) if (RssItemSource.Commenturl != null && RssItemSource.Commenturl != "") { try { RssItemDest.Comments = new Uri(RssItemSource.Commenturl); } catch { } } }