IFeedFactory is an interface which defines all of the methods used by objects responsible for the creation of IFeed objects. Currently there are only two implementations of the IFeedFactory implementation: FileSystemFeedFactory and HttpFeedFactory.

IFeedFactory Members

The best possible documentation for this interface is the interface itself:

    public interface IFeedFactory
    {
        /// <summary>
        /// Pings the feed to verify that it actually exists.
        /// </summary>
        /// <param name="feeduri">The Uri of the feed to ping.</param>
        /// <returns>True if the feed was successfully pinged, false otherwise.</returns>
        bool PingFeed(Uri feeduri);

        /// <summary>
        /// Creates a new ISyndicationFeed class parsed from the provided Uri.
        /// </summary>
        /// <param name="feeduri">The Uri of the feed to be parsed.</param>
        /// <returns>A new ISynidcationFeed object. The exact type returned depends on the type of feed detected.</returns>
        IFeed CreateFeed(Uri feeduri);

        /// <summary>
        /// Creates a new ISyndicationFeed class of a specific type from the provided Uri. Method will throw an error
        /// if the type specified and the type actually detected in the document don't match.
        /// </summary>
        /// <param name="feeduri">The Uri of the syndication feed to parse.</param>
        /// <param name="feedtype">The type of syndication feed.</param>
        /// <returns>A new ISyndicationFeed object of type [feedtype].</returns>
        IFeed CreateFeed(Uri feeduri, FeedType feedtype);

        /// <summary>
        /// Creates a new ISyndicationFeed class of a specified type from the provided xml string. 
        /// The URI is used as a unique identifier for the feed.
        /// </summary>
        /// <param name="feeduri">The Uri of the syndication feed to parse.</param>
        /// <param name="feedtype">The type of feed.</param>
        /// <param name="feedxml">The xml content of the feed.</param>
        /// <returns>A new ISyndicationFeed object of [feedtype].</returns>
        IFeed CreateFeed(Uri feeduri, FeedType feedtype, string feedxml);

        /// <summary>
        /// Downloads the XML content of the feed and returns it as a string.
        /// </summary>
        /// <param name="feeduri">The Uri of the feed to parse.</param>
        /// <returns>A string containing the XML document in its entirety.</returns>
        string DownloadXml(Uri feeduri);

        /// <summary>
        /// Quickly parses the top-most XML to determine what type of syndication feed the feed hosted
        /// at [feeduri] is.
        /// </summary>
        /// <param name="feeduri">The Uri of the feed to parse.</param>
        /// <returns>The type of feed located at [feeduri].</returns>
        FeedType CheckFeedType(Uri feeduri);

        /// <summary>
        /// Quickly parses the top-most XML to determine what type of syndication feed [feedxml] is.
        /// </summary>
        /// <param name="feedxml">The Xml content of the feed to parse.</param>
        /// <returns>The type of feed contained in [feedxml].</returns>
        FeedType CheckFeedType(string feedxml);
    }

FeedTypes and IFeedFactory.CreateFeed(Uri feeduri)

FeedType is an enumerated type with the following values:
  • FeedType.Rss20
  • FeedType.Atom10
If you stick with calling just the IFeedFactory.CreateFeed(Uri feeduri) method you never actually need to deal with FeedType nor any of the other IFeedFactory methods which use it - IFeedFactory.CreateFeed(Uri feeduri) calls the CheckFeedType(string feedxml) method internally to determine the type of the feed and to return the appropriate IFeed object. I'd be so bold as to call this a "best practice" for 99% of cases.

FileSystemFeedFactory

The FileSystemFeedFactory class allows QDFeedParser applications to quickly parse RSS and Atom files stored on disk. Therefore it has the following prerequisites:
  1. All Uris passed to the FileSystemFeedFactory must contain valid locations of RSS/Atom on disk to which QDFeedParser has read access.
That's it. You can use PingFeed(Uri feeduri) to check to see if the file exists.

Usage

Here's a quick code sample which shows the FileSystemFeedFactory at work:

Uri feeduri = new Uri("C:\src\feeds\Aaronontheweb.xml");
IFeedFactory factory = new FileSystemFeedFactory();
IFeed feed = factory.CreateFeed(feeduri);

HttpFeedFactory

The HttpFeedFactory class allows QDFeedParser applications to.... you guessed it: parse RSS / Atom feeds accessed over HTTP. HttpFeedFactory will probably be what most Quick and Dirty Feed Parser users will be using. Here's the contract for working with HttpFeedFactory:
  1. You must provide a valid Uri for a valid RSS/Atom feed.
That's it. Again, you can use PingFeed(Uri feeduri) to check to see if the Uri is valid or not.

Last edited Jul 1, 2010 at 3:39 AM by Aaronontheweb, version 3

Comments

MAScodes Apr 21, 2013 at 3:23 PM 
Uri feeduri = new Uri("C:\src\feeds\Aaronontheweb.xml");

should probably read

Uri feeduri = new Uri(@"C:\src\feeds\Aaronontheweb.xml");