private WebFeed(IFeed feed) { items = new List<Item>(); title = feed.Title; link = feed.Link; description = feed.Description; path = feed.Path; lastWriteTime = feed.LastWriteTime; foreach (IFeedItem item in (IFeedsEnum)feed.Items) { Item rssItem = new Item(item); // only add items that have enclosures if (rssItem.Enclosure != null) items.Add(rssItem); } }
/// <summary> /// Private constructor to be used with factory pattern. /// </summary> /// <exception cref="System.Xml.XmlException">Occurs when the XML is not well-formed.</exception> /// <param name="xmlNode">An XML block containing the RSSFeed content.</param> private WebFeed(XmlNode xmlNode) { XmlNode channelNode = xmlNode.SelectSingleNode("rss/channel"); items = new List<Item>(); title = channelNode.SelectSingleNode("title").InnerText; link = channelNode.SelectSingleNode("link").InnerText; description = channelNode.SelectSingleNode("description").InnerText; XmlNodeList itemNodes = channelNode.SelectNodes("item"); foreach (XmlNode itemNode in itemNodes) { Item rssItem = new Item(itemNode); // only add items that have enclosures if (rssItem.Enclosure != null) items.Add(rssItem); } }
public void Load () { DateTime loadstart = DateTime.Now; List<WebFeed> newRssFeeds = new List<WebFeed>(); try { IFeedsManager fs = new FeedsManagerClass(); IFeedFolder folder = (IFeedFolder)fs.GetFolder(Properties.Settings.Default.ImagePathOverride); foreach (IFeed feed in FeedUtility.CommonFeedList(folder)) { System.Diagnostics.Debug.Print("Found feed {0} with {1} items.", feed.Name, ((IFeedsEnum)feed.Items).Count); try { WebFeed rssFeed = WebFeed.FromApi(feed); // Only add this feed if it contains items if (rssFeed != null) { System.Diagnostics.Debug.Print("Feed has {0} items with enclosures.", rssFeed.Items.Count); if (rssFeed.Items.Count > 0) newRssFeeds.Add(rssFeed); } else System.Diagnostics.Debug.Print("Feed is null."); } catch (System.Runtime.InteropServices.COMException ex) { System.Diagnostics.Debug.Print("Failed to get RSS feed '{0}' from API; skipping feed. Error: {1} ", feed.Name, ex.ToString()); // Ignore exception, meaning ignore this feed and continue with next feed. } } } finally { // Collect garbage so that all the COM objects are released which // closes the backing structured storage files. GC.Collect(); } if (newRssFeeds.Count == 0) { // There were no suitable feeds, hence get default feeds from resources. System.Diagnostics.Debug.Print("There were no suitable feeds, hence get default feeds from resources."); WebFeed rssFeed = WebFeed.FromText(Properties.Resource.DefaultRSSText); newRssFeeds.Add(rssFeed); } this.webFeeds = newRssFeeds; // reset current indexes currentFeedIndex = -1; currentItemIndex = -1; MoveNext(); lastRefresh = loadstart; }