diff --git a/Source/LibationWinForms/BookLiberation/AudioConvertForm.cs b/Source/LibationWinForms/BookLiberation/AudioConvertForm.cs deleted file mode 100644 index 2fe1c398..00000000 --- a/Source/LibationWinForms/BookLiberation/AudioConvertForm.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using DataLayer; -using LibationFileManager; - -namespace LibationWinForms.BookLiberation -{ - class AudioConvertForm : AudioDecodeForm - { - public AudioConvertForm() - { - this.Load += (_, _) => this.RestoreSizeAndLocation(Configuration.Instance); - this.FormClosing += (_, _) => this.SaveSizeAndLocation(Configuration.Instance); - } - - #region AudioDecodeForm overrides - public override string DecodeActionName => "Converting"; - #endregion - - #region Processable event handler overrides - public override void Processable_Begin(object sender, LibraryBook libraryBook) - { - LogMe.Info($"Convert Step, Begin: {libraryBook.Book}"); - - base.Processable_Begin(sender, libraryBook); - } - public override void Processable_Completed(object sender, LibraryBook libraryBook) - { - base.Processable_Completed(sender, libraryBook); - LogMe.Info($"Convert Step, Completed: {libraryBook.Book}{Environment.NewLine}"); - } - - #endregion - } -} diff --git a/Source/LibationWinForms/BookLiberation/AudioConvertForm.resx b/Source/LibationWinForms/BookLiberation/AudioConvertForm.resx deleted file mode 100644 index e8ae276d..00000000 --- a/Source/LibationWinForms/BookLiberation/AudioConvertForm.resx +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/Source/LibationWinForms/BookLiberation/AudioDecodeForm.Designer.cs b/Source/LibationWinForms/BookLiberation/AudioDecodeForm.Designer.cs deleted file mode 100644 index b16425dd..00000000 --- a/Source/LibationWinForms/BookLiberation/AudioDecodeForm.Designer.cs +++ /dev/null @@ -1,104 +0,0 @@ -namespace LibationWinForms.BookLiberation -{ - partial class AudioDecodeForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.pictureBox1 = new System.Windows.Forms.PictureBox(); - this.bookInfoLbl = new System.Windows.Forms.Label(); - this.progressBar1 = new System.Windows.Forms.ProgressBar(); - this.remainingTimeLbl = new System.Windows.Forms.Label(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); - this.SuspendLayout(); - // - // pictureBox1 - // - this.pictureBox1.Location = new System.Drawing.Point(14, 14); - this.pictureBox1.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.pictureBox1.Name = "pictureBox1"; - this.pictureBox1.Size = new System.Drawing.Size(117, 115); - this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; - this.pictureBox1.TabIndex = 0; - this.pictureBox1.TabStop = false; - // - // bookInfoLbl - // - this.bookInfoLbl.AutoSize = true; - this.bookInfoLbl.Location = new System.Drawing.Point(138, 14); - this.bookInfoLbl.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.bookInfoLbl.Name = "bookInfoLbl"; - this.bookInfoLbl.Size = new System.Drawing.Size(121, 15); - this.bookInfoLbl.TabIndex = 0; - this.bookInfoLbl.Text = "[multi-line book info]"; - // - // progressBar1 - // - this.progressBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.progressBar1.Location = new System.Drawing.Point(14, 143); - this.progressBar1.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.progressBar1.Name = "progressBar1"; - this.progressBar1.Size = new System.Drawing.Size(611, 27); - this.progressBar1.TabIndex = 2; - // - // remainingTimeLbl - // - this.remainingTimeLbl.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.remainingTimeLbl.Location = new System.Drawing.Point(632, 143); - this.remainingTimeLbl.Name = "remainingTimeLbl"; - this.remainingTimeLbl.Size = new System.Drawing.Size(60, 31); - this.remainingTimeLbl.TabIndex = 3; - this.remainingTimeLbl.Text = "ETA:\r\n"; - this.remainingTimeLbl.TextAlign = System.Drawing.ContentAlignment.TopRight; - // - // DecryptForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(707, 183); - this.Controls.Add(this.remainingTimeLbl); - this.Controls.Add(this.progressBar1); - this.Controls.Add(this.bookInfoLbl); - this.Controls.Add(this.pictureBox1); - this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.Name = "DecryptForm"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "DecryptForm"; - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.PictureBox pictureBox1; - private System.Windows.Forms.Label bookInfoLbl; - private System.Windows.Forms.ProgressBar progressBar1; - private System.Windows.Forms.Label remainingTimeLbl; - } -} \ No newline at end of file diff --git a/Source/LibationWinForms/BookLiberation/AudioDecodeForm.cs b/Source/LibationWinForms/BookLiberation/AudioDecodeForm.cs deleted file mode 100644 index 73d43562..00000000 --- a/Source/LibationWinForms/BookLiberation/AudioDecodeForm.cs +++ /dev/null @@ -1,114 +0,0 @@ -using System; -using DataLayer; -using Dinah.Core.Net.Http; -using Dinah.Core.Threading; -using LibationFileManager; -using LibationWinForms.BookLiberation.BaseForms; - -namespace LibationWinForms.BookLiberation -{ - public partial class AudioDecodeForm : LiberationBaseForm - { - public virtual string DecodeActionName { get; } = "Decoding"; - public AudioDecodeForm() => InitializeComponent(); - - private Func GetCoverArtDelegate; - - #region Processable event handler overrides - public override void Processable_Begin(object sender, LibraryBook libraryBook) - { - base.Processable_Begin(sender, libraryBook); - - GetCoverArtDelegate = () => PictureStorage.GetPictureSynchronously( - new PictureDefinition( - libraryBook.Book.PictureId, - PictureSize._500x500)); - - //Set default values from library - AudioDecodable_TitleDiscovered(sender, libraryBook.Book.Title); - AudioDecodable_AuthorsDiscovered(sender, libraryBook.Book.AuthorNames()); - AudioDecodable_NarratorsDiscovered(sender, libraryBook.Book.NarratorNames()); - AudioDecodable_CoverImageDiscovered(sender, - PictureStorage.GetPicture( - new PictureDefinition( - libraryBook.Book.PictureId, - PictureSize._80x80)).bytes); - } - #endregion - - #region Streamable event handler overrides - public override void Streamable_StreamingProgressChanged(object sender, DownloadProgress downloadProgress) - { - base.Streamable_StreamingProgressChanged(sender, downloadProgress); - if (!downloadProgress.ProgressPercentage.HasValue) - return; - - if (downloadProgress.ProgressPercentage == 0) - updateRemainingTime(0); - else - progressBar1.UIThreadAsync(() => progressBar1.Value = (int)downloadProgress.ProgressPercentage); - } - - public override void Streamable_StreamingTimeRemaining(object sender, TimeSpan timeRemaining) - { - base.Streamable_StreamingTimeRemaining(sender, timeRemaining); - updateRemainingTime((int)timeRemaining.TotalSeconds); - } - - private void updateRemainingTime(int remaining) - => remainingTimeLbl.UIThreadAsync(() => remainingTimeLbl.Text = $"ETA:\r\n{formatTime(remaining)}"); - - private string formatTime(int seconds) - { - var timeSpan = new TimeSpan(0, 0, seconds); - return - timeSpan.TotalHours >= 1 ? $"{timeSpan:%h}h {timeSpan:mm}m {timeSpan:ss}s" - : timeSpan.TotalMinutes >= 1 ? $"{timeSpan:%m}m {timeSpan:ss}s" - : $"{seconds} sec"; - } - #endregion - - #region AudioDecodable event handlers - private string title; - private string authorNames; - private string narratorNames; - - public override void AudioDecodable_TitleDiscovered(object sender, string title) - { - base.AudioDecodable_TitleDiscovered(sender, title); - this.UIThreadAsync(() => this.Text = DecodeActionName + " " + title); - this.title = title; - updateBookInfo(); - } - - public override void AudioDecodable_AuthorsDiscovered(object sender, string authors) - { - base.AudioDecodable_AuthorsDiscovered(sender, authors); - authorNames = authors; - updateBookInfo(); - } - - public override void AudioDecodable_NarratorsDiscovered(object sender, string narrators) - { - base.AudioDecodable_NarratorsDiscovered(sender, narrators); - narratorNames = narrators; - updateBookInfo(); - } - - private void updateBookInfo() - => bookInfoLbl.UIThreadAsync(() => bookInfoLbl.Text = $"{title}\r\nBy {authorNames}\r\nNarrated by {narratorNames}"); - - public override void AudioDecodable_RequestCoverArt(object sender, Action setCoverArtDelegate) - { - base.AudioDecodable_RequestCoverArt(sender, setCoverArtDelegate); - setCoverArtDelegate(GetCoverArtDelegate?.Invoke()); - } - - public override void AudioDecodable_CoverImageDiscovered(object sender, byte[] coverArt) - { - base.AudioDecodable_CoverImageDiscovered(sender, coverArt); - pictureBox1.UIThreadAsync(() => pictureBox1.Image = Dinah.Core.Drawing.ImageReader.ToImage(coverArt)); - } - #endregion - } -} diff --git a/Source/LibationWinForms/BookLiberation/AudioDecodeForm.resx b/Source/LibationWinForms/BookLiberation/AudioDecodeForm.resx deleted file mode 100644 index e8ae276d..00000000 --- a/Source/LibationWinForms/BookLiberation/AudioDecodeForm.resx +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/Source/LibationWinForms/BookLiberation/AudioDecryptForm.cs b/Source/LibationWinForms/BookLiberation/AudioDecryptForm.cs deleted file mode 100644 index e7af1981..00000000 --- a/Source/LibationWinForms/BookLiberation/AudioDecryptForm.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using DataLayer; -using LibationFileManager; - -namespace LibationWinForms.BookLiberation -{ - class AudioDecryptForm : AudioDecodeForm - { - public AudioDecryptForm() - { - this.Load += (_, _) => this.RestoreSizeAndLocation(Configuration.Instance); - this.FormClosing += (_, _) => this.SaveSizeAndLocation(Configuration.Instance); - } - - #region AudioDecodeForm overrides - public override string DecodeActionName => "Decrypting"; - #endregion - - #region Processable event handler overrides - public override void Processable_Begin(object sender, LibraryBook libraryBook) - { - LogMe.Info($"Download & Decrypt Step, Begin: {libraryBook.Book}"); - - base.Processable_Begin(sender, libraryBook); - } - public override void Processable_Completed(object sender, LibraryBook libraryBook) - { - base.Processable_Completed(sender, libraryBook); - LogMe.Info($"Download & Decrypt Step, Completed: {libraryBook.Book}{Environment.NewLine}"); - } - - #endregion - } -} diff --git a/Source/LibationWinForms/BookLiberation/AudioDecryptForm.resx b/Source/LibationWinForms/BookLiberation/AudioDecryptForm.resx deleted file mode 100644 index e8ae276d..00000000 --- a/Source/LibationWinForms/BookLiberation/AudioDecryptForm.resx +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/Source/LibationWinForms/BookLiberation/AutomatedBackupsForm.Designer.cs b/Source/LibationWinForms/BookLiberation/AutomatedBackupsForm.Designer.cs deleted file mode 100644 index 606fabef..00000000 --- a/Source/LibationWinForms/BookLiberation/AutomatedBackupsForm.Designer.cs +++ /dev/null @@ -1,93 +0,0 @@ -namespace LibationWinForms.BookLiberation -{ - partial class AutomatedBackupsForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.keepGoingCb = new System.Windows.Forms.CheckBox(); - this.logTb = new System.Windows.Forms.TextBox(); - this.label1 = new System.Windows.Forms.Label(); - this.SuspendLayout(); - // - // keepGoingCb - // - this.keepGoingCb.AutoSize = true; - this.keepGoingCb.Checked = true; - this.keepGoingCb.CheckState = System.Windows.Forms.CheckState.Checked; - this.keepGoingCb.Location = new System.Drawing.Point(12, 12); - this.keepGoingCb.Name = "keepGoingCb"; - this.keepGoingCb.Size = new System.Drawing.Size(325, 17); - this.keepGoingCb.TabIndex = 0; - this.keepGoingCb.Text = "Keep going. Uncheck to stop when current backup is complete"; - this.keepGoingCb.UseVisualStyleBackColor = true; - // - // logTb - // - this.logTb.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.logTb.Location = new System.Drawing.Point(12, 48); - this.logTb.Multiline = true; - this.logTb.Name = "logTb"; - this.logTb.ReadOnly = true; - this.logTb.ScrollBars = System.Windows.Forms.ScrollBars.Both; - this.logTb.Size = new System.Drawing.Size(960, 202); - this.logTb.TabIndex = 1; - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(9, 32); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(501, 13); - this.label1.TabIndex = 2; - this.label1.Text = "NOTE: if the working directories are inside of Dropbox, some book liberation acti" + - "ons may hang indefinitely"; - // - // AutomatedBackupsForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(984, 262); - this.Controls.Add(this.label1); - this.Controls.Add(this.logTb); - this.Controls.Add(this.keepGoingCb); - this.Name = "AutomatedBackupsForm"; - this.Text = "Automated Backups"; - this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.AutomatedBackupsForm_FormClosing); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.CheckBox keepGoingCb; - private System.Windows.Forms.TextBox logTb; - private System.Windows.Forms.Label label1; - } -} \ No newline at end of file diff --git a/Source/LibationWinForms/BookLiberation/AutomatedBackupsForm.cs b/Source/LibationWinForms/BookLiberation/AutomatedBackupsForm.cs deleted file mode 100644 index a020ecb0..00000000 --- a/Source/LibationWinForms/BookLiberation/AutomatedBackupsForm.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Windows.Forms; -using Dinah.Core.Threading; - -namespace LibationWinForms.BookLiberation -{ - public interface ILogForm - { - void WriteLine(string text); - } - public partial class AutomatedBackupsForm : Form, ILogForm - { - public bool KeepGoingChecked => keepGoingCb.Checked; - - public bool KeepGoing => keepGoingCb.Enabled && keepGoingCb.Checked; - - public AutomatedBackupsForm() - { - InitializeComponent(); - } - - public void WriteLine(string text) - { - if (!IsDisposed) - logTb.UIThreadAsync(() => logTb.AppendText($"{DateTime.Now} {text}{Environment.NewLine}")); - } - - public void FinalizeUI() - { - keepGoingCb.Enabled = false; - - if (!IsDisposed) - logTb.AppendText(""); - } - - private void AutomatedBackupsForm_FormClosing(object sender, FormClosingEventArgs e) => keepGoingCb.Checked = false; - } -} diff --git a/Source/LibationWinForms/BookLiberation/AutomatedBackupsForm.resx b/Source/LibationWinForms/BookLiberation/AutomatedBackupsForm.resx deleted file mode 100644 index e8ae276d..00000000 --- a/Source/LibationWinForms/BookLiberation/AutomatedBackupsForm.resx +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/Source/LibationWinForms/BookLiberation/ILogForm.cs b/Source/LibationWinForms/BookLiberation/ILogForm.cs new file mode 100644 index 00000000..ae3b27e6 --- /dev/null +++ b/Source/LibationWinForms/BookLiberation/ILogForm.cs @@ -0,0 +1,9 @@ +using System; + +namespace LibationWinForms.BookLiberation +{ + public interface ILogForm + { + void WriteLine(string text); + } +} diff --git a/Source/LibationWinForms/BookLiberation/PdfDownloadForm.cs b/Source/LibationWinForms/BookLiberation/PdfDownloadForm.cs deleted file mode 100644 index 017bb3f4..00000000 --- a/Source/LibationWinForms/BookLiberation/PdfDownloadForm.cs +++ /dev/null @@ -1,18 +0,0 @@ -using DataLayer; - -namespace LibationWinForms.BookLiberation -{ - internal class PdfDownloadForm : DownloadForm - { - public override void Processable_Begin(object sender, LibraryBook libraryBook) - { - base.Processable_Begin(sender, libraryBook); - LogMe.Info($"PDF Step, Begin: {libraryBook.Book}"); - } - public override void Processable_Completed(object sender, LibraryBook libraryBook) - { - base.Processable_Completed(sender, libraryBook); - LogMe.Info($"PDF Step, Completed: {libraryBook.Book}"); - } - } -} diff --git a/Source/LibationWinForms/BookLiberation/PdfDownloadForm.resx b/Source/LibationWinForms/BookLiberation/PdfDownloadForm.resx deleted file mode 100644 index 03e6393f..00000000 --- a/Source/LibationWinForms/BookLiberation/PdfDownloadForm.resx +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/Source/LibationWinForms/BookLiberation/ProcessorAutomationController.cs b/Source/LibationWinForms/BookLiberation/ProcessorAutomationController.cs index 38a185c3..87917db0 100644 --- a/Source/LibationWinForms/BookLiberation/ProcessorAutomationController.cs +++ b/Source/LibationWinForms/BookLiberation/ProcessorAutomationController.cs @@ -3,11 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; -using DataLayer; -using Dinah.Core; using FileLiberator; -using LibationFileManager; -using LibationWinForms.BookLiberation.BaseForms; namespace LibationWinForms.BookLiberation { @@ -25,7 +21,6 @@ namespace LibationWinForms.BookLiberation LogError += (_, tuple) => Serilog.Log.Logger.Error(tuple.Item1, tuple.Item2 ?? "Automated backup: error"); } - public static LogMe RegisterForm() => RegisterForm(null); public static LogMe RegisterForm(T form) where T : ILogForm { var logMe = new LogMe(); @@ -53,66 +48,6 @@ namespace LibationWinForms.BookLiberation public static class ProcessorAutomationController { - public static async Task BackupSingleBookAsync(LibraryBook libraryBook) - { - Serilog.Log.Logger.Information($"Begin {nameof(BackupSingleBookAsync)} {{@DebugInfo}}", new { libraryBook?.Book?.AudibleProductId }); - - var logMe = LogMe.RegisterForm(); - var backupBook = CreateBackupBook(logMe); - - // continue even if libraryBook is null. we'll display even that in the processing box - await new BackupSingle(logMe, backupBook, libraryBook).RunBackupAsync(); - } - - public static async Task BackupAllBooksAsync(List libraryBooks = null) - { - Serilog.Log.Logger.Information("Begin " + nameof(BackupAllBooksAsync)); - - var automatedBackupsForm = new AutomatedBackupsForm(); - var logMe = LogMe.RegisterForm(automatedBackupsForm); - var backupBook = CreateBackupBook(logMe); - - await new BackupLoop(logMe, backupBook, automatedBackupsForm, libraryBooks).RunBackupAsync(); - } - - public static async Task ConvertAllBooksAsync() - { - Serilog.Log.Logger.Information("Begin " + nameof(ConvertAllBooksAsync)); - - var automatedBackupsForm = new AutomatedBackupsForm(); - var logMe = LogMe.RegisterForm(automatedBackupsForm); - - var convertBook = CreateProcessable(logMe); - - await new BackupLoop(logMe, convertBook, automatedBackupsForm).RunBackupAsync(); - } - - public static async Task BackupAllPdfsAsync() - { - Serilog.Log.Logger.Information("Begin " + nameof(BackupAllPdfsAsync)); - - var automatedBackupsForm = new AutomatedBackupsForm(); - var logMe = LogMe.RegisterForm(automatedBackupsForm); - - var downloadPdf = CreateProcessable(logMe); - - await new BackupLoop(logMe, downloadPdf, automatedBackupsForm).RunBackupAsync(); - } - - private static Processable CreateBackupBook(LogMe logMe) - { - var downloadPdf = CreateProcessable(logMe); - - //Chain pdf download on DownloadDecryptBook.Completed - async void onDownloadDecryptBookCompleted(object sender, LibraryBook e) - { - await downloadPdf.TryProcessAsync(e); - } - - var downloadDecryptBook = CreateProcessable(logMe, onDownloadDecryptBookCompleted); - return downloadDecryptBook; - } - public static void DownloadFile(string url, string destination, bool showDownloadCompletedDialog = false) { Serilog.Log.Logger.Information($"Begin {nameof(DownloadFile)} for {url}"); @@ -133,212 +68,5 @@ namespace LibationWinForms.BookLiberation async void runDownload() => await downloadFile.PerformDownloadFileAsync(url, destination); new Task(runDownload).Start(); } - - /// - /// Create a new and links it to a new . - /// - /// The derived type to create. - /// The derived Form to create on , Show on , Close on , and Dispose on - /// The logger - /// An additional event handler to handle - /// A new of type - private static TProcessable CreateProcessable(LogMe logMe, EventHandler completedAction = null) - where TForm : LiberationBaseForm, new() - where TProcessable : Processable, new() - { - var strProc = new TProcessable(); - - strProc.Begin += (sender, libraryBook) => - { - var processForm = new TForm(); - processForm.RegisterFileLiberator(strProc, logMe); - processForm.Processable_Begin(sender, libraryBook); - }; - - strProc.Completed += completedAction; - - return strProc; - } - } - - internal abstract class BackupRunner - { - protected LogMe LogMe { get; } - protected Processable Processable { get; } - protected AutomatedBackupsForm AutomatedBackupsForm { get; } - - protected BackupRunner(LogMe logMe, Processable processable, AutomatedBackupsForm automatedBackupsForm = null) - { - LogMe = logMe; - Processable = processable; - AutomatedBackupsForm = automatedBackupsForm; - } - - protected abstract Task RunAsync(); - protected abstract string SkipDialogText { get; } - protected abstract MessageBoxButtons SkipDialogButtons { get; } - protected abstract MessageBoxDefaultButton SkipDialogDefaultButton { get; } - protected abstract DialogResult SkipResult { get; } - - public async Task RunBackupAsync() - { - AutomatedBackupsForm?.Show(); - - try - { - await RunAsync(); - } - catch (Exception ex) - { - LogMe.Error(ex); - } - - AutomatedBackupsForm?.FinalizeUI(); - LogMe.Info("DONE"); - } - - protected async Task ProcessOneAsync(LibraryBook libraryBook, bool validate) - { - try - { - var statusHandler = await Processable.ProcessSingleAsync(libraryBook, validate); - - if (statusHandler.IsSuccess) - return true; - - foreach (var errorMessage in statusHandler.Errors) - LogMe.Error(errorMessage); - } - catch (Exception ex) - { - LogMe.Error(ex); - } - - return showRetry(libraryBook); - } - - private bool showRetry(LibraryBook libraryBook) - { - LogMe.Error("ERROR. All books have not been processed. Most recent book: processing failed"); - - DialogResult? dialogResult = Configuration.Instance.BadBook switch - { - Configuration.BadBookAction.Abort => DialogResult.Abort, - Configuration.BadBookAction.Retry => DialogResult.Retry, - Configuration.BadBookAction.Ignore => DialogResult.Ignore, - Configuration.BadBookAction.Ask => null, - _ => null - }; - - string details; - try - { - static string trunc(string str) - => string.IsNullOrWhiteSpace(str) ? "[empty]" - : (str.Length > 50) ? $"{str.Truncate(47)}..." - : str; - - details = -$@" Title: {libraryBook.Book.Title} - ID: {libraryBook.Book.AudibleProductId} - Author: {trunc(libraryBook.Book.AuthorNames())} - Narr: {trunc(libraryBook.Book.NarratorNames())}"; - } - catch - { - details = "[Error retrieving details]"; - } - - // if null then ask user - dialogResult ??= MessageBox.Show(string.Format(SkipDialogText + "\r\n\r\nSee Settings to avoid this box in the future.", details), "Skip importing this book?", SkipDialogButtons, MessageBoxIcon.Question, SkipDialogDefaultButton); - - if (dialogResult == DialogResult.Abort) - return false; - - if (dialogResult == SkipResult) - { - libraryBook.Book.UserDefinedItem.BookStatus = LiberatedStatus.Error; - ApplicationServices.LibraryCommands.UpdateUserDefinedItem(libraryBook.Book); - - LogMe.Info($"Error. Skip: [{libraryBook.Book.AudibleProductId}] {libraryBook.Book.Title}"); - } - - return true; - } - } - - internal class BackupSingle : BackupRunner - { - private LibraryBook _libraryBook { get; } - - protected override string SkipDialogText => @" -An error occurred while trying to process this book. Skip this book permanently? -{0} - -- Click YES to skip this book permanently. - -- Click NO to skip the book this time only. We'll try again later. -".Trim(); - protected override MessageBoxButtons SkipDialogButtons => MessageBoxButtons.YesNo; - protected override MessageBoxDefaultButton SkipDialogDefaultButton => MessageBoxDefaultButton.Button2; - protected override DialogResult SkipResult => DialogResult.Yes; - - public BackupSingle(LogMe logMe, Processable processable, LibraryBook libraryBook) - : base(logMe, processable) - { - _libraryBook = libraryBook; - } - - protected override async Task RunAsync() - { - if (_libraryBook is not null) - await ProcessOneAsync(_libraryBook, validate: true); - } - } - - internal class BackupLoop : BackupRunner - { - protected override string SkipDialogText => @" -An error occurred while trying to process this book. -{0} - -- ABORT: Stop processing books. - -- RETRY: retry this book later. Just skip it for now. Continue processing books. (Will try this book again later.) - -- IGNORE: Permanently ignore this book. Continue processing books. (Will not try this book again later.) -".Trim(); - protected override MessageBoxButtons SkipDialogButtons => MessageBoxButtons.AbortRetryIgnore; - protected override MessageBoxDefaultButton SkipDialogDefaultButton => MessageBoxDefaultButton.Button1; - protected override DialogResult SkipResult => DialogResult.Ignore; - - private List libraryBooks { get; } - - public BackupLoop(LogMe logMe, Processable processable, AutomatedBackupsForm automatedBackupsForm, List libraryBooks = null) - : base(logMe, processable, automatedBackupsForm) - => this.libraryBooks = libraryBooks ?? ApplicationServices.DbContexts.GetLibrary_Flat_NoTracking(); - - protected override async Task RunAsync() - { - // support for 'skip this time only' requires state. iterators provide this state for free. therefore: use foreach/iterator here - foreach (var libraryBook in Processable.GetValidLibraryBooks(libraryBooks)) - { - var keepGoing = await ProcessOneAsync(libraryBook, validate: false); - if (!keepGoing) - return; - - if (AutomatedBackupsForm.IsDisposed) - break; - - if (!AutomatedBackupsForm.KeepGoing) - { - if (!AutomatedBackupsForm.KeepGoingChecked) - LogMe.Info("'Keep going' is unchecked"); - return; - } - } - - LogMe.Info("Done. All books have been processed"); - } } } diff --git a/Source/LibationWinForms/grid/GridEntry.cs b/Source/LibationWinForms/grid/GridEntry.cs index 0d20ef1f..7040316c 100644 --- a/Source/LibationWinForms/grid/GridEntry.cs +++ b/Source/LibationWinForms/grid/GridEntry.cs @@ -46,7 +46,6 @@ namespace LibationWinForms } } - public bool DownloadInProgress { get; private set; } public string ProductRating { get; private set; } public string PurchaseDate { get; private set; } public string MyRating { get; private set; } @@ -68,7 +67,8 @@ namespace LibationWinForms //Cache these statuses for faster sorting. if ((DateTime.Now - lastStatusUpdate).TotalSeconds > 2) { - UpdateLiberatedStatus(notify: false); + _bookStatus = LibraryCommands.Liberated_Status(LibraryBook.Book); + _pdfStatus = LibraryCommands.Pdf_Status(LibraryBook.Book); lastStatusUpdate = DateTime.Now; } return (_bookStatus, _pdfStatus); @@ -84,23 +84,6 @@ namespace LibationWinForms public GridEntry(LibraryBook libraryBook) => setLibraryBook(libraryBook); - public async Task DownloadBook() - { - if (DownloadInProgress) - return; - - try - { - DownloadInProgress = true; - await BookLiberation.ProcessorAutomationController.BackupSingleBookAsync(LibraryBook); - UpdateLiberatedStatus(); - } - finally - { - DownloadInProgress = false; - } - } - public void UpdateLibraryBook(LibraryBook libraryBook) { if (AudibleProductId != libraryBook.Book.AudibleProductId) @@ -209,14 +192,6 @@ namespace LibationWinForms Committed?.Invoke(this, null); } - private void UpdateLiberatedStatus(bool notify = true) - { - _bookStatus = LibraryCommands.Liberated_Status(LibraryBook.Book); - _pdfStatus = LibraryCommands.Pdf_Status(LibraryBook.Book); - if (notify) - NotifyPropertyChanged(nameof(Liberate)); - } - #endregion #region Data Sorting