Esempio n. 1
0
 // Writes a single book volume to the output; it expects the writer returned by the
 // Create method. After writing all book volumes the method Finalize must be called.
 public void Write(BinaryWriter writer, Volume volume)
 {
     // The initial bool true will be recognized when deserializing the volumes. The
     // method Finalize writes false as the end marker.
     writer.Write(true);
     volume.Write(writer);
 }
Esempio n. 2
0
 // Parses a single book volume.
 Volume ParseVolume(XmlReader reader)
 {
     var volume = new Volume();
     var formats = new List<string>();
     while (reader.Read())
         if (reader.NodeType == XmlNodeType.Element)
             switch (reader.LocalName) {
             case "file":
                 volume.URL = ParseVolumeUrl(reader);
                 break;
             case "format":
                 if (!reader.ReadToDescendant("value", RDF))
                     throw new ApplicationException("Missing format value.");
                 formats.Add(reader.ReadElementContentAsString());
                 break;
             case "extent":
                 volume.Size = reader.ReadElementContentAsInt();
                 break;
             case "modified":
                 if (!reader.ReadToDescendant("value", RDF))
                     throw new ApplicationException("Missing modified date value.");
                 volume.Uploaded = reader.ReadElementContentAsDate();
                 break;
             case "isFormatOf":
                 volume.Number = int.Parse(reader.GetAttribute("resource", RDF).
                                             Substring(6), CultureInfo.InvariantCulture);
                 break;
             }
     volume.Formats = formats.Count > 0 ? formats.ToArray() : null;
     return volume;
 }
Esempio n. 3
0
 // Gets volumes for the specified book number.
 public bool TryGetVolumes(int number, out Volume[] volumes)
 {
     if (number >= 0 && number < VolumesByNumber.Length) {
         volumes = VolumesByNumber[number];
         return volumes != null;
     }
     volumes = null;
     return false;
 }