Exemplo n.º 1
0
 // Enumerates over all items in the Project Gutenberg catalog. If you need the creation
 // date you must get it by calling the GetCreated method before this one. The returned
 // items can be either meta-data for books or files (book volumes). Books come first.
 public IEnumerable<object> GetItems(XmlReader reader)
 {
     Log.Verbose("Getting items...");
     while (reader.ReadToFollowingElement())
         switch (reader.LocalName) {
         case "etext":
             // The number is parsed within the ParseBook method. This copy is for logging
             // purposes only.
             var number = int.Parse(reader.GetAttribute("ID", RDF).Substring(5),
                                     CultureInfo.InvariantCulture);
             Book book;
             using (var subreader = reader.ReadSubtree())
                 try {
                     book = ParseBook(subreader);
                 } catch (Exception exception) {
                     throw new ApplicationException(string.Format(
                         "Parsing book {0} failed.", number), exception);
                 }
             yield return book;
             break;
         case "file":
             // The URL is parsed within the ParseVolume method. This copy is for logging
             // purposes only.
             var url = ParseVolumeUrl(reader);
             Volume volume;
             using (var subreader = reader.ReadSubtree())
                 try {
                     volume = ParseVolume(subreader);
                 } catch (Exception exception) {
                     throw new ApplicationException(string.Format(
                         "Parsing volume {0} failed.", url), exception);
                 }
             yield return volume;
             break;
         }
 }