Exemple #1
0
        public DownloadBookViewModel GetDownloadBookViewModel(string md5Hash)
        {
            NonFictionBook nonFictionBook = localDatabase.GetNonFictionBookByMd5Hash(md5Hash.ToLowerInvariant());

            if (nonFictionBook == null || !nonFictionBook.FileId.HasValue)
            {
                return(null);
            }
            LibraryFile libraryFile      = localDatabase.GetFileById(nonFictionBook.FileId.Value);
            string      downloadFileName = String.Concat(nonFictionBook.Authors, " - ", nonFictionBook.Title, ".", nonFictionBook.Format);

            if (downloadFileName.Length > 200)
            {
                downloadFileName = String.Concat(nonFictionBook.Md5Hash, ".", nonFictionBook.Format);
            }
            DownloadBookViewModel result = new DownloadBookViewModel
            {
                DownloadFileName = downloadFileName,
                LocalFilePath    = libraryFile.FilePath
            };

            if (fileExtensionContentTypeProvider.TryGetContentType(downloadFileName, out string contentTypeFromFormat))
            {
                result.ContentType = contentTypeFromFormat;
            }
            else if (fileExtensionContentTypeProvider.TryGetContentType(downloadFileName, out string contentTypeFromLocalFileExtension))
            {
                result.ContentType = contentTypeFromLocalFileExtension;
            }
            else
            {
                result.ContentType = "application/octet-stream";
            }
            return(result);
        }
Exemple #2
0
 public NonFictionDetailsTabViewModel(MainModel mainModel, IWindowContext parentWindowContext, NonFictionBook book, bool isInModalWindow)
     : base(mainModel, parentWindowContext, book.Title)
 {
     this.book           = book;
     IsInModalWindow     = isInModalWindow;
     DownloadBookCommand = new Command(DownloadBook);
     CloseCommand        = new Command(CloseTab);
     Initialize();
 }
Exemple #3
0
 public NonFictionDetailsWindowViewModel(MainModel mainModel, NonFictionBook book, bool modalWindow)
 {
     this.mainModel      = mainModel;
     this.book           = book;
     this.modalWindow    = modalWindow;
     tabViewModel        = null;
     WindowTitle         = book.Title;
     WindowWidth         = mainModel.AppSettings.NonFiction.DetailsWindow.Width;
     WindowHeight        = mainModel.AppSettings.NonFiction.DetailsWindow.Height;
     WindowClosedCommand = new Command(WindowClosed);
 }
Exemple #4
0
        public BookViewModel GetBookViewModel(int bookId)
        {
            NonFictionBook book = localDatabase.GetNonFictionBookById(bookId);

            if (book == null)
            {
                return(null);
            }
            return(new BookViewModel
            {
                Title = book.Title,
                Authors = book.Authors,
                Series = book.Series,
                Publisher = book.Publisher,
                Year = book.Year,
                Language = book.Language,
                Format = book.Format,
                Identifier = book.Identifier,
                AddedDateTime = FormatDateTime(book.AddedDateTime),
                LastModifiedDateTime = FormatDateTime(book.LastModifiedDateTime),
                Library = book.Library,
                FileSize = FileSizeToString(book.SizeInBytes, true),
                Topic = book.Topic,
                Volume = book.VolumeInfo,
                Periodical = book.Periodical,
                City = book.City,
                Edition = book.Edition,
                Pages = GetPagesText(book.Pages, book.PagesInFile),
                Tags = book.Tags,
                Md5Hash = book.Md5Hash,
                Commentary = book.Commentary,
                LibgenId = book.LibgenId.ToString(),
                Issn = book.Issn,
                Udc = book.Udc,
                Lbc = book.Lbc,
                Lcc = book.Lcc,
                Ddc = book.Ddc,
                Doi = book.Doi,
                OpenLibraryId = book.OpenLibraryId,
                GoogleBookId = book.GoogleBookId,
                Asin = book.Asin,
                Dpi = book.Dpi.ToString(),
                Ocr = GetOcrString(book.Searchable),
                Bookmarked = GetBookmarkedString(book.Bookmarked),
                Scanned = GetScannedString(book.Scanned),
                Orientation = GetOrientationString(book.Orientation),
                Paginated = GetPaginatedString(book.Paginated),
                Color = GetColorString(book.Color),
                Cleaned = GetCleanedString(book.Cleaned),
                IsInLibrary = book.FileId.HasValue
            });
        }
Exemple #5
0
 public static string GetNonFictionCoverUrl(Mirrors.MirrorConfiguration mirror, NonFictionBook book)
 {
     return(Replace(mirror.NonFictionCoverUrl, nonFictionTransformations, book));
 }
Exemple #6
0
 public Task <SynchronizationResult> SynchronizeNonFictionAsync(IProgress <object> progressHandler, CancellationToken cancellationToken)
 {
     return(Task.Run(async() =>
     {
         Logger.Debug("Synchronization has started.");
         if (NonFictionBookCount == 0)
         {
             throw new Exception("Non-fiction table must not be empty.");
         }
         CheckAndCreateNonFictionIndexes(progressHandler, cancellationToken);
         if (cancellationToken.IsCancellationRequested)
         {
             Logger.Debug("Synchronization has been cancelled.");
             return SynchronizationResult.CANCELLED;
         }
         Logger.Debug("Loading last non-fiction book.");
         NonFictionBook lastModifiedNonFictionBook = localDatabase.GetLastModifiedNonFictionBook();
         Logger.Debug($"Last non-fiction book: Libgen ID = {lastModifiedNonFictionBook.LibgenId}, last modified date/time = {lastModifiedNonFictionBook.LastModifiedDateTime}.");
         string jsonApiUrl = Mirrors[AppSettings.Mirrors.NonFictionSynchronizationMirrorName].NonFictionSynchronizationUrl;
         if (jsonApiUrl == null)
         {
             throw new Exception("JSON API URL is null.");
         }
         JsonApiClient jsonApiClient = new JsonApiClient(HttpClient, jsonApiUrl, lastModifiedNonFictionBook.LastModifiedDateTime,
                                                         lastModifiedNonFictionBook.LibgenId);
         progressHandler.Report(new ImportLoadLibgenIdsProgress());
         BitArray existingLibgenIds = localDatabase.GetNonFictionLibgenIdsBitArray();
         NonFictionImporter importer = new NonFictionImporter(localDatabase, existingLibgenIds, lastModifiedNonFictionBook);
         progressHandler.Report(new SynchronizationProgress(0, 0, 0));
         int downloadedBookCount = 0;
         int totalAddedBookCount = 0;
         int totalUpdatedBookCount = 0;
         Importer.ImportProgressReporter importProgressReporter = (int objectsAdded, int objectsUpdated) =>
         {
             progressHandler.Report(new SynchronizationProgress(downloadedBookCount, totalAddedBookCount + objectsAdded,
                                                                totalUpdatedBookCount + objectsUpdated));
         };
         while (true)
         {
             List <NonFictionBook> currentBatch;
             try
             {
                 Logger.Debug("Downloading next batch from the server.");
                 currentBatch = await jsonApiClient.DownloadNextBatchAsync(cancellationToken);
             }
             catch (TaskCanceledException)
             {
                 Logger.Debug("Synchronization has been cancelled.");
                 return SynchronizationResult.CANCELLED;
             }
             if (!currentBatch.Any())
             {
                 Logger.Debug("Current batch is empty, download is complete.");
                 break;
             }
             downloadedBookCount += currentBatch.Count;
             Logger.Debug($"Batch download is complete, {downloadedBookCount} books have been downloaded so far.");
             progressHandler.Report(new SynchronizationProgress(downloadedBookCount, totalAddedBookCount, totalUpdatedBookCount));
             if (cancellationToken.IsCancellationRequested)
             {
                 Logger.Debug("Synchronization has been cancelled.");
                 return SynchronizationResult.CANCELLED;
             }
             Logger.Debug("Importing downloaded batch.");
             Importer.ImportResult importResult =
                 importer.Import(currentBatch, importProgressReporter, SYNCHRONIZATION_PROGRESS_UPDATE_INTERVAL, cancellationToken);
             if (cancellationToken.IsCancellationRequested)
             {
                 Logger.Debug("Synchronization has been cancelled.");
                 return SynchronizationResult.CANCELLED;
             }
             totalAddedBookCount += importResult.AddedObjectCount;
             totalUpdatedBookCount += importResult.UpdatedObjectCount;
             Logger.Debug($"Batch has been imported, total added book count = {totalAddedBookCount}, total updated book count = {totalUpdatedBookCount}.");
         }
         Logger.Debug("Synchronization has been completed successfully.");
         return SynchronizationResult.COMPLETED;
     }));
 }
Exemple #7
0
 private void OpenDetails(NonFictionBook book)
 {
     OpenNonFictionDetailsRequested?.Invoke(this, new OpenNonFictionDetailsEventArgs(book));
 }
Exemple #8
0
 public OpenNonFictionDetailsEventArgs(NonFictionBook nonFictionBook)
 {
     NonFictionBook = nonFictionBook;
 }
Exemple #9
0
 private void PopulateBookField(NonFictionBook book, string fieldName, string line, ref int position)
 {
 }
Exemple #10
0
        static void Main(string[] args)
        {
            // BOOK BOOK BOOK
            // book 1
            var nightCircus = new FantasyBook("The Night Circus", "Erin Morgenstern", 2018, 5)
            {
                IsOwned = true,
                World   = "Earth"
            };

            // book 2
            var goodOmens = new FantasyBook("Good Omens", "Neil Gaiman and Terry Pratchett", 2020, 5)
            {
                IsOwned = true,
                World   = "Earth"
            };

            // book 3
            var besomStangAndSword = new NonFictionBook("Besom, Stang & Sword", "Christopher Orapello and Tara-Love Maguire", 2020, 4)
            {
                IsOwned         = true,
                WasInteresting  = true,
                IsPrimarySource = true,
                Topic           = "Witchcraft"
            };

            // call methods from Book Class on book 1 & 2
            nightCircus.StartABookClub();
            goodOmens.ReadBook();
            nightCircus.Learn();
            besomStangAndSword.Learn();
            Console.WriteLine(new string('-', 50));

            // HOBBY HOBBY HOBBY
            // hobby 1
            var painting = new ArtisticHobby("painting", SkillLevel.MidLevel)
            {
                ArtType = ArtType.Visual
            };

            // hobby 2
            var archery = new SportHobby("archery", SkillLevel.Beginner)
            {
                Equipment = "bow and arrows"
            };

            // hobby 3
            var plannering = new CraftHobby("art planning", SkillLevel.Amatuer)
            {
                Tools = "pens, washi tape, and highlighters"
            };

            // use a method from the Hobby Class on an instance
            painting.Levels();
            archery.DoTheHobby();
            painting.MakeMoney();
            plannering.UpgradeTools();
            plannering.DoTheHobby();
            plannering.UpgradeTools();
            Console.WriteLine(new string('-', 50));



            // SNACK SNACK SNACK
            // snack 1
            var pie = new DessertSnack
            {
                Name             = "Cherry Pie",
                MainInregredient = "Cherries",
                Flavor           = Flavour.Sweet,
            };

            // snack 2
            var parmZucchini = new VeggieSnack
            {
                Name             = "Parmesan Crusted Zucchini",
                IsHealthy        = true,
                MainInregredient = "Zucchini",
                Flavor           = Flavour.Savory
            };

            // snack 3
            var pineapple = new FruitSnack
            {
                Name             = "Pineapple",
                IsHealthy        = true,
                MainInregredient = "Pineapple",
                Flavor           = Flavour.Sweet,
                IsPineapple      = true,
            };

            // call methods for Snacks
            pie.EatSnack();
            parmZucchini.MakeSnack();
            pineapple.EatsYouBack();
            pineapple.EatSnack();
            Console.WriteLine(new string('-', 50));

            // CHAPSTICK CHAPSTICK CHAPSTICK
            // chapstick 1
            var burtsBees = new UnflavoredChapstick("Burt's Bees");

            // chapstick 2
            var cucumber = new FlavoredChapstick("Burt's Bees", false);

            // chaptstick 3
            var pink = new TintedChapstick("EOS")
            {
                Color = "pink"
            };

            // methods
            pink.WhatFlavor();
            Console.WriteLine($"Your {pink.Brand} chapstick is {pink.Flavor}.");
            burtsBees.ApplyChapstick();
        }
Exemple #11
0
 public Task <SynchronizationResult> SynchronizeNonFiction(IProgress <object> progressHandler, CancellationToken cancellationToken)
 {
     return(Task.Run(async() =>
     {
         Logger.Debug("Synchronization has started.");
         if (NonFictionBookCount == 0)
         {
             throw new Exception("Non-fiction table must not be empty.");
         }
         CheckAndCreateNonFictionIndexes(progressHandler, cancellationToken);
         if (cancellationToken.IsCancellationRequested)
         {
             Logger.Debug("Synchronization has been cancelled.");
             return SynchronizationResult.CANCELLED;
         }
         Logger.Debug("Loading last non-fiction book.");
         NonFictionBook lastModifiedNonFictionBook = localDatabase.GetLastModifiedNonFictionBook();
         Logger.Debug($"Last non-fiction book: Libgen ID = {lastModifiedNonFictionBook.LibgenId}, last modified date/time = {lastModifiedNonFictionBook.LastModifiedDateTime}.");
         string jsonApiUrl = Mirrors[AppSettings.Mirrors.NonFictionSynchronizationMirrorName].NonFictionSynchronizationUrl;
         if (jsonApiUrl == null)
         {
             throw new Exception("JSON API URL is null.");
         }
         JsonApiClient jsonApiClient = new JsonApiClient(HttpClient, jsonApiUrl, lastModifiedNonFictionBook.LastModifiedDateTime,
                                                         lastModifiedNonFictionBook.LibgenId);
         List <NonFictionBook> downloadedBooks = new List <NonFictionBook>();
         progressHandler.Report(new JsonApiDownloadProgress(0));
         while (true)
         {
             List <NonFictionBook> currentBatch;
             try
             {
                 Logger.Debug("Downloading next batch from the server.");
                 currentBatch = await jsonApiClient.DownloadNextBatchAsync(cancellationToken);
             }
             catch (TaskCanceledException)
             {
                 Logger.Debug("Synchronization has been cancelled.");
                 return SynchronizationResult.CANCELLED;
             }
             if (!currentBatch.Any())
             {
                 Logger.Debug("Current batch is empty, download is complete.");
                 break;
             }
             downloadedBooks.AddRange(currentBatch);
             Logger.Debug($"{downloadedBooks.Count} books have been downloaded so far.");
             progressHandler.Report(new JsonApiDownloadProgress(downloadedBooks.Count));
             if (cancellationToken.IsCancellationRequested)
             {
                 Logger.Debug("Synchronization has been cancelled.");
                 return SynchronizationResult.CANCELLED;
             }
         }
         NonFictionImporter importer = new NonFictionImporter(localDatabase, lastModifiedNonFictionBook);
         Logger.Debug("Importing data.");
         importer.Import(downloadedBooks, progressHandler, cancellationToken);
         if (cancellationToken.IsCancellationRequested)
         {
             Logger.Debug("Synchronization has been cancelled.");
             return SynchronizationResult.CANCELLED;
         }
         Logger.Debug("Synchronization has been completed successfully.");
         return SynchronizationResult.COMPLETED;
     }));
 }