Beispiel #1
0
        protected override async Task ProcessAsync()
        {
            var accounts = getAccounts();

            if (!accounts.Any())
            {
                Console.WriteLine("No accounts. Exiting.");
                Environment.ExitCode = (int)ExitCode.RunTimeError;
                return;
            }

            var _accounts = accounts.ToArray();

            var intro
                = (_accounts.Length == 1)
                                ? "Scanning Audible library. This may take a few minutes."
                                : $"Scanning Audible library: {_accounts.Length} accounts. This may take a few minutes per account.";

            Console.WriteLine(intro);

            var(TotalBooksProcessed, NewBooksAdded) = await LibraryCommands.ImportAccountAsync((a) => ApiExtended.CreateAsync(a), _accounts);

            Console.WriteLine("Scan complete.");
            Console.WriteLine($"Total processed: {TotalBooksProcessed}\r\nNew: {NewBooksAdded}");
        }
Beispiel #2
0
        private void UpdateCountsBw_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            while (runBackupCountsAgain)
            {
                runBackupCountsAgain = false;

                var libraryStats = LibraryCommands.GetCounts();
                e.Result = libraryStats;
            }
            updateCountsBw = null;
        }
Beispiel #3
0
        private async void btnRemoveBooks_Click(object sender, EventArgs e)
        {
            var selectedBooks = SelectedEntries.ToList();

            if (selectedBooks.Count == 0)
            {
                return;
            }

            var titles    = selectedBooks.Select(rge => "- " + rge.Title).ToList();
            var titlesAgg = titles.Take(5).Aggregate((a, b) => $"{a}\r\n{b}");

            if (titles.Count == 6)
            {
                titlesAgg += $"\r\n\r\nand 1 other";
            }
            else if (titles.Count > 6)
            {
                titlesAgg += $"\r\n\r\nand {titles.Count - 5} others";
            }

            string thisThese = selectedBooks.Count > 1 ? "these" : "this";
            string bookBooks = selectedBooks.Count > 1 ? "books" : "book";

            var result = MessageBox.Show(
                this,
                $"Are you sure you want to remove {thisThese} {selectedBooks.Count} {bookBooks} from Libation's library?\r\n\r\n{titlesAgg}",
                "Remove books from Libation?",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Question,
                MessageBoxDefaultButton.Button1);

            if (result == DialogResult.Yes)
            {
                var idsToRemove        = selectedBooks.Select(rge => rge.AudibleProductId).ToList();
                var removeLibraryBooks = await LibraryCommands.RemoveBooksAsync(idsToRemove);

                foreach (var rEntry in selectedBooks)
                {
                    _removableGridEntries.Remove(rEntry);
                }

                UpdateSelection();
            }
        }
Beispiel #4
0
        private async void IndexLibraryDialog_Shown(object sender, EventArgs e)
        {
            if (_accounts != null && _accounts.Length > 0)
            {
                this.label1.Text
                    = (_accounts.Length == 1)
                                        ? "Scanning Audible library. This may take a few minutes."
                                        : $"Scanning Audible library: {_accounts.Length} accounts. This may take a few minutes per account.";

                try
                {
                    (TotalBooksProcessed, NewBooksAdded) = await LibraryCommands.ImportAccountAsync((account) => new WinformResponder(account), _accounts);
                }
                catch (Exception ex)
                {
                    var msg = "Error importing library. Please try again. If this still happens after 2 or 3 tries, stop and contact administrator";
                    Serilog.Log.Logger.Error(ex, msg);
                    MessageBox.Show(msg, "Error importing library", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            this.Close();
        }
Beispiel #5
0
        private async void IndexLibraryDialog_Shown(object sender, EventArgs e)
        {
            if (_accounts != null && _accounts.Length > 0)
            {
                this.label1.Text
                    = (_accounts.Length == 1)
                                        ? "Scanning Audible library. This may take a few minutes."
                                        : $"Scanning Audible library: {_accounts.Length} accounts. This may take a few minutes per account.";

                try
                {
                    (TotalBooksProcessed, NewBooksAdded) = await LibraryCommands.ImportAccountAsync((account) => ApiExtended.CreateAsync(account, new WinformLoginChoiceEager(account)), _accounts);
                }
                catch (Exception ex)
                {
                    MessageBoxAlertAdmin.Show(
                        "Error importing library. Please try again. If this still happens after 2 or 3 tries, stop and contact administrator",
                        "Error importing library",
                        ex);
                }
            }

            this.Close();
        }
Beispiel #6
0
        private async void RemoveBooksDialog_Shown(object sender, EventArgs e)
        {
            if (_accounts == null || _accounts.Length == 0)
            {
                return;
            }
            try
            {
                var removedBooks = await LibraryCommands.FindInactiveBooks((account) => ApiExtended.CreateAsync(account, new WinformLoginChoiceEager(account)), _libraryBooks, _accounts);

                var removable = _removableGridEntries.Where(rge => removedBooks.Any(rb => rb.Book.AudibleProductId == rge.AudibleProductId)).ToList();

                if (!removable.Any())
                {
                    return;
                }

                foreach (var r in removable)
                {
                    r.Remove = true;
                }

                UpdateSelection();
            }
            catch (Exception ex)
            {
                MessageBoxAlertAdmin.Show(
                    "Error scanning library. You may still manually select books to remove from Libation's library.",
                    "Error scanning library",
                    ex);
            }
            finally
            {
                _dataGridView.Enabled = true;
            }
        }