Example #1
0
 public static List<ChapterItem> GetChapters(BookItem item, WebRuleItem rule, HtmlExpand html)
 {
     var chapters = new List<ChapterItem>();
     var ms =
         html.Narrow(rule.CatalogBegin, rule.CatalogEnd)
             .Matches(@"<a[^<>]+?href=""?(?<href>[^""<>\s]+)[^<>]*>(?<title>[\s\S]+?)</a>");
     foreach (Match match in ms)
     {
         var url = match.Groups["href"].Value;
         chapters.Add(new ChapterItem(match.Groups["title"].Value, UrlHelper.GetAbsolute(item.Url, url),
             LocalHelper.GetSafeFile(url)));
     }
     return chapters;
 }
Example #2
0
        public static List <ChapterItem> GetChapters(BookItem item, WebRuleItem rule, HtmlExpand html)
        {
            var chapters = new List <ChapterItem>();
            var ms       =
                html.Narrow(rule.CatalogBegin, rule.CatalogEnd)
                .Matches(@"<a[^<>]+?href=""?(?<href>[^""<>\s]+)[^<>]*>(?<title>[\s\S]+?)</a>");

            foreach (Match match in ms)
            {
                var url = match.Groups["href"].Value;
                chapters.Add(new ChapterItem(match.Groups["title"].Value, UrlHelper.GetAbsolute(item.Url, url),
                                             LocalHelper.GetSafeFile(url)));
            }
            return(chapters);
        }
Example #3
0
 private void ExecuteUpdateCommand(int index)
 {
     if (index < 0 || index >= BooksList.Count || BooksList[index].Source == BookSources.本地) return;
     RingVisibility = Visibility.Visible;
     Task.Factory.StartNew(() =>
     {
         var item = BooksList[index];
         var conn = DatabaseHelper.Open();
         var rule = DatabaseHelper.GetRule(item.Url);
         var chapters = Helper.HttpHelper.GetChapters(item, rule, (HtmlExpand)new HtmlExpand().SetUrl(item.Url));
         var length = chapters.Count;
         if (item.Count < length)
         {
             var result = Parallel.For((long) item.Count, length, i =>
             {
                 var chapter = chapters[Convert.ToInt32(i)];
                 var html = new HtmlExpand();
                 html.SetUrl(chapter.Url);
                 LocalHelper.WriteTemp(
                     ((HtmlExpand)html.Narrow(rule.ChapterBegin, rule.ChapterEnd)).GetText(rule.Replace), chapter.Content);
             });
             while (!result.IsCompleted)
             {
                 Thread.Sleep(1000);
             }
             DbTransaction trans = conn.BeginTransaction();
             try
             {
                 for (var i = item.Count; i < length; i++)
                 {
                     var chapter = chapters[i];
                     DatabaseHelper.Insert<ChapterItem>(
                         "Name, Content, BookId, Url",
                         "@Name, @Content, @BookId, @Url",
                         new SQLiteParameter("@Name", chapter.Name),
                         new SQLiteParameter("@Content", LocalHelper.ReadTemp(chapter.Content)),
                         new SQLiteParameter("@BookId", item.Id),
                         new SQLiteParameter("@Url", chapter.Url));
                 }
                 trans.Commit();
             }
             catch (Exception)
             {
                 trans.Rollback();
             }
         }
         DatabaseHelper.Close();
         RingVisibility = Visibility.Collapsed;
     });
 }
Example #4
0
 private void ExecuteUpdateCommand()
 {
     if (_book.Source == BookSources.本地) return;
     RingVisibility = Visibility.Visible;
     Task.Factory.StartNew(() =>
     {
         DatabaseHelper.Open();
         var rule = DatabaseHelper.GetRule(_book.Url);
         var chapter = ChaptersList[_book.Index];
         var html = new HtmlExpand();
         html.SetUrl(chapter.Url);
         html.Narrow(rule.ChapterBegin, rule.ChapterEnd);
         var content = html.GetText(rule.Replace);
         DatabaseHelper.Update<ChapterItem>(
             "Content = @content",
             $"Id = {chapter.Id}",
             new SQLiteParameter("@content", content));
         DatabaseHelper.Close();
         Application.Current.Dispatcher.Invoke(() =>
         {
             _setConent(content);
         });
         RingVisibility = Visibility.Collapsed;
     });
 }