Exemplo n.º 1
0
 private static bool BookCanBeDownloaded(Book book)
 {
     bool result = true;
     int maxPeriodFromDeath = 0;
     foreach (Author author in book.Authors)
     {
         int periodFromDeath = PeriodFromDeath(author.DeathDate);
         if (periodFromDeath > maxPeriodFromDeath)
         {
             maxPeriodFromDeath = periodFromDeath;
         }
     }
     if (maxPeriodFromDeath < 71)
     {
         return false;
     }
     if (book.BookContents.FirstOrDefault() != null)
     {
         return result && book.BookContents.FirstOrDefault().Source == null;
     }
     else
     {
         return false;
     }
 }
Exemplo n.º 2
0
 private void UpdateBookRecord(Entities context, Book book, BookItem bookItem)
 {
     if (book.Cover == null && bookItem.volumeInfo.imageLinks != null && bookItem.volumeInfo.imageLinks.thumbnail != null)
     {
         book.Cover = DownloadCover(bookItem.volumeInfo.imageLinks.thumbnail);
         book.CoverUpdated = DateTime.Now;
     }
     if (string.IsNullOrEmpty(book.Description) && !string.IsNullOrEmpty(bookItem.volumeInfo.description))
     {
         book.Description = bookItem.volumeInfo.description;
     }
     if (book.PagesCount.GetValueOrDefault(0) == 0 && bookItem.volumeInfo.pageCount > 0)
     {
         book.PagesCount = bookItem.volumeInfo.pageCount;
     }
     if (!string.IsNullOrEmpty(bookItem.volumeInfo.publisher))
     {
         book.Publisher = bookItem.volumeInfo.publisher;
     }
     if (bookItem.volumeInfo.publishedDate != null)
     {
         try
         {
             book.PublishDate = Convert.ToDateTime(bookItem.volumeInfo.publishedDate);
         }
         catch { }
     }
     if (bookItem.volumeInfo.industryIdentifiers != null)
     {
         book.ISBN = GetISBN(bookItem.volumeInfo.industryIdentifiers);
     }
     UpdateBookRecordAsProcessed(context, book);
 }
Exemplo n.º 3
0
 private void UpdateBookRecordAsProcessed(Entities context, Book book)
 {
     book.FromGoogleBooks = true;
     if (book.CoverUpdated == null)
     {
         book.CoverUpdated = DateTime.Now;
     }
 }
Exemplo n.º 4
0
 private void AddBookToDatabase(string bookName)
 {
     book = new Book();
     book.BookId = Guid.NewGuid();
     book.Name = bookName;
     book.ClearName = TextNormalization.GetClearName(bookName);
     book.CoverUpdated = DateTime.Now;
     book.Created = DateTime.Now;
     context.Books.Add(book);
 }
Exemplo n.º 5
0
 private static void UploadBookSources(Book book, Flag flag)
 {
     byte[] bookSources = GetBookSources(book.BookContents.FirstOrDefault().SourceFileName);
     /*using (FileStream fs = new FileStream(AppConfig.TemporaryFolder + "test.zip", FileMode.Create, FileAccess.Write))
     {
         fs.Write(bookSources, 0, bookSources.Length);
         fs.Flush();
     }*/
     if (bookSources != null)
     {
         book.BookContents.FirstOrDefault().Source = bookSources;
         flag.State = 1;
     }
 }