RSS Feeder.NET is a free open source desktop RSS feed aggregator which downloads feeds from web sources and stores them locally for offline viewing, searching and processing. It is also a rich blogging tool which you can use to blog a variety of blog engines including WordPress, B2Evolution, .Text, Community Server etc. You can be fully MS Outlook® dependent or can run fully standalone. You can also use both at the same time whichever you find comfortable to work with. It does not increase the Outlook load time, nor does it make the Outlook slow or prevent it from closing properly. It is a Smart Client that makes best use of both Local Resource and Distributed Web Information sources.

Blog from Outlook. You can specify an Outlook folder for a weblog account. All the posts from that folder is automatically posted to the weblog during synchronization. You can write posts as HTML using Word editor. Post content (HTML markup) is cleaned rigorously before posting to the weblog.

Outlook View. It uses a customized view to present a more readable list of feeds in Outlook Folders. The standard Post view is not easy to browse through quickly. The view puts the subject first in bold and an excerpt of the post under the subject.

Optimized Startup. You can safely put RSS Feeder at startup and it won’t make your Windows® start slower. A clever lazy loading process puts no effort on Windows® during startup instead starts the app when Windows® has finally regained its strength after the long boot up struggle.

Newsgator Import. Newsgator users can use RSS Feeder to import all the subscriptions and seamlessly replace Newsgator without modifying the Outlook folder locations.

The three pane view of Outlook is a user interface engineering marvel. It makes browsing through information fast and easy. In RSS Feeder, I have followed the same concept. The left most pane is the channel list. When you click a channel you see the list of feeds in the middle list. You can instantly search through feeds using the search box at the bottom middle. When you click on a feed, the feed content is displayed on the right side viewer.

You can directly edit channel properties from the left bottom property grid. Click on the title “Properties” to show the property grid. .NET’s built in property grid makes it very convenient to expose objects and allow users to modify the objects conveniently. I have implemented several extensions on property grid which I will be explaining later on.

The most convenient reading view for blogs is the newspaper style view which I call “The Daily Blogpapper”. You can just open the Blogpaper, read through all the latest posts collected from all the channels (optionally excluded) and click on “Mark as Read”. It’s as simple as this.

The previous Outlook style view is useful to work with feeds and channels. But it is not a convenient reading environment. The Blogpaper gives you a truly comfortable reading environment for everyday reading.

RSS Feeder is not just an RSS Aggregator; it’s also an equally powerful feature rich blogging tool.

Outlook 2003 style view is created using the amazing free UI components which you can find at Divelements Ltd. On the left side, you can see the weblogs accounts and your posts in that account. The right side is the editing environment.

RSS Feeder currently supports MetaWebLogAPI supported blog engines like WordPress, B2Evolution, Drupal etc. and also some XML web service based blog engines like .Text and Community Server. We will see how we can implement these in detail later on.

If you don’t like my app, you can remain a MS Outlook user. When you install the application, it will ask you whether you need Outlook integration. You just need to specify a base folder which will contain all the child channel folders and the RSS Feeder will feed Outlook with all the feeds.

The convenient view of feed list makes it very easy to skim through lots of post rapidly. The auto preview also gives a glimpse of the post content eliminating the need to open each post and we can decide whether to keep or throw it away.

This is my favorite, you can create posts in an Outlook folder and then create a web log account which maps to that folder. All the posts in that folder are delivered to the web log. You can drag posts from some other place or can write new posts in that folder. Whenever RSS Feeder runs its periodical synchronization (every 5 mins) it will read the posts from the folder and then send the posts to the corresponding blog site.

The Send/Receive window of RSS Feeder gives you detailed statistics about feed synchronization. You can view the errors received from the server, you can see the speed of your internet connection and the number of feeds sent to Outlook.

While posting blogs, it also gives you the post ID generated from the server or the detail error message received while posting.

Newsgator import

RSS Feeder will automatically import Newsgator settings including all the subscription and Outlook folders at first run. This gives you zero effort for migrating from Newsgator to RSS Feeder.

In order to qualify an application as a smart client, the application needs to fulfill the following requirements according to the definition of Smart Client at MSDN.

Local resources and user experience

All smart client applications share an ability to exploit local resources such as hardware for storage, processing or data capture such as compact flash memory, CPUs and scanners for example. Smart client solutions offer hi-fidelity end-user experiences by taking full advantage of all that the Microsoft® Windows® platform has to offer. Examples of well known smart client applications are Word, Excel, MS Money, and even PC games such as Half-Life 2. Unlike "browser-based" applications such as Amazon.Com or eBay.com, smart client applications live on your PC, laptop, Tablet PC, or smart device.

Connected

Smart client applications are able to readily connect to and exchange data with systems across the enterprise or the internet. Web services allow smart client solutions to utilize industry standard protocols such as XML, HTTP and SOAP to exchange information with any type of remote system.

Offline capable

Smart client applications work whether they are connected to the Internet or not. Microsoft® Money and Microsoft® Outlook are two great examples. Smart clients can take advantage of local caching and processing to enable operation during periods of no network connectivity or intermittent network connectivity. Offline capabilities are not only used in mobile scenarios but also by desktop solutions where they can take advantage of offline architecture to update backend systems on background threads, thus keeping the user interface responsive and improving the overall end-user experience. This architecture can also provide cost and performance benefits since the user interface need not be shuttled to the smart client from a server. Since smart clients can exchange just the data needed with other systems in the background, reductions in the volume of data exchanged with other systems are realized (even on hard-wired client systems this bandwidth reduction can realize huge benefits). This in turn increases the responsiveness of the user interface (UI) since the UI is not rendered by a remote system.

Intelligent deployment and update

In the past traditional client applications were difficult to deploy and update. It was not uncommon to install one application only to have it break another. Issues such as "DLL Hell" made installing and maintaining client applications difficult and frustrating. The Updater Application Block for .NET from the patterns and practices team provides prescriptive guidance to those who wish to create self-updating .NET Framework-based applications that are deployed across multiple desktops. The release of Visual Studio 2005 and the .NET Framework 2.0 will beckon a new era of simplified smart client deployment and updating with the release of a new deploy and update technology known as ClickOnce.

Local resources and user experience

After downloading the application, it runs locally, stores all the feeds and your personal blogs in an MS Access Database and XML store respectively. It also gives you a rich user interface like Outlook 2003 to work with. As a result, you get the full benefits of desktop convenience yet all the information you are working with are produced in some web source.

Connected

The application connects to RSS Feed sources using HTTP and downloads the feeds to local store. It uses XML RPC for XMLRPC enabled blog engines in order to post web logs. Some of the famous XMLRPC supported blog engines are WordPress, B2Evolution, Drupal etc. It also uses Web Service to communicate with Blog engines like .Text and CommunityServer.

Offline capable

The application is fully offline capable. When it is not connected, you read the feeds from local store which are already downloaded. But when it gets connected, it automatically downloads recent feeds in the background and updates the view seamlessly.

Intelligent deployment and update

The application uses Updater Application Block 2.0 to provide auto update feature. Whenever I release a new version or deploy some bug fixes to a central server, all the users of that application automatically get the update behind the scene. This saves each and every user from going to the website and downloading the new version every time I release something new. It also allows me to instantly deliver bug fixes to everyone within a very short time.

Error reporting

This is my personal requirement for smart client. As the smart client is running on a distant computer, unlike web sites, you do not know whether the users are facing any problems or not and whether the applications are generating any exceptions. We need to provide some kind of error reporting feature that automatically captures the error and transmits the error to some central server so that the error can be fixed. You have seen this error reporting feature in Windows XP or Office 2003 applications. Whenever there is an error, it sends the error report to Microsoft. Similarly, this application also traps errors behind the scene and sends the exception trace to a tracking system at Sourceforge.

Multithreaded

Another favorite requirement of mine for making a client really smart is to make the application fully multithreaded. Smart clients should always be responsive. It must not get stuck whenever it is downloading or uploading data. Users will keep on working without knowing that there is something big going on in the background. For example, while a user is writing a blog, the application should download the feeds in the background without hindering the user’s authoring environment at all.

Crash proof

A smart client becomes a dumb client when it crashes in front of a user showing the dreaded “Continue” or “Quit” dialog box. In order to make your app truly smart, you need to catch any unhandled error and publish the error safely. In this app, I will show you how this has been done.

RSS Feeder is a complete application which deals with XML, XSLT, HTML, HTTP GET/POST, Configuration management, Cryptography, Logging, Auto Update, Rich UI, RSS/RDF/ATOM feed processing, XML RPC, Web Service, Blogging, Outlook automation, Multithreading and a lot more. Covering all these in detail requires the volume of a book. So, in this article I will just cover the tips and tricks I have used in all these areas. By the time you reach the end of this article, you will be fully equipped with real life experience of making a rich connected Smart Client application implementing the best practices and neat tricks you can find all over the web.

Enterprise Library is a major new release of the Microsoft patterns and practices application blocks. Application blocks are reusable software components designed to assist developers with common enterprise development challenges. Enterprise Library brings together new releases of the most widely used application blocks into a single integrated download.

Extensibility: All application blocks include defined extensibility points that allow developers to customize the behavior of the application blocks by adding it in their own code.

Ease of use: Enterprise Library offers numerous usability improvements, including a graphical configuration tool, a simpler installation procedure, and a clearer and more complete documentation and samples.

Integration: Enterprise Library application blocks are designed to work together and are tested to make sure that they do. It is also possible to use the application blocks individually (except in cases where the blocks depend on each other, such as on the Configuration Application Block).

Application blocks help address the common problems that developers face in every project. They have been designed to encapsulate the Microsoft recommended best practices for .NET applications. They can be added into .NET applications quickly and easily. For example, the Data Access Application Block provides access to the most frequently used features of ADO.NET in simple-to-use classes, boosting developer productivity. It also addresses scenarios not directly supported by the underlying class libraries. (Different applications have different requirements and you will find that every application block is not useful in every application that you build. Before using an application block, you should have a good understanding of your application requirements and of the scenarios that this application block is designed to address.)

RSS Feeder uses the following application blocks:

Caching Application Block: Caching frequently accessed data like the XSLT file which renders HTML from RSS feeds every time you click on an RSS Feed.

The Updater Application block is a real pain to implement. After trying for weeks, I have finally given up its default BITSDownloader which does not work at all in my case. I have started using HTTPDownloader which works without any problem. When I use BITSDownloader I always get an error that the response header does not contain Content-Length. But if I capture the traffic, I can clearly see that Content-Length is present in the HTTP Response header. So, I have moved to the HTTPDownloader created by Kent Boogaart, for Katersoft. The HTTPDowloader uses nothing but the built-in HttpWebRequest to download the files from the server. It works both synchronously and asynchronously which suites all update scenarios.

The updater works this way:

First it gets the URL of the manifest XML. A manifest is prepared and stored in a server which describes the files that are needed to be downloaded.

After downloading the manifest, first it finds out the files that are needed to be downloaded according to the manifest. The it starts downloading them.

Once the download is complete, it spawns a console application which waits until RSS Feeder closes.

When RSS Feeder closes, the console application performs the updates and quits.

One problem I faced while downloading manifest is that the Proxy caches manifests. Normally your internet service provider uses proxies to cache web content. As XML is a web content, proxy servers nowadays cache XML files. As a result, even if I frequently update the manifest XML on the server, the proxies do not update their cache accordingly and returns an old version of the manifest file. This prevents auto update.

In order to solve this, I have injected a tick count at the end of the URI of the manifest. This always produces a unique URL and thus prevents proxies from returning old content.

When you implement auto update in your application, you will come across a dilemma, whether to overwrite an older file with a newer file or not. For example, my RSS Feeder has several XSLT files which render RSS feeds to HTML. Now, the user has the freedom to change those files. So, if I release a new version of the file, I cannot overwrite those files without knowing whether the user has changed them or not. But I do need to update it because I may have fixed some problems in some of the files. Now you may think, duh! It’s an easy solution. Just check if the file dates are equal to the EXE’s date. If it is then the user has not changed the file. This is not always true because I release the updated EXE frequently. So, I cannot compare with the EXE’s date. The only way we can ensure we do not overwrite files accidentally is to preserve MD5 hash of each file and before copying ensure if the hash matches. I am not sure whether it is built into Updater Application block, but it would be nice to have this feature that automatically checks whether MD5 of a particular file matches before it overwrites a file.

Enterprise Library is a great piece of work. It can really take off a lot of framework development load from any type of application you develop. Normally when we go for developing a new project, we start with a framework which provides configuration management, security, cryptography, database access etc. All these require time to integrate and test. Enterprise Library saves you from developing such framework because it provides the best practices collected from years of experience of successful projects.

However, using Enterprise Library classes directly from all layers of your application is problematic. Very soon, you will feel the need for a wrapper class. Also, as it is a generic library, you first need to customize it a bit before getting started. Here I will present some extra tweaking that you can use to get started with Enterprise Library.

If you want to use Security Block classes, you need to specify the security provider name e.g. MD5CryptoServiceProvider:

Cryptographer.CreateHash( "MD5CryptoServiceProvider", “hash me” );

So, very soon, your code will be full of EL classes and when any class’s signature changes or new version is released, as it did from Pattern and Practices Application Blocks to the new Enterprise Library, you will have to perform Search and Replace throughout your project to upgrade your code. This is a real pain. So, what I have done here is, I have made an Enterprise Library Helper class named EntLibHelper which you can use in the following way:

So, next time, when Microsoft releases something called Universal Library, all you need to do is change the code inside EntLibHelper. Moreover, EntLibHelper handles all the troubles of initializing Enterprise Library blocks, ensures proper usage and provides a convenient interface which frees developers from remembering EL interfaces.

Check the source code for EntLibHelper. Remember, it is compatible with the app.config for RSSFeeder. If you make changes in any of the names, for example, renaming Logging Category or changing MD5 hashing to SHA hashing, you will have to change the names specified in the constants at the top of the class.

Channels is a collection of Channel which represents a source of RSS feed. Channel is a collection of RSSFeed objects. RSSFeed object contains some basic information about a post like title, publish date, and the GUID which uniquely identifies a particular item. The entire XML received for each item is stored in the XML field.

Some of the items are extracted from the original XML to the RSS object for faster access. For example, when we render the list of feeds in a Listview, we need to show the title and the publish date. Moreover we need to sort on the publish date. This is why some of the fields are duplicated in the RSSFeed object which is taken from the actual XML.

Generally both RSS and Atom XML contain the title of the post, the author’s name, a unique ID, link to the post, publish date and a detail body.

The root node is <rss> which contains one or more <channel> nodes. <item> node represents one post. The body of the post is available in the <description> node. Some RSS Feed generators write both HTML and plain text content inside the <description>. However, some advanced generators write a plain text version inside the <description> and the actual HTML version with all the formatting inside the <content:encoded> node.

Uniquely identifying an item is troublesome because not all sites generate the guid node. For example, CodeProject RSS feeds contain no guid node. As a result, the only option you have to uniquely identify a feed is either to generate an MD5/SHA hash of the entire content and use that hash value as identifier or use the link node. RSS Feeder first looks whether there is any guid node, if not it uses the link node as the unique identifier. (To CodeProject: If this is not correct, let me know.)

Not all sites follow the RSS 2.0 format. Some sites are still using the RSS 0.9 format. Even those who do follow, do not always generate all the nodes properly. An example is the CodeProject RSS feeds, where you can see that the guid node is missing. You need to be careful while parsing RSS.

<?xmlversion="1.0"encoding="utf-8"?><feedversion="0.3"xml:lang="en-US"xmlns="http://purl.org/atom/ns#"><title>.NET Community Blog</title><linkrel="alternate"type="text/html"href="http://localhost/b2evolution/index.php"/><tagline>.NET Community Blog</tagline><generatorurl="http://b2evolution.net/"version="0.9.0.10">b2evolution</generator><modified>1970-01-01T00:00:00Z</modified><entry><titletype="text/plain"mode="xml">Important information</title><linkrel="alternate"type="text/html"href=http://localhost/b2evolution/index.php... /><author><name>admin</name></author><id>http://localhost/b2evolution/index.php?...</id><issued>2005-06-17T10:05:52Z</issued><modified>1970-01-01T00:00:00Z</modified><contenttype="text/html"mode="escaped"><![CDATA[<span class="code-SummaryComment"> <p>Blog B contains a few posts in the
'b2evolution Tips' category.</p>
<p>All these entries are designed to help you so,
as EdB would say:
"<em>read them all before you start
hacking away!</em>" ...]]></span></content></entry>

Atom type is also similar but looks a bit better to me than the RSS 2.0 format. The better things that I have noticed are, one the content node which has a nice type attribute that defines the type of the content. The mode attribute that helps to identify whether HTML decoding is required or not. It also has a nice id attribute which uniquely identifies an entry. The nodes are obvious and best of all; everyone generates consistent output when they produce Atom feed whereas RSS has several versions that are still widely being used.

When you make an RSS aggregator, you will soon realize that people do not follow a consistent date format. Some use .NET’s DateTime format, some use PHP’s date format, some use Java’s date format and some even use RFC822 or RFC1123 date formats. There are so many different date formats people are using nowadays that you cannot find any code that can parse them all. After much struggle, I have finally come down to this function which tries to digest several possible date formats:

A variety of widely accepted formats make developers’ lives difficult because they have to support all of the widely used specifications in their application. A feed aggregator needs to support RSS, Atom and RDF all together because all of these are widely used. This results in design complexity because you need to make your object model and parsing process generic for parsing and storing feeds of three different formats.

After much searching, I have finally realized that everyone produces different object models for RSS and Atom feeds. However, having different object model means you need to create different table structures in the database which is difficult to maintain. You also need to write code in all places which first checks whether it is dealing with Atom or RSS feed. This makes your application complicated. Such a problem is solved by XML. In XML, you can store different types of data, yet fully structured. Using XSL, you can easily render different XML structures the same way. So, it does not matter whether you have Atom or RSS content inside your XML, an XSL can easily check the type and produce same HTML output for viewing.

First let’s see the generic feed parser that I have made. The FeedProcessor.cs is the generic feed parser which can parse RSS/Atom/RDF the same way and produce Channel and RSSFeed objects in one generic format.

While parsing, first it sees whether the XML contains RSS or Atom or RDF:

The complex part is parsing the entry or item node which actually contains the XML content. We need to parse it in two ways:

We need to discover some essential properties like publish date, title and GUID according to what we are parsing (Arom/RSS).

We need to store the everything we are reading in a buffer because XmlReader is a one way reader and we cannot go back once we have forwarded.

So, we not only need to use an XmlReader to read, but also an XmlWriter to write the same thing as we read in a temporary buffer.

The next design complexity is writing a generic function which parses the entry and item node in the same way. Although we can make two different functions for parsing entry and item nodes, the functions will have 90% code duplicated; the only differences are the name of some nodes and some structural differences. So, here is the function which parses it all:

You will see in the above code that I have used a custom function called ReadString instead of using XmlReader’s ReadString method. The documentation says ReadString method is supposed to read the content of the string. It is not supposed to jump off the end tag. But in practice, it does go over the end tag and stops at the next begin tag. So, if you are reading the <title> node, and call ReadString, the next node you will get is the <pubDate> node, not the </title>. But we need to know when a tag is closed so that we can close the tag in the XmlWriter also. This is why I have made the custom ReadString method:

The best way to make this application simple and think only about RSS is to convert Atom XML to RSS XML just after downloading the content from web source. This way, the whole application can deal with the RSS feed and need not worry about all other formats. So, in future, if another format gets popular, all I need to do is write another converter which converts that format to RSS format. The application receives no significant changes.

In the source code, you will find atomtorss2.xslt which converts Atom 0.3 XML to RSS 2.0 XML. Here is a little excerpt of the XSLT which does the conversion:

EXSLT is taking XSLT processing to the next level. It supports a rich collection of functions that you can use in XSLT scripts which makes XSL a truly powerful script for real world XML transformation. The beauty of XsltTransformer is that, it allows you to write pure .NET functions which are invoked whenever they are called from XSLT script. Using this feature, you can make complicated XML transformation which fully utilizes the full power of .NET platform. You can even write functions that can call a database and get dynamic values and put that value in the resulting XML.

Using EXSLT is very easy. The following code shows how an Atom 0.3 XML is converted to RSS 2.0 XML:

Although we all know it, I always forget to do the right thing to serialize ArrayList which contains custom objects. So, I have made a convenient SerializationHelper class which exposes variants of Serialize or Deserialize functions which you can use in your applications:

If you have a property of type ArrayList, the serialized XML looks very ugly and does not look like what we call – strongly typed if that applies to XML. In order to customize how an ArrayList is serialized, you can try the two attributes XmlArray and XmlArrayItem:

The easiest way to carry additional files with your projects is not to carry them as external files, instead putting them inside an assembly. Visual Studio has a nice property named Build Action for this purpose:

If you set the property to Embedded Resource, that file is linked inside the assembly. This means that the entire content of the file is embedded inside the assembly as inline resource. As a result, you can make one assembly which contains all the files you need. You can directly read the files from the assembly as a Stream without opening as a file. Each file is embedded inside the assembly by the following naming convention:

NameSpace.FileName.Extention

So, for the file atomtorss2.xslt, the full name of the embedded resource is:

RSSFeederResources.atomtorss2.xslt

The best thing about embedded resources is that they are not in the file system as separate physical files. So, you never need to worry about the path of the files. You can directly read the content of the file as a Stream. However, the embedded resource is read-only. If you want to modify the content, then there is no way known to me so far to do that. In that, case you will have to create a file from embedded resource and use that file always.

The SerializationHelper has some convenient functions to deal with embedded assemblies. For example:

You get an Icon object directly from an embedded icon file. This is very convenient for carrying all the icons that your application uses. You don’t need to maintain separate icon files and worry about their path.

The best place to store application specific data is not in the folder where your program is installed but in the “Application Data” folder that Windows® creates for each user. There are actually two Application Data folders. One is directly under the user folder and another is inside the hidden folder "Local Settings". So, if you user name is Omar AL Zabir, the path to these folders will be:

The major difference between them is that the first one is visible. You can browse to that folder using Explorer. But the second one is hidden by default. You need to turn on “Show Hidden Files” from Explorer Options in order to see that folder.

Another difference is that, when you have a roaming profile in Windows®, the first visible folder is synchronized to the network store. So, whatever you store in that folder, you can easily access it when you login from another computer inside the domain. This location is better for storing files than the location where your application .exe is located because that does not roam. Remember, the second folder is computer specific and it is not synchronized when you move from one computer to another.

RSS Feeder stores all the data in the second folder.

You can get the path to these special folders using the Environment.GetFolderPath function. It takes an enumeration as shown in the following code snippet:

OPML is an XML-based format that allows exchange of outline-structured information between applications running on different operating systems and environments. OPML is used to store information about RSS Feed sources. For example, a blog site uses OPML to store all the blog titles and feed locations that it contains. If you go to blogs.msdn.com you will get the OPML for all the Microsoft bloggers’ feed URL and title.

RSS aggregators use OPML to exchange subscription information among other aggregators. For example, you can export all your subscriptions as OPML from Newsgator and then import the OPML to my RSS Feeder. In fact you don’t need to do it at all. Whenever you run it, it will import the Newsgator settings. Beware, Newsgator's XML contains "xmlurl" but all other OPML use "xmlUrl". The difference is in the case of "U".

Newsgator stores its subscription information in an OPML. Its OPML is a bit different:

It uses additional properties like ng:folderName and ng:folderType to describe Outlook Folder location where subscriptions are mapped. RSS Feeder provides Newsgator import feature. It uses this information to map to the same folder as Newsgator does.

The OpmlHelper class in the source code provides OPML parsing and generation functionality.

As RSS Feeder uses an MS Access database, it does not have much problem with multiple clients connecting to database or extra design issues that we need to consider while using SQL Server. However, we do need to optimize connection open and close as MS Access takes pretty long time to open and close connections.

So, what I have done here is open a static connection when the app starts and use that connection throughout the application. When the application closes, it closes the open connection. This gives significant performance boost than opening and closing connection whenever we access the database.

However, static connection object leads to multithreading issues. Sometimes two threads can try to execute commands on the same connection at the same time. For example, imagine Feed Downloader is downloading feeds in the background and you are reading the feeds. Now both you and the feed downloader are trying to read/write feeds from the database at the same time. At least one will fail as the connection will be in Executing state instead of Open state. In order to prevent this, I have implemented a Thread.Sleep whenever I see the connection is in Executing state.

So, when a thread tries to get hold of a connection object while the connection is executing, the thread goes into a 50 ms sleep. This is pretty much enough time to let the execution complete.

In a normal single processor computer, you will rarely face this problem. But if you have a P4 Hyper Threading Processor which simulates two processors, or your own HP6000 with six Xeon Processors in your house, then you will see this problem frequently.

This is the most complicated part. The first problem you will face while automating Outlook is releasing all the object references used in your code. If you do not release the references properly, Outlook will never close even if it disappears from the screen. The second problem is making a version independent solution. If you “Add Reference...” to Outlook COM library from Visual Studio and set reference to a specific version of DLL, the interop assembly that is generated becomes a version specific assembly. As a result, it will not work properly with older versions of Outlook. The only way you can make it version independent is to develop against the oldest version of Outlook you want to support and make builds from that version.

Another solution to make a truly version independent Outlook automation is to use Late Binding. You can use the Activator class in .NET framework to instantiate any COM object using ProgID. So, you can launch Outlook using late binding in the following way:

Although this makes coding a nightmare, but you can make helper functions to deal with the objects and properties. The OutlookHelper class provided with the source code gives you many helper functions to automate Outlook. However, you still have to memorize the object model of the Outlook first before writing code using Late Bound approach. In order to have a safe late bound approach to COM interop and a version independent yet strongly typed Outlook Automation Library, check my article SafeCOMWrapper. If you use this, you don’t have to write the cumbersome code and you don’t need to remember the object model.

Here’s a late bound way to show Folder Picker dialog box from the Outlook:

Whenever the application downloads RSS feeds, it also sends them to a mapped Outlook folder. First it transforms XML of an entry to HTML using XSLT transformation described in this article. Then it uses a UserProperty to store the actual XML against the post. This way, you can write macros later on to work on the XML of the original entries.

RSS Feeder provides blogging directly from Outlook. First you create a “Mail and Post” type folder. Then you create Posts in that folder. You can also drag posts from other folders to this folder. RSS Feeder picks up the posts available in the folder and then publishes it to the weblog site.

The following code shows how this is done the hard way which is the late bound way:

Although there is nothing special in this area, but I can show you some handy tips. For example, I have made a handy function which downloads content from a URL and gives progress update as the download continues. As a result, you can make a progress dialog box which can show the downloaded content size and the connection speed while the download continues.

This is the standard way to make Events. I have seen people making custom delegates and taking all the required information as parameters. That’s not the prescribed way. The suggested way is to make delegates similar to EventHandler delegate and make your own class extend the EventArgs which contains all the event parameters. This makes the design consistent and other developers can pick up the concept easily as it is something closer to what they already use.

One of the common mistakes we all do is that we try to update the UI from background threads or self created threads than using the main UI thread and thus make our apps crash frequently. While designing multithreaded applications, you need to ensure that you are in no way using any resource on the UI from any other thread other than the main thread. Normally the common mistake we all make is, we breakup the code of another thread in different functions and on those functions we forget about the fact that it is running in another thread. As a result, the app crashes frequently whenever we try to access the UI elements.

In order to update UI from a function called from or running in another thread, you need to use the Invoke or BeginInvoke method of the Control or Form. Here is my favorite way to do this:

The function which accesses UI element checks itself whether it requires invoke. If it requires invoke, it calls itself using a delegate via the Invoke method. If it does not require invoke, it executes the code which handles the UI elements. Thus it guarantees to prevent the problem of accessing UI elements from another thread. It also saves code because you need not Invoke it explicitly from all the places.

An interesting feature of RSS Aggregators is to detect the presence of RSS feed or RSS Feed location from any URL. There are different scenarios you have to consider while implementing auto discovery:

The URL can itself be an RSS Feed, not an HTML.

The URL can be a HTML page having <link rel="alternate" type="application/rss+xml" …> which refers to a RSS source.

The HTML page may contain hyperlinks to RSS Feed sources.

RSS Feeder can intelligently identify what a URL contains and take actions accordingly. For example if you provide the URL of an HTML page, it will find all the RSS feed sources specified inside the HTML. So, if you provide the URL msdn.microsoft.com it will automatically detect all the RSS Channels specified in that page.

On the other hand, if you give it a URL containing some type of feed, it will automatically detect the type of feed.

The HTML processing is done by the famous SgmlReader. Here’s is the code which discovers the type of content that is found after downloading data from a URL:

The code reads the node one by one until it discovers either html, rss, rdf or feed node. If it reaches the html node, it assumes that this is an HTML document and looks for the link node which specifies the reference to RSS or Atom feed source. If it finds such sources, it makes a collection of those sources and returns the collection.

Believe it or not, you cannot transform an XML to HTML properly using XSL if it contains embedded HTML content inside the XML nodes. .NET framework’s built in XSL transformer cannot decode the HTML content inside the nodes. Although the XSL specification says you can do this:

<xsl:value-ofdisable-output-escaping="yes"select="description"/>

This is used to prevent XSL transformer from escaping the content of the description node and to render as it is, but it does not work. The XSL transformer is going to encode the HTML content no matter what happens. As a result, instead of getting a nicely formatted HTML output, you see the HTML codes.

Due to this problem, I created the HtmlReader and HtmlWriter classes. Details about this can be found in my HTML Cleaner article.

This is trickier than rendering a single post as you have to render multiple channels in one HTML. The process is as follows:

Combine all the channels into one XML which contains one RSS node but multiple channel nodes.

Transform the combined XML using XSLT in order to render HTML.

The first problem I encountered was combining multiple XML using XmlWriter. XmlWriter’s WriteRaw method is supposed to write everything I give it without doing any encoding. But it does not do that, instead it encodes any XML given as a node’s value. As a result, I cannot write XML of an RSS entry using XmlWriter. In order to do this, I need to first create a StreamWriter and then wrap that using XmlTextWriter. Regular XML construction is done by the XmlTextWriter, but whenever raw XML needs to be written, I call the StreamWriter’s WriteLine method.

This is a common requirement for many desktop applications where you need only one instance of your app to be allowed to run.

Doing this requires a bit of Win32 level knowledge. When an app is created, it registers a Mutex. But before creating it first checks whether there is any Mutex already registered with the same name. If there is, then another instance of application is already running and so we quit.

Suppose you have a list of items. Every time a user selects an item, you need to perform some database operation and generate HTML which takes time. You have written this code in the SelectedIndexChanged event of the list. So if the user selects an item by clicking it and then holds down the DOWN arrow for a while, the event is going to be fired repeatedly which results in frequent database calls and HTML rendering. As those operations take time, the selection pointer does not smoothly go down, instead it gets stuck on every item for a while making the whole UI unresponsive until all the method executions are finished.

Another scenario is, if the user first clicks an item and then scrolls down using a mouse and holds SHIFT and clicks another item to make multiple selections, the SelectedIndexChanged event of the list is going to be fired for each and every item that falls within the selection range. As a result, the user is going to be stuck for a while until all the events are fired and the code execution for all the events is finished.

In order to solve these problems, we will use a timer to invoke the method which does the actual work instead of calling it directly. The process is as follows:

On SelectedIndexChanged event of the list, we first stop the timer in order to initialize its state. Then we start the timer with an interval.

We set a delegate to the method which needs to be called.

On the Elapsed event, we call the delegate, stop the timer and clear the delegate.

As a result, no matter how many times the SelectedIndexChanged event of the list is fired, it just sets a timer which in turn queues a method invoke. As we use a delegate to point to a method instead of an event, the delegate is called only once which in turn calls the actual method just once.

.NET Winforms applications are memory hog apps. An innocent one button, one form application takes about 15 to 20 MB memory when it loads, whereas a VB 6 counter part takes just 15 to 20 KB.

However, if you open Task Manager while RSS Feeder is in the tray and no window is visible, you will notice that it takes only around 3 to 5 MB memory.

This is done by reducing the WorkingSet of the Process of the app. WorkingSet is a property of the Process class which contains how much memory the process is consuming. The interesting thing is that, it is not a read-only variable; you can increase or decrease it. If you try to decrease it, you will notice the memory usage goes down significantly. Although it does not work always, we can give it a try whenever we want it.

We all know how to do it, add a key in the registry and that’s all. But putting an application at startup, specially a .NET application at startup is a serious pain for Windows. Normally if you try to load a Winforms application for the first time, you will see how slow it is and how much hard disk activity it consumes. Putting such applications at startup when Windows is doing a lot of other tasks is going to make the boot-up much slower and make the user lose his patience.

That’s why, I have made an application loader in VB 6 which takes only 20 KB and loads in the blink of an eye. When the RSS Feeder is set to load at startup by the user, it actually puts the loader at startup with a 5 minutes delay. The loader immediately goes to sleep for 5 minutes after loading, allowing Windows to breathe freely for a while and wipe out sweats after heavy boot-up pushups. When everything is nice and quiet, it starts the jumbo .NET app.

As the RSS Feeder runs all over the world without letting me know anything about it, I need a way to know whether my users are happily using it or not. So, I have implemented a silent crash report module which traps any unhandled exceptions and reports back to me via Source Forge tracking system.

Error reporting works in the following way:

Whenever an unhandled exception occurs, the error report is queued to an Error Queue.

The queue is frequently monitored by an Error Reporting Engine. Whenever it picks up an error from the queue, it launches a background thread.

The background thread prepares an error report collecting some context information like the current login name of the user which helps to identify duplicate reports from the same user.

The message is posted as HTTP POST to Source Forge Tracker System.

The error reporting engine uses a timer to periodically check the queue.

In order to make a successful HTTP dialog, we do need to get the response a bit, but not the whole response. Source forge’s pages are pretty heavy. Do not think of downloading a full page. Besides the page that is returned contains all the posted items and there may be thousands of error reports!

There is a very convenient way to catch any exception that someone mistakenly skipped putting inside the try catch block. The Application class provides an event ThreadException which traps any unhandled exception that was not caught by any catch block. When you forget to catch any exception, you see the shameful “Continue” or “Quit” dialog box with detailed exception trace exposing all your mistakes. If you catch the ThreadException you can capture any leaked exception, and can remain quiet or silently write to a log file in order to pick it up later on.

EntLibHelper consults the configuration file to decide what to do with the unhandled exception. You can specify in the configuration file what to do with exceptions in the unhandled exception category. If you specify to throw it again, it shuts down the application. But if you specify to trap it, it sends the exception to the Error Reporting engine for sending it to a tracking system. As a result, you will see the error reporting window pops up which notifies me about the error. This is a zero hassle for both you and me.

RSS Feeder is not only an RSS aggregator but also an equally powerful blogging tool. It gives you a nice Outlook 2003 style UI to work with multiple weblogs.

You can create one or more weblog accounts, write posts and save for publishing it later on. When you send a post for publishing, it goes to a send queue which is collected by the send/receive module. If there is any problem in posting, you can come back and open the post to see the error report.

Most of the widely used blog engines use XML RPC specially those which are developed using PHP. Some of them are WordPress, B2Evolution, Drupal etc. XML RPC is similar to SOAP where a method call and parameters are serialized to an XML. You can learn more about XML RPC by Googling on XMLRPC and also from this site.

Most of the Blog engines support a well defined API called MetaWeblogAPI. This API uses XMLRPC to call a fixed set of web methods. Although the API is fixed, the method names differ from one blog engine to another. As a result, you cannot really write a generic code for MetaWeblogAPI that works on all blog engines which support this API. I believe there is an urgent need to standardize a universally accepted list of methods and parameters or in short a fixed interface for all blog engines. For example, if you are blogging to B2Evolution, you need to use the following methods:

b2.getCategories: Get the categories for a blog.

b2.newPost: Make a new post.

On the other hand, for WordPress which supports the same MetaWeblogAPI, the method names are:

metaWeblog.getCategories

metaWeblog.newPost

This makes life difficult to implement a blogging library that works universally for all. However, this has been done pretty well in RSS Feeder. Currently it supports almost all PHP based blog engines and famous .NET based blog engines like .Text and Community Server.

The editing environment has been made as rich as possible while maintaining the restrictions the blog engines apply to formatting. Not all HTML formatting are supported by blog engines. Most of them strip of style attribute and style sheets. Some don't allow the <font> tag. Some prevent <div> inside the <p> tag. So, the editor that I have made more or less accommodates sufficient formatting tools that suites all.

When you have a big toolbar containing 30 to 40 buttons, it becomes difficult to write code for handling click on each of these buttons. You end up either writing click handlers for each button or one toolbar level handler with a big if else or switch case to determine which button was clicked.

Instead of this, I have tried a convenient approach. Each button contains a method name in the tag of a button. For example, the Save button has a tag value set to $SavePost. The user control has a public method named SavePost. Inside the click handler of the toolbar, I have this code:

It uses reflection to find the method on the user control which matches the name specified in the tag and invokes the method. So, you don’t need to write the click handler or switch blocks to decide which button is clicked and for that which method needs to be called.

Moreover, if the Tag does not start with a $ sign, it means the method needs to be invoked on the DHTML editor control where the user writes the body of the post. The DHTML editor control exposes lots of formatting methods which are thus directly mapped to the toolbar buttons.

The editor you see is the DHTML editor control that comes with Internet Explorer. This is the control that Microsoft uses in most of their products including the HTML Designer Window of Visual Studio. You will find the control in this path:

C:\Program Files\Common Files\Microsoft Shared\Triedit\dhtmled.ocx

Working with this control is pretty difficult because almost all the functionality that it provides is via a method named ExecCommand. You can find a reference to this method at MSDN. This function lets you control the editor’s behavior, change formatting style, show common dialog boxes like Find, Link, Image etc. For example, you can use the following command to set the editor to Bold mode:

As working with this control requires you to memorize all the function names and parameters, a convenient wrapper is necessary. That’s what you have in the HtmlEditor control provided in the source code. It exposed almost all the functionalities of DHTML editor as convenient public methods and properties like SetBold, SelectedText, OrderList etc. As the wrapper is a .NET class which extends the DHTML editor control, you can easily create a new instance of it and put it inside a container. Here’s the code sample which shows you how to create a new editor and put it inside a Panel:

One important issue you need to notice is that, you can only work with this component when the handle is created, which means that IsHandleCreated property is true. If you want to work with this component on the Load event of a Control or Form then it will fail. The editor does not load properly when the Load event is fired. It for some reason takes a long time to get initialized properly. So, any task that you need to perform on the load needs to be performed on the HandleCreated event of the control. Also keep in mind to always check the IsHandleCreated property before using this control. For example:

You must be wondering how I made the UI. It’s developed using the marvelous free controls found at Divelements Ltd. I am a great fan of their tools and I have also used it in my other project Smart UML.

I have tried to make RSS Feeder an ideal Smart Client application by implementing all the best practices that I have been able to collect from the web. This application is a good example of the use of Enterprise Library in a real application. It also uses the Application Updater Block 2.0 which was a real pain to implement. Hope you will find this article a good source of essentials of desktop application development. Although it’s been only a month since this app was developed and released, I hope it’s pretty much stable and feature-rich to be a part of your daily life. I will look forward to get feedback from you which will guide me to improve this in future and make it the best tool for feed aggregation and blogging.

.Net is handled by the CLR, so trying to reduce the working set is just as easily done by calling GC.Collect. The point being that you aren't really "freeing memory", you are just forcing the GC to run which doing too often or when not necessary just is a burden on the system and application.

I would recommend disposing properly in the first place and trying to limit the libraries you use.

I was looking for an Feed Aggregator that I would use in my project to collect Feeds that will then be analyzed. I saw your RssFeeder as a very good match. But since it is a little old I was curious whether it will cater to all types of feeds (Rss,Atom,..) which are there now a days. let me tell you, my knowledge on RSS overall is less. Please let me now whether it will suffice my needs? Feeds can be for various sources.

Secondly, does it have any error logging mechanism. If so then where can I find it?Lastly, at what frequency does the tool pull data from the sources. Can that be controlled?

Hi Omar, I have installed ur RSSfeeder.Its workin fine. But when i tried to debug the source i got following exceptions D:\Web App\Smart\RSSFeeder_Src\RSSFeeder\RSSFeeder\Newspaper.cs(283): The type 'AxSHDocVw.AxWebBrowser' has no event named 'NewWindow3'. D:\Web App\Smart\RSSFeeder_Src\RSSFeeder\RSSFeeder\Newspaper.cs(645): The type or namespace name 'DWebBrowserEvents2_NewWindow3Event' does not exist in the class or namespace 'AxSHDocVw' (are you missing an assembly reference?)

I tried compiling under VS2005, after using the convert wizard, which claimed it ran successfully. I got an error:

Error 1 Invalid Resx file. Could not load type RSSBlogAPI.Post, RSSBlogAPI, Version=3.0.2032.25206, Culture=neutral, PublicKeyToken=null which is used in the .RESX file. Ensure that the necessary references have been added to your project. Line 1279, position 4. C:\SRI\CALO\Projects\IPTO\RSS\RSSFeeder_src_3_3\RSSFeeder\RSSBlogAPI\WebLogManager.resx 1279 4 RSSBlogAPI

Have other people successfully compiled under VS2005? Other ideas why this might be a problem?

Error 1 Metadata file 'E:\hziee\myproject\RSSFeeder\RSSBlogAPI\bin\Debug\RSSBlogAPI.dll' could not be found RSSFeeder

Error 2 Invalid Resx file. Could not load type RSSBlogAPI.Post, RSSBlogAPI, Version=3.0.2032.25206, Culture=neutral, PublicKeyToken=null which is used in the .RESX file. Ensure that the necessary references have been added to your project. Line 1279, position 4. E:\hziee\myproject\RSSFeeder\RSSBlogAPI\WebLogManager.resx 1279 4 RSSBlogAPIthere is two errors;how can i fix it?

Error 1 An assembly with the same simple name 'AxInterop.SHDocVw, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null has already been imported. Try removing one of the references or sign them to enable side-by-side. e:\hziee\myproject\RSSFeeder\RSSBlogAPI\obj\Debug\AxInterop.SHDocVw.dll RSSBlogAPI

You'll need to delete the reference as mentioned before then add the MSHTML reference to the RSSBlogAPI. That can be found under the COM tab and "Microsoft HTML Object Library". Then build that assembly to see if it works. Build each one individually and not the whole solution at one time to help you isolate what references you may be missing.

Here is the trick though you who use VS2005 are looking for though; go to the VS command prompt. It is usually under programs->Visual Studio 2005 ->Visual Studio Tools. Then run the following (it may take a couple of seconds):

aximp %WINDIR%\system32\shdocvw.dll

This will build the SHDocVw.dll file and AxSHDocVw.dll assmblies you are missing. Add these to the RSSFeeder project. They will be in "Program Files\Visual Studio 8\VC\". It should all compile fine now.

First, thanks for posting this utility. It almost perfectly fits my need. Almost.

How can I get it to show the first n characters or lines of the content? Right now I see about 4 lines of content and I'd like to trim that down. Better yet, I'd like to see just the title, publish date/time and author.