Example #1
0
        public EpubContentReader(string file, SettingsBase settings, IDirectoryHelper directory)
        {
            var bookZip = ZipFile.Open(file, ZipArchiveMode.Update);
            var tempFile = Path.Combine(settings.TempDirectory, Path.GetFileNameWithoutExtension(file));
            bookZip.ExtractToDirectory(tempFile);
            bookZip.Dispose();
            var contentInfoFile = directory.GetFiles(tempFile, "*.opf", SearchOption.AllDirectories).FirstOrDefault(f => f.EndsWith(".opf"));

            var doc = XDocument.Load(contentInfoFile);
            var elements = doc.Root.Elements();
            var metadata = elements.Where(e => e.Name.LocalName == "metadata").FirstOrDefault();
            var metaDataElements = metadata.Elements();
            this.title = metaDataElements.Where(e => e.Name.LocalName == "title").FirstOrDefault().Value;
            this.creator = metaDataElements.Where(e => e.Name.LocalName == "creator").FirstOrDefault().Value;
            var coverInfoElement = metaDataElements.Where(e => e.Attributes("name").Where(a => a.Value == "cover").FirstOrDefault() != null).FirstOrDefault();
            coverLocation = "";
            if (coverInfoElement != null)
            {
                var coverValue = coverInfoElement.Attributes("content").FirstOrDefault().Value;
                var manifest = elements.Where(e => e.Name.LocalName == "manifest").FirstOrDefault();
                var manifestElements = manifest.Elements();
                var coverManifest = manifestElements.Where(e => e.Attributes("id").FirstOrDefault() != null && e.Attributes("id").FirstOrDefault().Value == coverValue).FirstOrDefault();
                var coverHref = coverManifest.Attributes("href").FirstOrDefault().Value;
                var fullCoverLocation = Path.Combine(Path.GetDirectoryName(contentInfoFile), coverHref.Replace("/", "\\"));
                coverLocation = fullCoverLocation;
            }
        }
Example #2
0
 public LibraryLoader(IDataContext<Book> db, SettingsBase settings)
 {
     this.db = db;
     this.directory = new DirectoryHelper();
     this.settings = settings;
 }
Example #3
0
 public LibraryLoader(IDataContext <Book> db, SettingsBase settings)
 {
     this.db        = db;
     this.directory = new DirectoryHelper();
     this.settings  = settings;
 }