Esempio n. 1
0
        public static FictionBook Deserialize(Stream stream)
        {
            FictionBook   fb2book    = null;
            XmlSerializer serializer = new XmlSerializer(typeof(FictionBook));

            using (XmlReader reader = XmlReader.Create(stream))
            {
                //StreamReader reader = new StreamReader(fs);
                fb2book = (FictionBook)serializer.Deserialize(reader);
            }
            return(fb2book);
        }
Esempio n. 2
0
        public static FictionBook ReadZipAsFB2(string zipPath)
        {
            FictionBook fb2book = null;

            using (ZipArchive archive = ZipFile.OpenRead(zipPath))
            {
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    if (entry.FullName.EndsWith(".fb2", StringComparison.OrdinalIgnoreCase))
                    {
                        fb2book = FictionBook.Deserialize(entry.Open());
                        break;
                        //entry.ExtractToFile(Path.Combine(extractPath, entry.FullName));
                    }
                }
            }
            return(fb2book);
        }
Esempio n. 3
0
        public static FictionBook Deserialize(string filename)
        {
            if (filename.EndsWith(".zip"))
            {
                return(FictionBookZipReader.ReadZipAsFB2(filename));
            }
            FictionBook   fb2book    = null;
            XmlSerializer serializer = new XmlSerializer(typeof(FictionBook));

            using (FileStream fs = new FileStream(filename, FileMode.Open))
            {
                using (XmlReader reader = XmlReader.Create(fs))
                {
                    //StreamReader reader = new StreamReader(fs);
                    fb2book = (FictionBook)serializer.Deserialize(reader);
                }
            }
            return(fb2book);
        }