Ejemplo n.º 1
0
 public void AddEntityToList(BookEntity entity)
 {
     Task.Run(async() =>
     {
         if (ShelfBookList.ToList().Find(p => p.BookID == entity.BookID) == null)
         {
             string html = await(new HttpHelper()).WebRequestGet(string.Format(ViewModelInstance.Instance.UrlService.GetAddToShelfPage(), entity.BookID));
             if (html.Contains("{\"success\":true}"))
             {
                 DispatcherHelper.CheckBeginInvokeOnUI(() =>
                 {
                     var temp = entity.Clone();
                     temp.LastReadChapterName = temp.NewestChapterName;
                     temp.UnReadCountData     = null;
                     var result = DBBookShelf.InsertOrUpdateBook(AppDataPath.GetBookShelfDBPath(), temp);
                     ShelfBookList.Insert(0, temp);
                     RefreshList();
                 });
             }
             else
             {
                 ToastHeplper.ShowMessage(entity.BookName + " 添加至个人书架失败");
             }
         }
         else
         {
             DispatcherHelper.CheckBeginInvokeOnUI(() =>
             {
                 var temp = ShelfBookList.ToList().Find(p => p.BookID == entity.BookID);
                 var sim  = LevenshteinDistancePercent(temp.LastReadChapterName, entity.NewestChapterName);
                 if (!sim)
                 {
                     temp.LastReadChapterName = temp.NewestChapterName;
                     temp.UnReadCountData     = null;
                     var result = DBBookShelf.InsertOrUpdateBook(AppDataPath.GetBookShelfDBPath(), temp);
                 }
             });
         }
     });
 }
Ejemplo n.º 2
0
        public void SetBookList(string html)
        {
            if (!string.IsNullOrEmpty(html))
            {
                var list = AnalysisSoduService.GetBookShelftListFromHtml(html);
                if (list == null)
                {
                    this.IsShow = true;
                }
                else
                {
                    this.ShelfBookList?.Clear();
                    this.IsShow = false;

                    if (list.Count > 0)
                    {
                        var temp = list.OrderByDescending(p => DateTime.Parse(p.UpdateTime)).ToList();
                        foreach (var item in temp)
                        {
                            var entity = DBBookShelf.GetBook(AppDataPath.GetBookShelfDBPath(), item);
                            if (!string.IsNullOrEmpty(entity?.LastReadChapterName))
                            {
                                item.LastReadChapterName = entity.LastReadChapterName;
                                var sim = LevenshteinDistancePercent(item.LastReadChapterName, item.NewestChapterName);
                                if (sim)
                                {
                                    item.UnReadCountData = "";
                                }
                                else
                                {
                                    item.UnReadCountData = "(有更新)";
                                }
                            }
                            else
                            {
                                item.UnReadCountData     = "(有更新)";
                                item.LastReadChapterName = item.NewestChapterName;
                            }
                            ShelfBookList.Add(item);
                        }
                        DBBookShelf.ClearBooks(AppDataPath.GetBookShelfDBPath());
                        DBBookShelf.InsertOrUpdateBooks(AppDataPath.GetBookShelfDBPath(), ShelfBookList.ToList());
                    }
                }
                ToastHeplper.ShowMessage("个人书架已更新");
            }
        }