Example #1
0
        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            Logger.Log("MainPage:Loaded:called");
            var bookdb = BookDataContext.Get();

            Logger.Log("MainPage:Loaded:about to migrate");
            CommonQueries.BookDoMigrate(bookdb);
            Logger.Log("MainPage:Loaded:done migration");

            // Reset to the tab the user had originally picked.
            SelectUserTab();
            var(id, _) = MainEpubReader.GetCurrReadingBook();  // _ is pos

            if (App.SavedActivatedBookData != null)
            {
                var nav = Navigator.Get();
                nav.DisplayBook(Navigator.NavigateControlId.InitializationCode, App.SavedActivatedBookData, App.SavedActivatedBookLocation);
            }
            else if (id != null)
            {
                var book = CommonQueries.BookGet(bookdb, id);
                if (book != null)
                {
                    var nav = Navigator.Get();
                    nav.DisplayBook(Navigator.NavigateControlId.InitializationCode, book);
                }
            }
            if (WarmUpDataBase == null)
            {
                WarmUpDataBase = CommonQueries.FirstSearchToWarmUpDatabase();
            }

#if DEBUG
            // There are only shown in debug mode!
            uiLogTab.Visibility    = Visibility.Visible;
            uiDebugMenu.Visibility = Visibility.Visible;
#endif

            await BookMarkFile.SmartReadAsync();

            Logger.Log("MainPage:Loaded:returning");
        }
Example #2
0
        protected override void OnActivated(IActivatedEventArgs args)
        {
            Logger.Log($"App:OnActivated:called");
            switch (args.Kind)
            {
            case ActivationKind.Protocol:
                var paarg = args as ProtocolActivatedEventArgs;
                var(bookId, bookLocation) = ProjectRomeActivity.ParseUrl(paarg.Uri);
                var nav      = Navigator.Get();
                var bookdb   = BookDataContext.Get();
                var bookData = CommonQueries.BookGet(bookdb, bookId);
                SavedActivatedBookData     = bookData;
                SavedActivatedBookLocation = bookLocation;
                DoLaunch();
                break;

            default:
                base.OnActivated(args);
                break;
            }
            Logger.Log($"App:OnActivated:done");
        }
        private void SyncPosition_Click(object sender, RoutedEventArgs e)
        {
            var bookdb = BookDataContext.Get();

            // The button is only clickable when there's exactly one item selected
            // (baring race conditions, of course)
            foreach (var item in uiList.SelectedItems)
            {
                var noteWithTitle = item as UserNoteWithTitle;
                if (noteWithTitle == null)
                {
                    return;                        // should never happen.
                }
                var note = noteWithTitle.BaseNote;
                if (note == null)
                {
                    continue;               // should never happen
                }
                var location = note.LocationToBookLocatation();
                if (location == null)
                {
                    continue;                   // should never happen
                }
                // Are we in the same book, or a different one?

                var nav = Navigator.Get();
                if (noteWithTitle.BookId != CurrBookData.BookId)
                {
                    var book = CommonQueries.BookGet(bookdb, noteWithTitle.BookId);
                    CurrBookData = book; // make sure to reset this!
                    nav.DisplayBook(ControlId, book, location);
                }
                else
                {
                    nav.UserNavigatedTo(ControlId, location);
                }
            }
        }
Example #4
0
        private static async Task <BookData> InsertFileIntoDatabase(BookDataContext bookdb, IFolder folder, string filename, bool getFullData = false)
        {
            BookData bookData = null;

            if (bookdb == null)
            {
                bookdb = BookDataContext.Get();
            }
            string fullfname = $"{folder.Path}\\{filename}";
            var    wd        = new WizardData()
            {
                FilePath = fullfname, FileName = filename
            };

            try
            {
                wd = await GutenbergFileWizard.GetDataAsync(wd, getFullData);

                if (!string.IsNullOrEmpty(wd.BookId))
                {
                    bookData = CommonQueries.BookGet(bookdb, wd.BookId);

                    //TODO: when I drop a book that's been added to the database because it was
                    // in a bookmark file (which should happen reasonably often!)
                    // then the bookData here is non-null, but also not really filled in well.
                    if (bookData == null || bookData.BookSource.StartsWith(BookData.BookSourceBookMarkFile))
                    {
                        if (wd.BD != null)
                        {
                            // Gotcha! Add to the main book database!
                            if (!string.IsNullOrEmpty(wd.BD.BookId))
                            {
                                wd.BD.Files.Add(new FilenameAndFormatData()
                                {
                                    FileName = filename,
                                    BookId   = wd.BookId,
                                    MimeType = "application/epub+zip"
                                });
                                wd.BD.BookSource = BookData.BookSourceUser;

                                // Add in possible data from the bookData set by the user
                                if (bookData != null)
                                {
                                    wd.BD.NavigationData = bookData.NavigationData;
                                    wd.BD.Review         = bookData.Review;
                                    wd.BD.Notes          = bookData.Notes;

                                    //TODO: now get this book into the database.
                                    // via some kind of merge??
                                }
                                else
                                {
                                    CommonQueries.BookAdd(bookdb, wd.BD, CommonQueries.ExistHandling.IfNotExists);
                                    CommonQueries.BookSaveChanges(bookdb);
                                    bookData = wd.BD;
                                }
                            }
                            else
                            {
                                App.Error($"ERROR: {filename} ({wd.BookId}) was unable to wizard read and get ID");
                            }
                        }
                        else
                        {
                            App.Error($"ERROR: {filename} ({wd.BookId}) was unable to wizard read");
                        }
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine($"{filename}({wd.BookId}) is {bookData.GetBestTitleForFilename()}");
                    }
                    var fullpath = folder.Path;
                    if (fullpath.Contains(@"AppX\Assets\PreinstalledBooks"))
                    {
                        // Whoops. The initial database might incorrectly have a developer path hard-coded.
                        // Replace with correct location.
                        fullpath = $"PreinstalledBooks:";
                    }
                    CommonQueries.DownloadedBookEnsureFileMarkedAsDownloaded(bookdb, wd.BookId, fullpath, filename);
                }
                else
                {
                    App.Error($"{filename} with id {wd.BookId} is not a known type of e-book");
                }
            }
            catch (Exception)
            {
                App.Error($"{filename} is not a readable e-book");
            }
            return(bookData);
        }