diff --git a/FileLiberator/AudioDecodable.cs b/FileLiberator/AudioDecodable.cs new file mode 100644 index 00000000..ae91fc52 --- /dev/null +++ b/FileLiberator/AudioDecodable.cs @@ -0,0 +1,40 @@ +using System; + +namespace FileLiberator +{ + public abstract class AudioDecodable : Processable + { + public event EventHandler> RequestCoverArt; + public event EventHandler TitleDiscovered; + public event EventHandler AuthorsDiscovered; + public event EventHandler NarratorsDiscovered; + public event EventHandler CoverImageDiscovered; + public abstract void Cancel(); + + public void OnRequestCoverArt(Action setCoverArtDel) + { + Serilog.Log.Logger.Debug("Event fired {@DebugInfo}", new { Name = nameof(RequestCoverArt) }); + RequestCoverArt?.Invoke(this, setCoverArtDel); + } + public void OnTitleDiscovered(string title) + { + Serilog.Log.Logger.Debug("Event fired {@DebugInfo}", new { Name = nameof(TitleDiscovered), Title = title }); + TitleDiscovered?.Invoke(this, title); + } + public void OnAuthorsDiscovered(string authors) + { + Serilog.Log.Logger.Debug("Event fired {@DebugInfo}", new { Name = nameof(AuthorsDiscovered), Authors = authors }); + AuthorsDiscovered?.Invoke(this, authors); + } + public void OnNarratorsDiscovered(string narrators) + { + Serilog.Log.Logger.Debug("Event fired {@DebugInfo}", new { Name = nameof(NarratorsDiscovered), Narrators = narrators }); + NarratorsDiscovered?.Invoke(this, narrators); + } + public void OnCoverImageDiscovered(byte[] coverImage) + { + Serilog.Log.Logger.Debug("Event fired {@DebugInfo}", new { Name = nameof(CoverImageDiscovered), CoverImageBytes = coverImage?.Length }); + CoverImageDiscovered?.Invoke(this, coverImage); + } + } +} diff --git a/FileLiberator/ConvertToMp3.cs b/FileLiberator/ConvertToMp3.cs index 10465727..c30222ea 100644 --- a/FileLiberator/ConvertToMp3.cs +++ b/FileLiberator/ConvertToMp3.cs @@ -12,20 +12,14 @@ using System.Threading.Tasks; namespace FileLiberator { - public class ConvertToMp3 : Processable, IAudioDecodable + public class ConvertToMp3 : AudioDecodable { private Mp4File m4bBook; - public event EventHandler> RequestCoverArt; - public event EventHandler TitleDiscovered; - public event EventHandler AuthorsDiscovered; - public event EventHandler NarratorsDiscovered; - public event EventHandler CoverImageDiscovered; - private long fileSize; private string Mp3FileName(string m4bPath) => m4bPath is null ? string.Empty : PathLib.ReplaceExtension(m4bPath, ".mp3"); - public void Cancel() => m4bBook?.Cancel(); + public override void Cancel() => m4bBook?.Cancel(); public override bool Validate(LibraryBook libraryBook) { @@ -47,10 +41,10 @@ namespace FileLiberator fileSize = m4bBook.InputStream.Length; - TitleDiscovered?.Invoke(this, m4bBook.AppleTags.Title); - AuthorsDiscovered?.Invoke(this, m4bBook.AppleTags.FirstAuthor); - NarratorsDiscovered?.Invoke(this, m4bBook.AppleTags.Narrator); - CoverImageDiscovered?.Invoke(this, m4bBook.AppleTags.Cover); + OnTitleDiscovered(m4bBook.AppleTags.Title); + OnAuthorsDiscovered(m4bBook.AppleTags.FirstAuthor); + OnNarratorsDiscovered(m4bBook.AppleTags.Narrator); + OnCoverImageDiscovered(m4bBook.AppleTags.Cover); using var mp3File = File.OpenWrite(Path.GetTempFileName()); diff --git a/FileLiberator/DownloadDecryptBook.cs b/FileLiberator/DownloadDecryptBook.cs index c1b3f619..86178c68 100644 --- a/FileLiberator/DownloadDecryptBook.cs +++ b/FileLiberator/DownloadDecryptBook.cs @@ -8,21 +8,14 @@ using AudibleApi; using DataLayer; using Dinah.Core; using Dinah.Core.ErrorHandling; -using Dinah.Core.Net.Http; using FileManager; namespace FileLiberator { - public class DownloadDecryptBook : Processable, IAudioDecodable + public class DownloadDecryptBook : AudioDecodable { private AudiobookDownloadBase aaxcDownloader; - public event EventHandler> RequestCoverArt; - public event EventHandler TitleDiscovered; - public event EventHandler AuthorsDiscovered; - public event EventHandler NarratorsDiscovered; - public event EventHandler CoverImageDiscovered; - public override async Task ProcessAsync(LibraryBook libraryBook) { OnBegin(libraryBook); @@ -96,9 +89,9 @@ namespace FileLiberator : new UnencryptedAudiobookDownloader(outFileName, cacheDir, audiobookDlLic); aaxcDownloader.DecryptProgressUpdate += (s, progress) => OnStreamingProgressChanged(progress); aaxcDownloader.DecryptTimeRemaining += (s, remaining) => OnStreamingTimeRemaining(remaining); - aaxcDownloader.RetrievedTitle += (s, title) => TitleDiscovered?.Invoke(this, title); - aaxcDownloader.RetrievedAuthors += (s, authors) => AuthorsDiscovered?.Invoke(this, authors); - aaxcDownloader.RetrievedNarrators += (s, narrators) => NarratorsDiscovered?.Invoke(this, narrators); + aaxcDownloader.RetrievedTitle += (s, title) => OnTitleDiscovered(title); + aaxcDownloader.RetrievedAuthors += (s, authors) => OnAuthorsDiscovered(authors); + aaxcDownloader.RetrievedNarrators += (s, narrators) => OnNarratorsDiscovered(narrators); aaxcDownloader.RetrievedCoverArt += AaxcDownloader_RetrievedCoverArt; // REAL WORK DONE HERE @@ -120,12 +113,12 @@ namespace FileLiberator { if (e is null && Configuration.Instance.AllowLibationFixup) { - RequestCoverArt?.Invoke(this, aaxcDownloader.SetCoverArt); + OnRequestCoverArt(aaxcDownloader.SetCoverArt); } if (e is not null) { - CoverImageDiscovered?.Invoke(this, e); + OnCoverImageDiscovered(e); } } @@ -209,7 +202,7 @@ namespace FileLiberator public override bool Validate(LibraryBook libraryBook) => !libraryBook.Book.Audio_Exists; - public void Cancel() + public override void Cancel() { aaxcDownloader?.Cancel(); } diff --git a/FileLiberator/DownloadFile.cs b/FileLiberator/DownloadFile.cs index 9f23b1e0..c41948e7 100644 --- a/FileLiberator/DownloadFile.cs +++ b/FileLiberator/DownloadFile.cs @@ -6,21 +6,16 @@ using Dinah.Core.Net.Http; namespace FileLiberator { // currently only used to download the .zip flies for upgrade - public class DownloadFile : IStreamable + public class DownloadFile : Streamable { - public event EventHandler StreamingBegin; - public event EventHandler StreamingProgressChanged; - public event EventHandler StreamingCompleted; - public event EventHandler StreamingTimeRemaining; - public async Task PerformDownloadFileAsync(string downloadUrl, string proposedDownloadFilePath) { var client = new HttpClient(); var progress = new Progress(); - progress.ProgressChanged += (_, e) => StreamingProgressChanged?.Invoke(this, e); + progress.ProgressChanged += (_, e) => OnStreamingProgressChanged(e); - StreamingBegin?.Invoke(this, proposedDownloadFilePath); + OnStreamingBegin(proposedDownloadFilePath); try { @@ -29,7 +24,7 @@ namespace FileLiberator } finally { - StreamingCompleted?.Invoke(this, proposedDownloadFilePath); + OnStreamingCompleted(proposedDownloadFilePath); } } } diff --git a/FileLiberator/IAudioDecodable.cs b/FileLiberator/IAudioDecodable.cs deleted file mode 100644 index ff5fc3ed..00000000 --- a/FileLiberator/IAudioDecodable.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace FileLiberator -{ - public interface IAudioDecodable - { - event EventHandler> RequestCoverArt; - event EventHandler TitleDiscovered; - event EventHandler AuthorsDiscovered; - event EventHandler NarratorsDiscovered; - event EventHandler CoverImageDiscovered; - void Cancel(); - } -} diff --git a/FileLiberator/IStreamable.cs b/FileLiberator/IStreamable.cs deleted file mode 100644 index 94049a7a..00000000 --- a/FileLiberator/IStreamable.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using Dinah.Core.Net.Http; - -namespace FileLiberator -{ - public interface IStreamable - { - event EventHandler StreamingBegin; - event EventHandler StreamingProgressChanged; - event EventHandler StreamingTimeRemaining; - event EventHandler StreamingCompleted; - } -} diff --git a/FileLiberator/Processable.cs b/FileLiberator/Processable.cs index e7a68e1f..f971051f 100644 --- a/FileLiberator/Processable.cs +++ b/FileLiberator/Processable.cs @@ -9,7 +9,7 @@ using Dinah.Core.Net.Http; namespace FileLiberator { - public abstract class Processable : IStreamable + public abstract class Processable : Streamable { public event EventHandler Begin; @@ -17,12 +17,6 @@ namespace FileLiberator public event EventHandler StatusUpdate; public event EventHandler Completed; - public event EventHandler StreamingBegin; - public event EventHandler StreamingProgressChanged; - public event EventHandler StreamingTimeRemaining; - public event EventHandler StreamingCompleted; - - // when used in foreach: stateful. deferred execution public IEnumerable GetValidLibraryBooks(IEnumerable library) @@ -64,31 +58,18 @@ namespace FileLiberator public virtual void OnBegin(LibraryBook libraryBook) { + Serilog.Log.Logger.Debug("Event fired {@DebugInfo}", new { Name = nameof(Begin), Book = libraryBook.LogFriendly() }); Begin?.Invoke(this, libraryBook); } public virtual void OnCompleted(LibraryBook libraryBook) { + Serilog.Log.Logger.Debug("Event fired {@DebugInfo}", new { Name = nameof(Completed), Book = libraryBook.LogFriendly() }); Completed?.Invoke(this, libraryBook); } - public virtual void OnStatusUpdate(string status) + public virtual void OnStatusUpdate(string statusUpdate) { - StatusUpdate?.Invoke(this, status); - } - public virtual void OnStreamingBegin(string filePath) - { - StreamingBegin?.Invoke(this, filePath); - } - public virtual void OnStreamingCompleted(string filePath) - { - StreamingCompleted?.Invoke(this, filePath); - } - public virtual void OnStreamingProgressChanged(DownloadProgress progress) - { - StreamingProgressChanged?.Invoke(this, progress); - } - public virtual void OnStreamingTimeRemaining(TimeSpan timeRemaining) - { - StreamingTimeRemaining?.Invoke(this, timeRemaining); + Serilog.Log.Logger.Debug("Event fired {@DebugInfo}", new { Name = nameof(StatusUpdate), Status = statusUpdate }); + StatusUpdate?.Invoke(this, statusUpdate); } } } diff --git a/FileLiberator/Streamable.cs b/FileLiberator/Streamable.cs new file mode 100644 index 00000000..e9d6f121 --- /dev/null +++ b/FileLiberator/Streamable.cs @@ -0,0 +1,31 @@ +using System; +using Dinah.Core.Net.Http; + +namespace FileLiberator +{ + public abstract class Streamable + { + public event EventHandler StreamingBegin; + public event EventHandler StreamingProgressChanged; + public event EventHandler StreamingTimeRemaining; + public event EventHandler StreamingCompleted; + public virtual void OnStreamingBegin(string filePath) + { + Serilog.Log.Logger.Debug("Event fired {@DebugInfo}", new { Name = nameof(StreamingBegin), Message = filePath }); + StreamingBegin?.Invoke(this, filePath); + } + public virtual void OnStreamingCompleted(string filePath) + { + Serilog.Log.Logger.Debug("Event fired {@DebugInfo}", new { Name = nameof(StreamingCompleted), Message = filePath }); + StreamingCompleted?.Invoke(this, filePath); + } + public virtual void OnStreamingProgressChanged(DownloadProgress progress) + { + StreamingProgressChanged?.Invoke(this, progress); + } + public virtual void OnStreamingTimeRemaining(TimeSpan timeRemaining) + { + StreamingTimeRemaining?.Invoke(this, timeRemaining); + } + } +} diff --git a/LibationWinForms/BookLiberation/AudioConvertForm.cs b/LibationWinForms/BookLiberation/AudioConvertForm.cs index 4960cfa3..66c1c0c9 100644 --- a/LibationWinForms/BookLiberation/AudioConvertForm.cs +++ b/LibationWinForms/BookLiberation/AudioConvertForm.cs @@ -17,15 +17,15 @@ namespace LibationWinForms.BookLiberation #endregion #region IProcessable event handler overrides - public override void OnBegin(object sender, LibraryBook libraryBook) + public override void Processable_Begin(object sender, LibraryBook libraryBook) { LogMe.Info($"Convert Step, Begin: {libraryBook.Book}"); - base.OnBegin(sender, libraryBook); + base.Processable_Begin(sender, libraryBook); } - public override void OnCompleted(object sender, LibraryBook libraryBook) + public override void Processable_Completed(object sender, LibraryBook libraryBook) { - base.OnCompleted(sender, libraryBook); + base.Processable_Completed(sender, libraryBook); LogMe.Info($"Convert Step, Completed: {libraryBook.Book}{Environment.NewLine}"); } diff --git a/LibationWinForms/BookLiberation/AudioDecodeForm.cs b/LibationWinForms/BookLiberation/AudioDecodeForm.cs index 3a54f5aa..af9273f5 100644 --- a/LibationWinForms/BookLiberation/AudioDecodeForm.cs +++ b/LibationWinForms/BookLiberation/AudioDecodeForm.cs @@ -19,9 +19,9 @@ namespace LibationWinForms.BookLiberation private string narratorNames; #region IProcessable event handler overrides - public override void OnBegin(object sender, LibraryBook libraryBook) + public override void Processable_Begin(object sender, LibraryBook libraryBook) { - base.OnBegin(sender, libraryBook); + base.Processable_Begin(sender, libraryBook); GetCoverArtDelegate = () => FileManager.PictureStorage.GetPictureSynchronously( new FileManager.PictureDefinition( @@ -29,10 +29,10 @@ namespace LibationWinForms.BookLiberation FileManager.PictureSize._500x500)); //Set default values from library - OnTitleDiscovered(sender, libraryBook.Book.Title); - OnAuthorsDiscovered(sender, string.Join(", ", libraryBook.Book.Authors)); - OnNarratorsDiscovered(sender, string.Join(", ", libraryBook.Book.NarratorNames)); - OnCoverImageDiscovered(sender, + AudioDecodable_TitleDiscovered(sender, libraryBook.Book.Title); + AudioDecodable_AuthorsDiscovered(sender, string.Join(", ", libraryBook.Book.Authors)); + AudioDecodable_NarratorsDiscovered(sender, string.Join(", ", libraryBook.Book.NarratorNames)); + AudioDecodable_CoverImageDiscovered(sender, FileManager.PictureStorage.GetPicture( new FileManager.PictureDefinition( libraryBook.Book.PictureId, @@ -41,9 +41,9 @@ namespace LibationWinForms.BookLiberation #endregion #region IStreamable event handler overrides - public override void OnStreamingProgressChanged(object sender, DownloadProgress downloadProgress) + public override void Streamable_StreamingProgressChanged(object sender, DownloadProgress downloadProgress) { - base.OnStreamingProgressChanged(sender, downloadProgress); + base.Streamable_StreamingProgressChanged(sender, downloadProgress); if (!downloadProgress.ProgressPercentage.HasValue) return; @@ -53,46 +53,46 @@ namespace LibationWinForms.BookLiberation progressBar1.UIThreadAsync(() => progressBar1.Value = (int)downloadProgress.ProgressPercentage); } - public override void OnStreamingTimeRemaining(object sender, TimeSpan timeRemaining) + public override void Streamable_StreamingTimeRemaining(object sender, TimeSpan timeRemaining) { - base.OnStreamingTimeRemaining(sender, timeRemaining); + base.Streamable_StreamingTimeRemaining(sender, timeRemaining); updateRemainingTime((int)timeRemaining.TotalSeconds); } #endregion #region IAudioDecodable event handlers - public override void OnRequestCoverArt(object sender, Action setCoverArtDelegate) + public override void AudioDecodable_RequestCoverArt(object sender, Action setCoverArtDelegate) { - base.OnRequestCoverArt(sender, setCoverArtDelegate); + base.AudioDecodable_RequestCoverArt(sender, setCoverArtDelegate); setCoverArtDelegate(GetCoverArtDelegate?.Invoke()); } - public override void OnTitleDiscovered(object sender, string title) + public override void AudioDecodable_TitleDiscovered(object sender, string title) { - base.OnTitleDiscovered(sender, title); + base.AudioDecodable_TitleDiscovered(sender, title); this.UIThreadAsync(() => this.Text = DecodeActionName + " " + title); this.title = title; updateBookInfo(); } - public override void OnAuthorsDiscovered(object sender, string authors) + public override void AudioDecodable_AuthorsDiscovered(object sender, string authors) { - base.OnAuthorsDiscovered(sender, authors); + base.AudioDecodable_AuthorsDiscovered(sender, authors); authorNames = authors; updateBookInfo(); } - public override void OnNarratorsDiscovered(object sender, string narrators) + public override void AudioDecodable_NarratorsDiscovered(object sender, string narrators) { - base.OnNarratorsDiscovered(sender, narrators); + base.AudioDecodable_NarratorsDiscovered(sender, narrators); narratorNames = narrators; updateBookInfo(); } - public override void OnCoverImageDiscovered(object sender, byte[] coverArt) + public override void AudioDecodable_CoverImageDiscovered(object sender, byte[] coverArt) { - base.OnCoverImageDiscovered(sender, coverArt); + base.AudioDecodable_CoverImageDiscovered(sender, coverArt); pictureBox1.UIThreadAsync(() => pictureBox1.Image = Dinah.Core.Drawing.ImageReader.ToImage(coverArt)); } #endregion diff --git a/LibationWinForms/BookLiberation/AudioDecryptForm.cs b/LibationWinForms/BookLiberation/AudioDecryptForm.cs index 58d8d3ac..753e761b 100644 --- a/LibationWinForms/BookLiberation/AudioDecryptForm.cs +++ b/LibationWinForms/BookLiberation/AudioDecryptForm.cs @@ -17,15 +17,15 @@ namespace LibationWinForms.BookLiberation #endregion #region IProcessable event handler overrides - public override void OnBegin(object sender, LibraryBook libraryBook) + public override void Processable_Begin(object sender, LibraryBook libraryBook) { LogMe.Info($"Download & Decrypt Step, Begin: {libraryBook.Book}"); - base.OnBegin(sender, libraryBook); + base.Processable_Begin(sender, libraryBook); } - public override void OnCompleted(object sender, LibraryBook libraryBook) + public override void Processable_Completed(object sender, LibraryBook libraryBook) { - base.OnCompleted(sender, libraryBook); + base.Processable_Completed(sender, libraryBook); LogMe.Info($"Download & Decrypt Step, Completed: {libraryBook.Book}{Environment.NewLine}"); } diff --git a/LibationWinForms/BookLiberation/BaseForms/LiberationBaseForm.cs b/LibationWinForms/BookLiberation/BaseForms/LiberationBaseForm.cs index 514db24a..d1642852 100644 --- a/LibationWinForms/BookLiberation/BaseForms/LiberationBaseForm.cs +++ b/LibationWinForms/BookLiberation/BaseForms/LiberationBaseForm.cs @@ -9,7 +9,7 @@ namespace LibationWinForms.BookLiberation.BaseForms { public class LiberationBaseForm : Form { - protected IStreamable Streamable { get; private set; } + protected Streamable Streamable { get; private set; } protected LogMe LogMe { get; private set; } private SynchronizeInvoker Invoker { get; init; } @@ -21,7 +21,7 @@ namespace LibationWinForms.BookLiberation.BaseForms Invoker = new SynchronizeInvoker(); } - public void RegisterFileLiberator(IStreamable streamable, LogMe logMe = null) + public void RegisterFileLiberator(Streamable streamable, LogMe logMe = null) { if (streamable is null) return; @@ -32,20 +32,20 @@ namespace LibationWinForms.BookLiberation.BaseForms if (Streamable is Processable processable) Subscribe(processable); - if (Streamable is IAudioDecodable audioDecodable) + if (Streamable is AudioDecodable audioDecodable) Subscribe(audioDecodable); } #region Event Subscribers and Unsubscribers - private void Subscribe(IStreamable streamable) + private void Subscribe(Streamable streamable) { UnsubscribeStreamable(this, EventArgs.Empty); streamable.StreamingBegin += OnStreamingBeginShow; - streamable.StreamingBegin += OnStreamingBegin; - streamable.StreamingProgressChanged += OnStreamingProgressChanged; - streamable.StreamingTimeRemaining += OnStreamingTimeRemaining; - streamable.StreamingCompleted += OnStreamingCompleted; + streamable.StreamingBegin += Streamable_StreamingBegin; + streamable.StreamingProgressChanged += Streamable_StreamingProgressChanged; + streamable.StreamingTimeRemaining += Streamable_StreamingTimeRemaining; + streamable.StreamingCompleted += Streamable_StreamingCompleted; streamable.StreamingCompleted += OnStreamingCompletedClose; Disposed += UnsubscribeStreamable; @@ -54,9 +54,9 @@ namespace LibationWinForms.BookLiberation.BaseForms { UnsubscribeProcessable(this, null); - processable.Begin += OnBegin; - processable.StatusUpdate += OnStatusUpdate; - processable.Completed += OnCompleted; + processable.Begin += Processable_Begin; + processable.StatusUpdate += Processable_StatusUpdate; + processable.Completed += Processable_Completed; //The form is created on IProcessable.Begin and we //dispose of it on IProcessable.Completed @@ -67,15 +67,15 @@ namespace LibationWinForms.BookLiberation.BaseForms //the IProcessable events need to live past that event. processable.Completed += UnsubscribeProcessable; } - private void Subscribe(IAudioDecodable audioDecodable) + private void Subscribe(AudioDecodable audioDecodable) { UnsubscribeAudioDecodable(this, EventArgs.Empty); - audioDecodable.RequestCoverArt += OnRequestCoverArt; - audioDecodable.TitleDiscovered += OnTitleDiscovered; - audioDecodable.AuthorsDiscovered += OnAuthorsDiscovered; - audioDecodable.NarratorsDiscovered += OnNarratorsDiscovered; - audioDecodable.CoverImageDiscovered += OnCoverImageDiscovered; + audioDecodable.RequestCoverArt += AudioDecodable_RequestCoverArt; + audioDecodable.TitleDiscovered += AudioDecodable_TitleDiscovered; + audioDecodable.AuthorsDiscovered += AudioDecodable_AuthorsDiscovered; + audioDecodable.NarratorsDiscovered += AudioDecodable_NarratorsDiscovered; + audioDecodable.CoverImageDiscovered += AudioDecodable_CoverImageDiscovered; Disposed += UnsubscribeAudioDecodable; } @@ -84,10 +84,10 @@ namespace LibationWinForms.BookLiberation.BaseForms Disposed -= UnsubscribeStreamable; Streamable.StreamingBegin -= OnStreamingBeginShow; - Streamable.StreamingBegin -= OnStreamingBegin; - Streamable.StreamingProgressChanged -= OnStreamingProgressChanged; - Streamable.StreamingTimeRemaining -= OnStreamingTimeRemaining; - Streamable.StreamingCompleted -= OnStreamingCompleted; + Streamable.StreamingBegin -= Streamable_StreamingBegin; + Streamable.StreamingProgressChanged -= Streamable_StreamingProgressChanged; + Streamable.StreamingTimeRemaining -= Streamable_StreamingTimeRemaining; + Streamable.StreamingCompleted -= Streamable_StreamingCompleted; Streamable.StreamingCompleted -= OnStreamingCompletedClose; } private void UnsubscribeProcessable(object sender, LibraryBook e) @@ -97,21 +97,21 @@ namespace LibationWinForms.BookLiberation.BaseForms processable.Completed -= UnsubscribeProcessable; processable.Completed -= OnCompletedDispose; - processable.Completed -= OnCompleted; - processable.StatusUpdate -= OnStatusUpdate; - processable.Begin -= OnBegin; + processable.Completed -= Processable_Completed; + processable.StatusUpdate -= Processable_StatusUpdate; + processable.Begin -= Processable_Begin; } private void UnsubscribeAudioDecodable(object sender, EventArgs e) { - if (Streamable is not IAudioDecodable audioDecodable) + if (Streamable is not AudioDecodable audioDecodable) return; Disposed -= UnsubscribeAudioDecodable; - audioDecodable.RequestCoverArt -= OnRequestCoverArt; - audioDecodable.TitleDiscovered -= OnTitleDiscovered; - audioDecodable.AuthorsDiscovered -= OnAuthorsDiscovered; - audioDecodable.NarratorsDiscovered -= OnNarratorsDiscovered; - audioDecodable.CoverImageDiscovered -= OnCoverImageDiscovered; + audioDecodable.RequestCoverArt -= AudioDecodable_RequestCoverArt; + audioDecodable.TitleDiscovered -= AudioDecodable_TitleDiscovered; + audioDecodable.AuthorsDiscovered -= AudioDecodable_AuthorsDiscovered; + audioDecodable.NarratorsDiscovered -= AudioDecodable_NarratorsDiscovered; + audioDecodable.CoverImageDiscovered -= AudioDecodable_CoverImageDiscovered; audioDecodable.Cancel(); } @@ -133,40 +133,30 @@ namespace LibationWinForms.BookLiberation.BaseForms /// (ie. shown) because Control doesn't get a window handle until it is Shown. /// private void OnStreamingBeginShow(object sender, string beginString) => Invoker.UIThreadAsync(Show); - + #endregion - #region IStreamable event handlers - public virtual void OnStreamingBegin(object sender, string beginString) - => Serilog.Log.Logger.Debug("Event fired {@DebugInfo}", new { Name = nameof(IStreamable.StreamingBegin), Message = beginString }); - public virtual void OnStreamingProgressChanged(object sender, DownloadProgress downloadProgress) { } - public virtual void OnStreamingTimeRemaining(object sender, TimeSpan timeRemaining) { } - public virtual void OnStreamingCompleted(object sender, string completedString) - => Serilog.Log.Logger.Debug("Event fired {@DebugInfo}", new { Name = nameof(IStreamable.StreamingCompleted), Message = completedString }); - + #region Streamable event handlers + public virtual void Streamable_StreamingBegin(object sender, string beginString) { } + public virtual void Streamable_StreamingProgressChanged(object sender, DownloadProgress downloadProgress) { } + public virtual void Streamable_StreamingTimeRemaining(object sender, TimeSpan timeRemaining) { } + public virtual void Streamable_StreamingCompleted(object sender, string completedString) { } + #endregion - #region IProcessable event handlers - public virtual void OnBegin(object sender, LibraryBook libraryBook) - => Serilog.Log.Logger.Debug("Event fired {@DebugInfo}", new { Name = nameof(Processable.Begin), Book = libraryBook.LogFriendly() }); - public virtual void OnStatusUpdate(object sender, string statusUpdate) - => Serilog.Log.Logger.Debug("Event fired {@DebugInfo}", new { Name = nameof(Processable.StatusUpdate), Status = statusUpdate }); - public virtual void OnCompleted(object sender, LibraryBook libraryBook) - => Serilog.Log.Logger.Debug("Event fired {@DebugInfo}", new { Name = nameof(Processable.Completed), Book = libraryBook.LogFriendly() }); - + #region Processable event handlers + public virtual void Processable_Begin(object sender, LibraryBook libraryBook) { } + public virtual void Processable_StatusUpdate(object sender, string statusUpdate) { } + public virtual void Processable_Completed(object sender, LibraryBook libraryBook) { } + #endregion - #region IAudioDecodable event handlers - public virtual void OnRequestCoverArt(object sender, Action setCoverArtDelegate) - => Serilog.Log.Logger.Debug("Event fired {@DebugInfo}", new { Name = nameof(IAudioDecodable.RequestCoverArt) }); - public virtual void OnTitleDiscovered(object sender, string title) - => Serilog.Log.Logger.Debug("Event fired {@DebugInfo}", new { Name = nameof(IAudioDecodable.TitleDiscovered), Title = title }); - public virtual void OnAuthorsDiscovered(object sender, string authors) - => Serilog.Log.Logger.Debug("Event fired {@DebugInfo}", new { Name = nameof(IAudioDecodable.AuthorsDiscovered), Authors = authors }); - public virtual void OnNarratorsDiscovered(object sender, string narrators) - => Serilog.Log.Logger.Debug("Event fired {@DebugInfo}", new { Name = nameof(IAudioDecodable.NarratorsDiscovered), Narrators = narrators }); - public virtual void OnCoverImageDiscovered(object sender, byte[] coverArt) - => Serilog.Log.Logger.Debug("Event fired {@DebugInfo}", new { Name = nameof(IAudioDecodable.CoverImageDiscovered), CoverImageBytes = coverArt?.Length }); + #region AudioDecodable event handlers + public virtual void AudioDecodable_RequestCoverArt(object sender, Action setCoverArtDelegate) { } + public virtual void AudioDecodable_TitleDiscovered(object sender, string title) { } + public virtual void AudioDecodable_AuthorsDiscovered(object sender, string authors) { } + public virtual void AudioDecodable_NarratorsDiscovered(object sender, string narrators) { } + public virtual void AudioDecodable_CoverImageDiscovered(object sender, byte[] coverArt) { } #endregion } } diff --git a/LibationWinForms/BookLiberation/DownloadForm.cs b/LibationWinForms/BookLiberation/DownloadForm.cs index 42127070..7d487b89 100644 --- a/LibationWinForms/BookLiberation/DownloadForm.cs +++ b/LibationWinForms/BookLiberation/DownloadForm.cs @@ -18,14 +18,14 @@ namespace LibationWinForms.BookLiberation #region IStreamable event handler overrides - public override void OnStreamingBegin(object sender, string beginString) + public override void Streamable_StreamingBegin(object sender, string beginString) { - base.OnStreamingBegin(sender, beginString); + base.Streamable_StreamingBegin(sender, beginString); filenameLbl.UIThreadAsync(() => filenameLbl.Text = beginString); } - public override void OnStreamingProgressChanged(object sender, DownloadProgress downloadProgress) + public override void Streamable_StreamingProgressChanged(object sender, DownloadProgress downloadProgress) { - base.OnStreamingProgressChanged(sender, downloadProgress); + base.Streamable_StreamingProgressChanged(sender, downloadProgress); // this won't happen with download file. it will happen with download string if (!downloadProgress.TotalBytesToReceive.HasValue || downloadProgress.TotalBytesToReceive.Value <= 0) return; diff --git a/LibationWinForms/BookLiberation/PdfDownloadForm.cs b/LibationWinForms/BookLiberation/PdfDownloadForm.cs index 85d85eef..017bb3f4 100644 --- a/LibationWinForms/BookLiberation/PdfDownloadForm.cs +++ b/LibationWinForms/BookLiberation/PdfDownloadForm.cs @@ -4,14 +4,14 @@ namespace LibationWinForms.BookLiberation { internal class PdfDownloadForm : DownloadForm { - public override void OnBegin(object sender, LibraryBook libraryBook) + public override void Processable_Begin(object sender, LibraryBook libraryBook) { - base.OnBegin(sender, libraryBook); + base.Processable_Begin(sender, libraryBook); LogMe.Info($"PDF Step, Begin: {libraryBook.Book}"); } - public override void OnCompleted(object sender, LibraryBook libraryBook) + public override void Processable_Completed(object sender, LibraryBook libraryBook) { - base.OnCompleted(sender, libraryBook); + base.Processable_Completed(sender, libraryBook); LogMe.Info($"PDF Step, Completed: {libraryBook.Book}"); } } diff --git a/LibationWinForms/BookLiberation/ProcessorAutomationController.cs b/LibationWinForms/BookLiberation/ProcessorAutomationController.cs index edab5e66..339f4c31 100644 --- a/LibationWinForms/BookLiberation/ProcessorAutomationController.cs +++ b/LibationWinForms/BookLiberation/ProcessorAutomationController.cs @@ -135,7 +135,7 @@ namespace LibationWinForms.BookLiberation /// 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 derived Form to create on , Show on , Close on , and Dispose on /// The logger /// An additional event handler to handle /// A new of type @@ -149,7 +149,7 @@ namespace LibationWinForms.BookLiberation { var processForm = new TForm(); processForm.RegisterFileLiberator(strProc, logMe); - processForm.OnBegin(sender, libraryBook); + processForm.Processable_Begin(sender, libraryBook); }; strProc.Completed += completedAction;