public void SaveNote()
 {
     Book                = BookDomain.SetUnchanged(_book);
     Editing.NoteText    = _noteText;
     Editing.EntityState = EntityState.Modified;
     _bookDomain.UpdateBook(Book);
     OnNoteChanged();
 }
Esempio n. 2
0
 private void Save()
 {
     SelectedBook.EntityState = EntityState.Modified;
     _bookDomain.UpdateBook(SelectedBook);
     OnBookChanged(SelectedBook, BookEventArgs.BookState.Updated, null);
     Window.Close();
 }
Esempio n. 3
0
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            for (var index = 0; index < _booksToScrape.Count; index++)
            {
                if (Worker.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                var book = _booksToScrape[index];
                //Generate cover image
                if (_generateCovers)
                {
                    book.CoverImage = _coverImageDomain.GenerateCoverImageFromPdf(book);
                }
                else
                {
                    book.CoverImage.EntityState = EntityState.Unchanged;
                }


                if (_rescrape == false && book.Scraped)
                {
                    //Book has already been scraped so skip
                    continue;
                }

                //Try and guess 10 digit ISBN
                book.Isbn = _guesser.GuessBookIsbn(book.BookFile.FullPathAndFileNameWithExtension);
                if (string.IsNullOrEmpty(book.Isbn))
                {
                    //Couldnt find any valid isbn so skip to next book
                    book.Scraped = false;
                    book.BookFile.EntityState        = EntityState.Unchanged;
                    book.BookHistory.EntityState     = EntityState.Unchanged;
                    book.SourceDirectory.EntityState = EntityState.Unchanged;
                    book.EntityState = EntityState.Modified;
                    _bookDomain.UpdateBook(book);
                    continue;
                }
                SearchResult scrapedResult;
                try
                {
                    _scrapeResults = _scraper.SearchBooks(book.Isbn);
                }
                catch (BookieException)
                {
                    Logger.Log.Error("No internet connection while scraping. Terminated");
                    e.Cancel    = true;
                    _noInternet = true;
                    return;
                }

                // If search results are found
                if (_scrapeResults != null && _scrapeResults.Count > 0)
                {
                    scrapedResult = _scrapeResults.FirstOrDefault(x => x.Book != null);
                    if (scrapedResult == null)
                    {
                        continue;
                    }
                    book.Isbn          = book.Isbn;
                    book.Title         = scrapedResult.Book.Title;
                    book.Abstract      = scrapedResult.Book.Abstract ?? "";
                    book.Pages         = scrapedResult.Book.Pages;
                    book.DatePublished = scrapedResult.Book.DatePublished;
                    book.Scraped       = true;

                    if (scrapedResult.Book.Authors != null)
                    {
                        book.Authors = scrapedResult.Book.Authors;
                    }
                    if (scrapedResult.Book.Publishers != null)
                    {
                        book.Publishers = scrapedResult.Book.Publishers;
                    }
                }
                else
                {
                    // No results found with an 10 digit ISBN so try with a 13 digit ISBN
                    book.Isbn = IsbnGuesser.Isbn13to10(book.Isbn);
                    if (string.IsNullOrEmpty(book.Isbn))
                    {
                        book.Scraped = false;
                        continue;
                    }
                    _scrapeResults = _scraper.SearchBooks(book.Isbn);
                    if (_scrapeResults == null || _scrapeResults.Count <= 0)
                    {
                        continue;
                    }
                    scrapedResult = _scrapeResults.FirstOrDefault(x => x.Book != null);
                    if (scrapedResult == null)
                    {
                        continue;
                    }
                    book.Isbn          = book.Isbn;
                    book.Title         = scrapedResult.Book.Title;
                    book.Abstract      = scrapedResult.Book.Abstract ?? "";
                    book.Pages         = scrapedResult.Book.Pages;
                    book.DatePublished = scrapedResult.Book.DatePublished;
                    book.Scraped       = true;
                }


                var publishers = scrapedResult.Publishers.ToList();
                var authors    = scrapedResult.Authors.ToList();

                foreach (var publisher in publishers)
                {
                    publisher.EntityState = EntityState.Added;
                    book.Publishers.Add(publisher);
                }

                foreach (var author in authors)
                {
                    author.EntityState = EntityState.Added;
                    book.Authors.Add(author);
                }

                book.BookFile.EntityState        = EntityState.Unchanged;
                book.BookHistory.EntityState     = EntityState.Unchanged;
                book.SourceDirectory.EntityState = EntityState.Unchanged;
                book.EntityState = EntityState.Modified;

                _bookDomain.UpdateBook(book);

                var percentage = Utils.CalculatePercentage(index + 1, 1, _booksToScrape.Count);
                Worker.ReportProgress(percentage, book);
            }
        }