Introduction to Windows RSS Platform

by Keyvan Nayyeri
Summary
As a 3D RSS reader, UniveRSS uses Windows RSS Platform to manage and work with feeds. Windows RSS Platform is a rich set of APIs that come with Internet Explorer 7 and enable great features for developers to manage, work and use RSS or Atom feeds.

In this article, third article of our articles about UniveRSS showcase, we introduce Windows RSS Platform and show its principles because it’s a main part of UniveRSS code and architecture.
Introduction
The most popular web browser in our world released its latest version (7.0) last year. Internet Explorer 7.0 came with several enhancements in different aspects of its preceding versions. In addition to major improvements in user interface and support for web standards and better security and performance, there was something new and interesting for developers and feed fans: the Windows RSS Platform.

In Internet Explorer 7.0 you’re able to add feeds from your favorite sites to your feed list and read them from a built-in reader. But this built-in reader is not as powerful as other common readers available and is just designed for quick access. The important point behind this feature is that it is a great platform that is built to provide all essential means to work with RSS or Atom feeds for developers. When you install IE 7.0 then this platform comes to your machine and lets you to use it. It means that developers can design their applications to use this platform’s capabilities and save their time from writing all low levels of working with feeds. Previously each feed reader had to have its own codes and components for this purpose. There are some advantages of having such a platform:
  • Easier development without the need to write all codes to work with feeds and feed items directly.
  • Easier process to manage feed lists for users. User adds his or her feeds to one place, edits or removes them there (Internet Explorer or any other application that can interact with Windows RSS Platform to manage feeds) but several applications can share these feeds.
  • Enhanced capabilities for working with feeds and organizing them. This means that Windows RSS Platform provides all essential means for developers and contains all features that are necessary for a feed reader application.
Moreover Microsoft has released some implementations in other applications with better features than the built-in reader in IE 7.0. For example Office 2007 comes with a built-in support for a feed reader in Outlook 2007. This feed reader (which is completely integrated with Outlook and lets you to mark or flag an item or email it or …) uses Windows RSS Platform to fetch data, manage feeds and work with them.
As another RSS reader that is built for .NET 3.0 and Windows Vista, UniveRSS (our case study) uses Windows RSS Platform to deal with feeds. So in this part of our articles about this showcase we want to discover Windows RSS Platform in general and introduce its capabilities. Understanding the principle of Windows RSS Platform lets you to understand UniveRSS code easier because a main part of UniveRSS architecture is dedicated to consume these APIs.
Getting Started
Apparently the first step to start development with the RSS Platform is to add its APIs to your applications. When you install Internet Explorer 7.0 on your machine it creates a new COM component (named Microsoft Feeds) for you and you can use this COM component to get benefits of RSS Platform. Therefore if you create a new project in Visual Studio, Right Click on solution and choose Add Reference item then open COM tab, Microsoft Feeds should be listed there (Figure 1).

Figure 1

Intro RSS Figure 1
Before talking about some technical details of Windows RSS Platform and its APIs it’s better to talk about its structure in general because this helps you to understand API easier. We will also talk about main classes and objects that play a role in this platform and as another main topic we will discover the process of updating a feed in Feed Download Engine in a nutshell.
Basic Information
Root and first object in RSS platform is FeedsManager. This object provides some basic means to work with feed folders and feeds. Feeds can be organized into folders and subfolders. There is a mapping between file system directories and these folders and subfolders so you can have a good imagination from here. Each folder can have some subfolders (or no subfolder) and/or some feeds (or no feed).

And XAML has striking benefits over older technologies and has an excellent implementation in conjunction with Windows Presentation Foundation.

IFeedFolder is a code representation of a folder. It provides all necessary properties and methods to work with folders and to manage their subfolders and feeds.

Like IFeedFolder, IFeed is a code representation for a feed and has several properties and methods to work with feeds.

Each feed has a collection of feed items. IFeedItem represents an item in this collection and actually provides some read only properties to get access to RSS 2.0 elements in a feed. In RSS 2.0 each feed item can have an enclosure which is a file attachment for a feed item. IFeedEnclosure is the object that helps you to work with enclosures.

You can find a full description about all properties and methods of above objects on MSDN. Later in this article we will discover an example to show basics of development with RSS platform.
Feed Download Engine
But how does RSS platform updates feeds and feed items to synchronize local data with servers? You will see the answer in the next paragraphs. Understanding the process that will be followed to synchronize feeds is important for us in UniveRSS because UniveRSS doesn’t add, remove or edit anything except using what RSS platform and its download engine have produced.

RSS platform has a Feed Download Engine which does all updates for you. Two main parameters were important for RSS platform developers at the time when developing the download engine. It works based on connection bandwidth and CPU usage and also its impact of servers. These two parameters (client resources and server resources) make this engine a great engine to be compatible with all clients and all web servers.

There are some options to set the interval of updates for feeds in platform. In addition to these options (that will be described in next paragraphs) users can update a feed or all feeds manually whenever they like but usually users use the automatic option.

On the other hand we can split the automatic option again into two options. First option is to let users set the interval for a feed to schedule automatic updates. The second option is to update feeds based on some formulas on a regular basis.

Before stepping into describing the download engine it’s better to talk about some concepts that will be used:

  • LastDownloadTime is a property for each feed that specifies the last time when it is synchronized and has a main role in automatic update calculations.
  • TTL (Time To Live) is a value that is determined by feed authors and specifies how often a feed is updated. This value has an important effect on the interval with which a feed will be updated by the download engine.
  • Download engine will update up to four feeds at a time in parallel and no more than this.
  • “Pending” feeds are some feeds that are queued in feed download engine and are ready to be updated. Download engine takes feeds for synchronization from this queue based on their priority.
  • Update interval is a value that user sets for individual feeds to override default schedule interval. If a feed has an interval, it will be updated based on this interval not the default interval. Default interval for all feeds is 24 hours.
Well, the process that will be followed for automatic updates is simple. This engine creates a task that will occur every 5 minutes regularly and does some steps to synchronize feeds.

At first step two groups of feeds will be updated:
  • Feeds in pending queue having zero as their LastDownloadTime.
  • Feeds in queue which have elapsed their update interval.
Whenever a feed is updated successfully its LastDownloadTime will be set to current time otherwise it will get a higher priority in pending queue.
Each feed may be updated based on user settings and it's TTL. Next synchronize time (TS) for a feed can be calculated by a formula as described on MSDN:
TS = LastDownloadTime + MAX(TTL, Interval) * (1.0 + RANDOM (0.1))
This formula guarantees that all feeds will be updated at good times regarding different parameters that play in synchronization scenario. A feed will be updated when the current time is greater or equal to TS.
Sample Application
In this part we discover a sample application to understand the development process for Windows RSS Platform in a Windows Application. In a nutshell we want to:
  • Check for existence of MSDN Blogs RSS feed in system feeds.
  • If MSDN Blogs feed is added, we can go to next step otherwise we will add it to the feeds list in the root folder.
  • Create an instance of the MSDN Blogs feed and synchronize it.
  • Add all feed items in this feed to a list.
  • Sort all feed items in this list by publication date descending.
  • Bind the list to a GridView control to view all data from feed items.
This can be a good example to see some common objects in action, like "User clicks on a button to see feed items data in GridView". I can recommend you to go back and forth and close the window, go to Internet Explorer 7.0 and read some items from this feed then go back and update your data to see better details. Attend to LastDownloadTime column and compare it with your current time and the previous times that you had launched this application. Also attend to the IsRead column and notice the effect of viewing feeds.

Source code of this example (the code that will run after clicking on the button) is as you see below. Output is similar to what is presented in Figure 2.

In this code, first I create an instance of FeedsManagerClass then use its IsSubscribed method to check if MSDN Blogs is in repository. If it isn’t there then I add it.

After this I create an instance of IFeed for MSDN Blogs feed and call its AsyncDownload method to update its items. Now I can iterate through its items by converting its Items property from object to IFeedsEnum. On each iteration I add an IFeedItem to my list.

When this loop ends, my items are added in same order as they were in repository. But now I want to sort them descending by publication date. Therefore I call the List.Sort method and pass a delegate to it, which returns a Comparer to sort items.

At the end it’s easy to bind my GridView to this list and show my items.
private void btnStart_Click(object sender, EventArgs e)

{
    IFeedsManager feedsManager = new FeedsManagerClass();
    
    // check if feed exists in repository
    if (!feedsManager.IsSubscribed(
    "http://blogs.msdn.com/MainFeed.aspx"))
    
    {
    // add feed to repository
    IFeedFolder folder = feedsManager.RootFolder as IFeedFolder;
    folder.CreateFeed("MSDN Blogs", 
    "http://blogs.msdn.com/MainFeed.aspx");
    }

    // create an instance of feed
    IFeed feed = feedsManager.GetFeedByUrl
    ("http://blogs.msdn.com/MainFeed.aspx") as IFeed;

    // synchronize feed
    feed.AsyncDownload();

    // get all items for feed
    List<IFeedItem> items = new List<IFeedItem>();

    // iterate through feed items
    foreach (IFeedItem item in (IFeedsEnum)feed.Items)
    {
        items.Add(item);
    }

    // sort items in list
    items.Sort(delegate(IFeedItem feed1, IFeedItem feed2)
    {

    return Comparer<DateTime>.
    Default.Compare(feed2.PubDate, feed1.PubDate);

    });

    // show items in GridView
    RSSData.DataSource = items;
    RSSData.Refresh();
}

Figure 2

Click on the image to open it in a separate window
Intro RSS Figure 2

Further Reading
Here we just discovered some general topics. Windows RSS Platform isn’t a huge platform so it’s easy to learn this platform by spending a short time. Here are some references for further reading about RSS Platform:
Sample Code referred to in this article is available for downloading as a Zip-File.
Keyvan Nayyeri has been a geek and programmer since he was 10. He has a BS degree in Applied Mathematics and as an experienced software architect and developer he is also a MVP from Telligent for Community Server technology. Keyvan is a co-author for Wrox press and also an author for ASP Alliance, DotNetSlackers and Code Project .NET communities. Currently he’s contributed in some projects such as BlogML, CSModules and Windows Live Writer Plugins. He edits his blog on .NET, Community Server and Technology.
The showcases on the Panel website provide examples of the possibilities within the new technologies and source codes serving as a blueprint for beginners learning to leverage these technologies. The development of the UniveRSS feed reader and other showcases on the Panel website are accompanied by articles with detailed information on the projects' underlying technologies.

The following topics are featured in this series of articles:
  • An introduction to UniveRSS, Windows Presentation Foundation, XAML and Internet Explorer 7 platform.
  • General architecture of UniveRSS and step by step guide of its development details.
  • An overview of the Windows RSS Platform
  • The use of animations in WPF
  • An overview of the UniveRSS Architecture
You can subscribe to your local MSDN Flash newsletter using the Panel registration to get notifications about new parts of our articles.
© 2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement