/// <summary> /// Save the image locally and then add to the epub manifest /// </summary> /// <param name="epub">The epub to add the image to</param> /// <param name="url">The address the image is located at</param> /// <param name="imgName"></param> /// <returns></returns> public string SaveImage(Epub epub, string url, string imgName) { WebClient webClient = new WebClient(); try { if (!File.Exists(epub.location + EpubStructure.EPUBLOCATION + EpubStructure.CONTENTLOCATION + EpubStructure.IMAGELOCATION + imgName)) { EpubParser.Retry(1, TimeSpan.FromSeconds(60), () => { webClient.DownloadFile(url, epub.location + EpubStructure.EPUBLOCATION + EpubStructure.CONTENTLOCATION + EpubStructure.IMAGELOCATION + imgName); }); } epub.AddToManifest(imgName, EpubStructure.IMAGELOCATION + imgName); } catch (Exception ex) { Logger.LogError("Failed to download: " + url + " - " + imgName); Logger.LogError(ex.Message); } finally { webClient.Dispose(); } return((EpubStructure.IMAGELOCATION + imgName).Replace("\\", "/")); }
/// <summary> /// /// </summary> /// <param name="url"></param> /// <param name="epub"></param> /// <returns></returns> public string Parse(string url, Epub epub) { this.epub = epub; HtmlWeb web = new HtmlWeb(); HtmlDocument doc = web.Load(url); string bodyText = ""; HtmlNode nodes = doc.DocumentNode.SelectNodes(RootNode)[0]; foreach (HtmlNode node in nodes.ChildNodes) { if (IgnoreNode(node)) { } else if (DecklistNode(node)) { bodyText += DecklistParser(node); } else if (ImageNode(node)) { bodyText += ImageParser(node); } else if (ParagraphNode(node)) { bodyText += ParagraphParser(node); } else if (HrNode(node)) { bodyText += HrParser(node); } else if (ListNode(node)) { bodyText += ListParser(node); } else if (ScriptNode(node)) { bodyText += ScriptParser(node); } else { bodyText += DefaultParser(node); } } return(bodyText); }
/// <summary> /// Constructor: Setup the epub /// </summary> public EpubSaver(Epub epub) { this.epub = epub; }