private async void BtnLogin_OnClick(object sender, RoutedEventArgs e) { string username = File.ReadAllText(@"D:\Test Dir\LoginWebTest\username.txt"); string password = File.ReadAllText(@"D:\Test Dir\LoginWebTest\password.txt"); parser = new Wenku8Parser2(username, password, Wenku8Parser.LoginDuration.OneDay); parser.Init(); if (await parser.TryLogin()) { parser.SaveCookie(); List <BookshelfLink> myBooks = await parser.GetBooksFromBookshelf(); bookListbox.ItemsSource = myBooks; if (myBooks.Count > 0) { bookListbox.SelectedIndex = 0; } btnLogin.IsEnabled = false; btnGetIssues.IsEnabled = true; } }
static async Task Main(string[] args) { //await Test(); using (BookContext bookContext = new BookContext(sqliteString)) { bookContext.Database.EnsureCreated(); bookContext.Database.OpenConnection(); // test with db bookContext.Set <ChapterLink>().Load(); bookContext.Set <IssueLink>().Load(); bookContext.Set <BookLink>().Load(); var testBook0 = bookContext.BookLinks.FirstOrDefault(); Console.WriteLine(testBook0?.IndexPage); string username = File.ReadAllText(@"D:\Test Dir\LoginWebTest\username.txt"); string password = File.ReadAllText(@"D:\Test Dir\LoginWebTest\password.txt"); Wenku8Parser2 parser = new Wenku8Parser2(username, password, Wenku8Parser.LoginDuration.OneDay); parser.Init(); if (await parser.TryLogin()) { parser.SaveCookie(); List <BookshelfLink> myBooks = await parser.GetBooksFromBookshelf(); foreach (var bookshelfLink in myBooks) { BookLink bookLinkFromWeb = await parser.FindBookIndexPageAsync(bookshelfLink.MainPage, CodePage.Gb2312); // update book to database (update or add new) await TryAddNewBook(bookContext, bookLinkFromWeb); bookContext.SaveChanges(); // download book parser.OnlyReturnNew = true; BookLink bookLinkFromDB = await bookContext.BookLinks.FirstOrDefaultAsync(b => b.IndexPage == bookLinkFromWeb.IndexPage); Book book = await parser.GetBookAsync(bookLinkFromDB, CodePage.Gb2312); bookContext.SaveChanges(); book.SaveToTxt(Environment.CurrentDirectory); // test with db //bookContext = new BookContext(); //bookContext.Database.EnsureCreated(); //bookContext.Database.OpenConnection(); var testBook = await bookContext.BookLinks.FirstOrDefaultAsync(); Console.WriteLine(testBook.IndexPage); //bookContext.Database.CloseConnection(); //bookContext.Dispose(); return; // download book //Book book = await parser.GetBookAsync(bookLink); // test with db after get book content bookContext.SaveChanges(); var testBook2 = await bookContext.BookLinks.FirstOrDefaultAsync(); Console.WriteLine(testBook2.IndexPage); bookContext.Database.CloseConnection(); // save txt to file //book.SaveToTxt(AppDomain.CurrentDomain.BaseDirectory); } } else { Console.WriteLine("Login failed!"); } } Console.ReadLine(); }