public ViewTest() { InitializeComponent(); var task = new BookIndexViewModel.DownloadTask(); chapter = new Chapter(); chapter.ChapterName = "人类已经不能阻挡我了"; chapter.ChapterUri = new Uri("http://www.83k.com/Html/Book/12/12342/4020652.shtml", UriKind.Absolute); task.TaskChapter = chapter; //DownloadChapter(task); }
public void PrepareTempDB() { using (var db1 = new SmartReaderDataContext("isostore:/SmartReader.sdf")) { if (db1.DatabaseExists() == false) { db1.CreateDatabase(); } } Storage = PhoneStorage.GetPhoneStorageInstance(); TestWebSite = GetFakeWebSite(); TestBook = GetFakeBook(TestWebSite); TestTextChapter = GetFakeTextChapter(TestBook); TestImageChapter = GetFakeImageChapter(TestBook); TestBook.Chapters = new[]{ TestTextChapter, TestImageChapter}; Storage.SaveWebSite(TestWebSite); Storage.SaveBook(TestBook); Storage.SaveChapters(TestBook.Chapters); //CreateFakeArticleImage(chapter); }
/// <summary> /// Download single chapter, should be active from the ChapterView Page /// </summary> /// <param name="chapter"></param> /// <param name="callback"></param> public void DownloadSingleChapter(Chapter chapter, Action callback) { var downloader = new HttpContentDownloader(); downloader.Download(chapter.ChapterUri, ar => { try { //At this step, we can get the index page in the search engine var state = (RequestState)ar.AsyncState; state.stopTimer = true; var response = (HttpWebResponse)state.Request.EndGetResponse(ar); response.GetResponseStream(); var parser = new WebSiteBookContentPageParser(); parser.ParsingCompleted += ChapterContentParsingCompleted; chapter.Downloaded = true; parser.Parse(response.GetResponseStream(), chapter); if (callback != null) { callback(); } } catch (WebException e) { //TODO need to recover from exception ExceptionHandler.HandleException(e); } }); }
public void PreviousChapter() { if (CurrentChapterIndex - 1 > 0) { CurrentChapterIndex--; CurrentChapter = CurrentBook.Chapters[CurrentChapterIndex]; } }
public void NextChapter() { if (CurrentChapterIndex + 1 < CurrentBook.Chapters.Length) { CurrentChapterIndex++; CurrentChapter = CurrentBook.Chapters[CurrentChapterIndex]; } }
private void ParseIndexContent ( HtmlNode node ) { //<a href="3939265.html" title="第一章 大梦初醒 更新时间:2010-03-22 00:17">第一章 大梦初醒</a> var chapter = new Chapter { LastUpdateTime = DateTime.Now}; chapter.ChapterName = node.InnerText; if (node.Attributes["href"].Value.ToLower().Contains("http")) { chapter.ChapterUri = new Uri(node.Attributes["href"].Value, UriKind.Absolute); } else { var baseUri = new Uri(book.RootUrl); chapter.ChapterUri = new Uri(baseUri , node.Attributes["href"].Value); //Take care of the double "//" problem } chapter.Book = book; chapterList.Add(chapter); }
private ArticleImage CreateFakeArticleImage(Chapter chapter) { var image = new ArticleImage(); // image.Chapter = chapter; var bitMapImage = new BitmapImage(); GifDecoder gd = new GifDecoder(); var img = new ImageTools.ExtendedImage(); gd.Decode(img, Application.GetResourceStream( new Uri("/SmartReader.Library;component/Resource/8004887.gif", UriKind.Relative) ).Stream); var png = new PngEncoder(); BitmapImage bitmap = new BitmapImage(); bitmap.CreateOptions = BitmapCreateOptions.None; using (MemoryStream stream = new MemoryStream()) { png.Encode(img, stream); bitmap.SetSource(stream); } image.ImageBytes = ConvertToBytes(bitmap); Storage.SaveArticleImages(new[] { image }); return image; }
private Chapter CreateFakeChapter(Book book) { var chapter = new Chapter(); chapter.Book = book; chapter.SaveContent1 = "String Content"; chapter.ChapterUri = new Uri("http://www.tszw.net/files/article/html/79/79194/2417331.html", UriKind.Absolute); chapter.ChapterName = "敌手的面目"; chapter.LastUpdateTime = DateTime.Now; chapter.IsImageContent = true; //db.Chapters.InsertOnSubmit(chapter); Storage.SaveChapters(new Chapter[] { chapter }); return chapter; }
public void SaveChapter(Chapter chapter) { _db.Chapters.Attach(chapter); _db.SubmitChanges(); }
public IEnumerable<ArticleImage> GetArticleImageByChapter(Chapter currentChapter) { var result = from articleImage in _db.ArticleImages where articleImage.ChapterId == currentChapter.Id orderby articleImage.SequenceId select articleImage ; return result; }
//As for state we need to parse book metadata to here public object Parse(Stream inputStream, object state) { Metadata = state as Chapter; Book book = null; bool getIndexPage = false; if (Metadata == null ) { book = state as Book; getIndexPage = true; } var content1 = EncodingHelper.FromGBKToUnicode(inputStream); inputStream.Close(); var doc = new HtmlDocument(); doc.LoadHtml(content1); var body = hh.GetSingleChildByTypeChain(doc.DocumentNode, new[] {"html", "body"}); if (body == null) body = doc.DocumentNode; if (getIndexPage && book != null ) { //GetIndexPageLink(body, book); GetIndexPageLinkNew(body,book); return null; } CleanHtmlTree(body); var contentNode = GetContentNode(body); if (IsContentImage(contentNode)) { Metadata.IsImageContent = true; var imageNodes = new List<HtmlNode>(); hh.GetAllImageElementWithFilter(contentNode, imageNodes); GetImageContents(imageNodes); } else { var textNodes = new List<HtmlNode>(); hh.GetAllTextElement(contentNode, textNodes); if (Metadata != null) { var content = NormalizeContentNode(textNodes); if (content.Length > 4000) { Metadata.SaveContent1 = content.Substring(0, 4000); Metadata.SaveContent2 = content.Substring(4000, content.Length - 4000); } else { Metadata.SaveContent1 = content; } } } Deployment.Current.Dispatcher.BeginInvoke(() => { Metadata.Downloaded = true; } ); return Metadata; }