Пример #1
0
        private async void FrmDownload_Load(object sender, EventArgs e)
        {
            BookInfoData bid = new BookInfoData();


            if (bid.GetBookInfos().Where(t => book.Equals(t)).FirstOrDefault() != null)
            {
                this.Close();
            }
            else
            {
                ChapterInfoData cif = new ChapterInfoData(book);

                groupBox1.Text = "正在初始化.....";
                HttpClient client = new HttpClient();
                string     html   = await client.GetStringAsync(book.URL);

                Match macth = Regex.Match(html, "<script>window.location.href='(.*)';</script>");
                if (macth.Length > 0 && macth.Groups.Count > 1)
                {
                    html = await client.GetStringAsync(macth.Groups[1].Value);
                }

                Elements           elements     = NSoupClient.Parse(html).Select("#list a[href]");
                List <ChapterInfo> chapterInfos = new List <ChapterInfo>();
                foreach (var item in elements)
                {
                    ChapterInfo chapterInfo = new ChapterInfo();
                    chapterInfo.ID       = Kit.GetGuid();
                    chapterInfo.Title    = item.Html().Replace(" ", "");
                    chapterInfo.Url      = "http://www.xs.la" + item.Attr("href");
                    chapterInfo.Metadata = item.Html();
                    chapterInfo.AddTime  = DateTime.Now;
                    chapterInfos.Add(chapterInfo);
                }
                cif.Save(chapterInfos);

                groupBox1.Text = "初始化完成";
            }

            BookInfoData bif = new BookInfoData();


            if (bif.GetBookInfos(t => book.Equals(t)).Count <= 0)
            {
                book.AddTime = DateTime.Now;
                bif.Add(book);
            }

            Download();
        }
Пример #2
0
        private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (listView1.SelectedItems.Count > 0)
            {
                BookInfo    book        = listView1.SelectedItems[0].Tag as BookInfo;
                FrmDownload frmDownload = new FrmDownload(book);
                frmDownload.ShowDialog();

                UserBookListData ubld = new UserBookListData();

                UserInfo userInfo = UserInfoHelper.GetUserInfo();

                if (ubld.GetUserBookLists(t => t.BookID == book.ID && t.UserID == userInfo.ID).Count <= 0)
                {
                    BookInfoData bif      = new BookInfoData();
                    BookInfo     bookInfo = bif.GetBookInfos(t => book.Equals(t)).FirstOrDefault();
                    if (bookInfo == null)
                    {
                        ubld.Add(userInfo.ID, book.ID);
                    }
                    else
                    {
                        ubld.Add(userInfo.ID, bookInfo.ID);
                    }
                }
                //刷新我的书架
                frmMain.LoadListViewData();
            }
        }