/// <summary> /// 跳转到直接章节 /// </summary> /// <param name="page">章节数</param> private void Jump(int page) { try { //文章html string html = string.Empty; html = BLL.GetHtml.GetHttpWebRequest(book.ListUrl[NewId[page]]); newTitle.Text = NewId[page]; string str = BLL.Tool.GetRegexStr(html, bookSource.ContentRegular); newText.Document.Blocks.Clear(); Run run = new Run(BLL.Tool.HtmlFilter(str)); Paragraph p = new Paragraph(); p.Inlines.Add(run); newText.Document.Blocks.Add(p); ///重置翻页数 this.newText.ScrollToVerticalOffset(0); //保存已阅章节数 if (book.Id != 0) { DataFetch.UpdateUpdateReadingBook((int)book.Id, page); } NewPages = page; } catch { new Tips("打开错误,请检查书源是否存在问题?").Show(); } }
/// <summary> /// 跳转到直接章节 /// </summary> /// <param name="page">章节数</param> /// <param name="cache">是否缓存 如果是true,代表只是缓存,前台阅读页并不会因此而改变</param> private void Jump(int page, bool cache = false) { if (NewId.Count < page) { //这里是为了禁止读取不存在的章节 return; } try { //文章html string html = string.Empty; //章节的标题和文本 string Title = string.Empty; string Text = string.Empty; if (!cache) { buffer.Visibility = Visibility.Visible; } Thread thread = new Thread(new ThreadStart(delegate { Title = NewId[page]; //判断本章节是否缓存 if (NewText.ContainsKey(page)) { Text = NewText[page]; } else { html = GetHtml.GetHttpWebRequest(book.ListUrl[NewId[page]]); Text = Tool.GetRegexStr(html, bookSource.ContentRegular); NewText[page] = Text; } if (!cache) { Dispatcher.BeginInvoke((Action) delegate { newTitle.Text = Title; newText.Document.Blocks.Clear(); Run run = new Run(Tool.HtmlFilter(Text)); Paragraph p = new Paragraph(); p.Inlines.Add(run); newText.Document.Blocks.Add(p); ///重置翻页数 this.newText.ScrollToVerticalOffset(0); buffer.Visibility = Visibility.Hidden; //保存已阅章节数 if (book.Id != 0) { DataFetch.UpdateUpdateReadingBook((int)book.Id, page); } NewPages = page; //这里是缓存下面的章节 for (int i = 1; i < 10; i++) { Jump(page + i, true); } }); } })); thread.IsBackground = true; //是否为后台线程 thread.Start(); } catch (Exception ex) { new Tips("打开错误,请检查书源是否存在问题?").Show(); Tool.TextAdditional(ex.Message); buffer.Visibility = Visibility.Hidden; } }