public void Refresh () { if (lastRefresh == DateTime.MinValue) { // we never successfully loaded the CFL, so let's do it again Load(); return; } IFeedsManager fs = new FeedsManagerClass(); try { IFeedFolder folder = (IFeedFolder)fs.GetFolder(Properties.Settings.Default.ImagePathOverride); foreach (IFeed feed in FeedUtility.LastWriteSince(folder, lastRefresh)) { WebFeed rssFeed = null; try { // This feed was updated or is new, let's get it. rssFeed = WebFeed.FromApi(feed); } 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()); continue; // Skip this feed. } // If the feed has no items with picture enclosures then skip it. if (rssFeed == null || rssFeed.Items.Count == 0) { System.Diagnostics.Debug.Print("Feed '{0}' does not have any picture enclosures; skipping feed.", feed.Name); continue; } // Before we add it let's see if we have an old version of the feed. int index = webFeeds.FindIndex(delegate(WebFeed f) { return (f.Path == rssFeed.Path); }); if (index == -1) { // This must be a new feed, let's append it to the list. webFeeds.Add(rssFeed); } else { // We have an existing feed with the same path. Let's insert it // where the previous feed is at. webFeeds.Insert(index, rssFeed); // Remove previous feed. webFeeds.RemoveAt(index + 1); // Assure that current indexes are not out of bounds. ValidateIndexes(); } } } finally { GC.Collect(); // Release all COM objects and their file handles. lastRefresh = DateTime.Now; } }
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; }