Example #1
0
        public async void _ScanDeviceLibrary()
        {
            var dlg = new Dialogs.YesNo("Rescan Library", "Your Kindle will be scanned for books which will then be organized and renamed according to your Kindle's settings.");
            await MaterialDesignThemes.Wpf.DialogHost.Show(dlg);

            if (dlg.DialogResult == false)
            {
                return;
            }

            var prgDlg = new Dialogs.Progress("Scanning Library", true);

            OpenBottomDrawer(prgDlg.Content);

            _ = Task.Run(() =>
            {
                try
                {
                    foreach (BookBase book in SelectedDevice.Rescan())
                    {
                        prgDlg.Current = $"Processed {book.Title}";
                    }
                }
                catch (Exception e)
                {
                    prgDlg.ShowError(e);
                }
                finally
                {
                    prgDlg.Finish($"{SelectedDevice.Name} library scan complete.");
                }
            });
        }
Example #2
0
        public async void _ReorganizeDeviceLibrary()
        {
            var dlg = new Dialogs.YesNo("Reorganize Library", "All books in your Kindle's library will be moved and renamed according to your Kindle's settings. This may take some time depending on the size of your library.");
            await MaterialDesignThemes.Wpf.DialogHost.Show(dlg);

            if (dlg.DialogResult == false)
            {
                return;
            }

            var prgDlg = new Dialogs.Progress("Reorganizing Library", true);

            OpenBottomDrawer(prgDlg.Content);

            _ = Task.Run(() =>
            {
                try
                {
                    foreach (BookBase book in SelectedDevice.Reorganize())
                    {
                        prgDlg.Current = $"Processed {book.Title}";
                    }
                    prgDlg.Current = "Cleaning up...";
                    SelectedDevice.Clean();
                }
                catch (Exception e)
                {
                    prgDlg.ShowError(e);
                }
                finally
                {
                    prgDlg.Finish($"{SelectedDevice.Name} reorganized.");
                }
            });
        }
Example #3
0
        public async void ImportDirectory(string path)
        {
            var dlg = new Dialogs.BulkImport(path);
            await MaterialDesignThemes.Wpf.DialogHost.Show(dlg);

            if (dlg.DialogResult == false)
            {
                return;
            }

            string[] files = dlg.SelectedFiles();

            var prgDlg = new Dialogs.Progress("Importing books", false);
            int step   = 100 / files.Length;

            OpenBottomDrawer(prgDlg.Content);

            _ = Task.Run(() =>
            {
                List <Exception> errors = new List <Exception>();

                foreach (string file in files)
                {
                    prgDlg.Current = $"Importing {file}";
                    try
                    {
                        App.LocalLibrary.ImportBook(file);
                    }
                    catch (Exception e)
                    {
                        e.Data["item"] = file;
                        errors.Add(e);
                    }
                    finally
                    {
                        prgDlg.Percent += step;
                    }
                }
                prgDlg.Finish("Import finished.");

                if (errors.Count > 0)
                {
                    prgDlg.ShowError(new AggregateException(errors.ToArray()));
                }
            });
        }
Example #4
0
        public void ImportBooksDrop(string[] paths)
        {
            if (paths.Length == 1 && Directory.Exists(paths[0]))
            {
                ImportDirectory(paths[0]);
                return;
            }
            else if (paths.Length == 1)
            {
                Task.Run(() =>
                {
                    if (!Formats.Resources.AcceptedFileTypes.Contains(Path.GetExtension(paths[0])))
                    {
                        var errDlg = new Dialogs.Error("Incompatible Format", $"Importing {Path.GetExtension(paths[0])} format books has not yet been implemented.");
                        _          = MaterialDesignThemes.Wpf.DialogHost.Show(errDlg);
                        return;
                    }
                    try
                    {
                        ImportBook(paths[0]);
                    }
                    catch (Exception e)
                    {
                        App.Current.Dispatcher.Invoke(() =>
                        {
                            var dlg = new Dialogs.Error("Import failed", e.Message);
                            _       = MaterialDesignThemes.Wpf.DialogHost.Show(dlg);
                        });
                        return;
                    }
                    finally
                    {
                        CloseBottomDrawer();
                    }
                    SnackBarQueue.Enqueue($"{Path.GetFileName(paths[0])} imported");
                });
            }
            else
            {
                List <Exception> errs = new List <Exception>();

                var prgDlg = new Dialogs.Progress("Importing Books", false);
                OpenBottomDrawer(prgDlg.Content);
                int step = 100 / paths.Length;

                Task.Run(() =>
                {
                    foreach (string path in paths)
                    {
                        prgDlg.Current  = $"Importing {Path.GetFileName(path)}";
                        prgDlg.Percent += step;
                        if (!Formats.Resources.AcceptedFileTypes.Contains(Path.GetExtension(path)))
                        {
                            Exception e    = new Exception($"Invalid filetype ${Path.GetExtension(path)}");
                            e.Data["item"] = path;
                            errs.Add(e);
                            continue;
                        }
                        try
                        {
                            ImportBook(path);
                        }
                        catch (Exception e)
                        {
                            e.Data["item"] = path;
                            errs.Add(e);
                            continue;
                        }
                    }

                    if (errs.Count > 0)
                    {
                        prgDlg.Finish("Import finished with errors:");
                        prgDlg.ShowError(new AggregateException(errs.ToArray()));
                    }
                    else
                    {
                        prgDlg.Close();
                        SnackBarQueue.Enqueue($"{paths.Length} new books imported successfully");
                    }
                });
            }
        }
Example #5
0
        public Unit _SendBook(IList bookList)
        {
            if (SelectedDevice == null)
            {
                var errDlg = new Dialogs.Error("No Kindle Selected", "Connect to Kindle Before Transferring Books");
                MaterialDesignThemes.Wpf.DialogHost.Show(errDlg);
                return(Unit.Default);
            }

            Task.Run(() =>
            {
                if (bookList.Count == 1)
                {
                    try
                    {
                        BookBase book = (BookBase)bookList[0];
                        book.FilePath = App.LocalLibrary.AbsoluteFilePath(book);
                        SelectedDevice.ImportBook(book);
                        SnackBarQueue.Enqueue($"{book.Title} transferred to {SelectedDevice.Name}");
                    }
                    catch (Exception e)
                    {
                        var dlg = new Dialogs.Error("Error transferring book", e.Message);
                    }
                }
                else
                {
                    List <Exception> errs = new List <Exception>();

                    var prgDlg = new Dialogs.Progress("Syncing Library", false);
                    OpenBottomDrawer(prgDlg.Content);

                    int step = 100 / bookList.Count;

                    foreach (Database.BookEntry book in bookList)
                    {
                        try
                        {
                            book.FilePath = App.LocalLibrary.AbsoluteFilePath(book);
                            SelectedDevice.ImportBook(book);
                            prgDlg.Current = $"Transferred {book.Title}";
                        }
                        catch (Exception e)
                        {
                            e.Data["item"] = book.Title;
                            errs.Add(e);
                        }
                        finally
                        {
                            prgDlg.Percent += step;
                        }
                    }

                    if (errs.Count > 0)
                    {
                        prgDlg.Finish("Book transfer finished with errors:");
                        prgDlg.ShowError(new AggregateException(errs.ToArray()));
                    }
                    else
                    {
                        prgDlg.Close();
                        SnackBarQueue.Enqueue("Book transfer finished");
                    }
                }
            });
            return(Unit.Default);
        }
Example #6
0
        public async void _SyncDeviceLibrary()
        {
            if (SelectedDevice == null)
            {
                var errDlg = new Dialogs.Error("No Kindle Selected", "Connect to Kindle Before Transferring Books");
                await MaterialDesignThemes.Wpf.DialogHost.Show(errDlg);

                return;
            }

            List <Database.BookEntry> toTransfer = new List <Database.BookEntry>();

            foreach (Database.BookEntry book in App.LocalLibrary.Database.BOOKS)
            {
                if (!SelectedDevice.Database.BOOKS.Any(x => x.Id == book.Id))
                {
                    toTransfer.Add(book);
                }
            }

            var dlg = new Dialogs.SyncConfirm(toTransfer, SelectedDevice.Name);
            await MaterialDesignThemes.Wpf.DialogHost.Show(dlg);

            if (dlg.DialogResult == false)
            {
                return;
            }

            var a = dlg.UserSelectedBooks;

            foreach (var b in dlg.UserSelectedBooks)
            {
                if (!b.Checked)
                {
                    Database.BookEntry t = toTransfer.FirstOrDefault(x => x.Id == b.Id);
                    if (t != null)
                    {
                        toTransfer.Remove(t);
                    }
                }
            }

            var prgDlg = new Dialogs.Progress("Syncing Kindle Library", false);

            OpenBottomDrawer(prgDlg.Content);

            _ = Task.Run(() =>
            {
                List <Exception> errs = new List <Exception>();
                int step = 100 / toTransfer.Count;
                for (int i = 0; i < toTransfer.Count; i++)
                {
                    Database.BookEntry book = toTransfer[i];
                    try
                    {
                        prgDlg.Current  = $"Copying {book.Title}";
                        prgDlg.Percent += step;
                        book.FilePath   = App.LocalLibrary.AbsoluteFilePath(book);
                        SelectedDevice.ImportBook(book);
                    }
                    catch (Exception e)
                    {
                        e.Data.Add("item", book.Title);
                        errs.Add(e);
                    }
                }

                if (errs.Count > 0)
                {
                    prgDlg.Finish("Library sync finished with errors:");
                    prgDlg.ShowError(new AggregateException(errs.ToArray()));
                }
                else
                {
                    prgDlg.Close();
                    SnackBarQueue.Enqueue($"{SelectedDevice.Name} library synced");
                }
            });
        }
Example #7
0
        public Unit _ReceiveBook(IList bookList)
        {
            if (bookList.Count == 0)
            {
                return(Unit.Default);
            }

            Database.BookEntry[] dbRows = new Database.BookEntry[bookList.Count];
            bookList.CopyTo(dbRows, 0);

            Task.Run(() =>
            {
                if (bookList.Count == 1)
                {
                    Database.BookEntry book = (Database.BookEntry)bookList[0];
                    try
                    {
                        book.FilePath = SelectedDevice.AbsoluteFilePath(book);
                        ImportBook(book);
                    }
                    catch (Exception e)
                    {
                        App.Current.Dispatcher.Invoke(() =>
                        {
                            var dlg = new Dialogs.Error("Error transferring book", e.Message);
                            MaterialDesignThemes.Wpf.DialogHost.Show(dlg);
                        });
                        return;
                    }
                    SnackBarQueue.Enqueue($"{book.Title} copied to library.");
                }
                else
                {
                    List <Exception> errs = new List <Exception>();

                    var prgDlg = new Dialogs.Progress("Syncing Library", false);
                    OpenBottomDrawer(prgDlg.Content);

                    int step = 100 / bookList.Count;

                    foreach (Database.BookEntry b in bookList)
                    {
                        Database.BookEntry book = new Database.BookEntry(b);
                        try
                        {
                            book.FilePath = SelectedDevice.AbsoluteFilePath(book);
                            ImportBook(book);
                        }
                        catch (Exception e)
                        {
                            e.Data["item"] = book.Title;
                            errs.Add(e);
                        }
                    }

                    if (errs.Count > 0)
                    {
                        prgDlg.Finish("Book transfer finished with errors:");
                        prgDlg.ShowError(new AggregateException(errs.ToArray()));
                    }
                    else
                    {
                        prgDlg.Close();
                        SnackBarQueue.Enqueue("Book transfer finished");
                    }
                }
            });

            return(Unit.Default);
        }