• Read an existing OPDS source.

    var feed = OpdsFeed.Load(new XmlTextReader("http://opds.9yue.com/category.atom"));

  • Validate an existing OPDS source.

    var validator = new OpdsValidateReader();
    validator.ValidationError += (sender, args) =>
    validator.Validate(new XmlTextReader("http://opds.9yue.com/detail/958.atom"));
  • Create OPDS syndication item from your existing data model

    You probably already defined a set of object in your domain language and probably don't wanna create another set of class just for generating OPDS. Assuming you have a Book class and going to create OPDS entries from books instances. The following code shows how to make it.

    public class Person
        public string Name { get; set; }
        public string Address { get; set; }
        public string Email { get; set; }
    public class Book
        public int Id { get; set; }
        public string Name { get; set; }
        [AdaptedName("AuthorName", PropertyPath = "Name")]
        [AdaptedName("AuthorEmail", PropertyPath = "Email")]
        [AdaptedName("AuthorAddress", PropertyPath = "Address")]
        public Person Author { get; set; }
        public decimal Price { get; set; }

    OPDS entry require an Id, a title and a few author information. But the Book class names that property differently. As you may already saw. The AdaptedName attributes are used to deal with the mapping.

    Then use the following code generate syndication items, i.e. the OPDS entry, from those books.

    // Initialize data.
    var data = new List<Book>() { new Book() { } };
    // Create converter
    var converter = new NamingDataOpdsItemConverter();
    // Convert data to opds items
    var items = converter.GetItems(new OpdsData(data));

    Job done.

Last edited Jul 11, 2012 at 3:45 AM by fadefy, version 1


No comments yet.