Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
 public static List<ChapterItem> GetBook(ref BookItem item, WebRuleItem rule)
 {
     var html = new HtmlExpand();
     html.SetUrl(item.Url);
     if (!string.IsNullOrWhiteSpace(rule.CoverBegin) || !string.IsNullOrWhiteSpace(rule.CoverEnd))
     {
         item.Image = html.GetCover(rule.CoverBegin, rule.CoverEnd);
     }
     if (!string.IsNullOrWhiteSpace(rule.AuthorBegin) || !string.IsNullOrWhiteSpace(rule.AuthorEnd))
     {
         item.Author = html.GetAuthor(rule.AuthorBegin, rule.AuthorEnd);
     }
     if (!string.IsNullOrWhiteSpace(rule.DescriptionBegin) || !string.IsNullOrWhiteSpace(rule.DescriptionEnd))
     {
         item.Description = html.GetDescription(rule.DescriptionBegin, rule.DescriptionEnd);
     }
     var chapters = GetChapters(item, rule, html);
     item.Count = chapters.Count;
     return chapters;
 }
Ejemplo n.º 3
0
        public static List <ChapterItem> GetBook(ref BookItem item, WebRuleItem rule)
        {
            var html = new HtmlExpand();

            html.SetUrl(item.Url);
            if (!string.IsNullOrWhiteSpace(rule.CoverBegin) || !string.IsNullOrWhiteSpace(rule.CoverEnd))
            {
                item.Image = html.GetCover(rule.CoverBegin, rule.CoverEnd);
            }
            if (!string.IsNullOrWhiteSpace(rule.AuthorBegin) || !string.IsNullOrWhiteSpace(rule.AuthorEnd))
            {
                item.Author = html.GetAuthor(rule.AuthorBegin, rule.AuthorEnd);
            }
            if (!string.IsNullOrWhiteSpace(rule.DescriptionBegin) || !string.IsNullOrWhiteSpace(rule.DescriptionEnd))
            {
                item.Description = html.GetDescription(rule.DescriptionBegin, rule.DescriptionEnd);
            }
            var chapters = GetChapters(item, rule, html);

            item.Count = chapters.Count;
            return(chapters);
        }
Ejemplo n.º 4
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;
     });
 }
Ejemplo n.º 5
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;
     });
 }
Ejemplo n.º 6
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);
        }