diff --git a/FileLiberator/IFileLiberator.cs b/FileLiberator/IFileLiberator.cs new file mode 100644 index 00000000..e6bdf7aa --- /dev/null +++ b/FileLiberator/IFileLiberator.cs @@ -0,0 +1,4 @@ +namespace FileLiberator +{ + public interface IFileLiberator { } +} diff --git a/FileLiberator/IProcessable.cs b/FileLiberator/IProcessable.cs index 9814f21d..254090b2 100644 --- a/FileLiberator/IProcessable.cs +++ b/FileLiberator/IProcessable.cs @@ -5,7 +5,7 @@ using Dinah.Core.ErrorHandling; namespace FileLiberator { - public interface IProcessable + public interface IProcessable : IFileLiberator { event EventHandler Begin; diff --git a/FileLiberator/IStreamable.cs b/FileLiberator/IStreamable.cs index 94049a7a..cdc5b1a3 100644 --- a/FileLiberator/IStreamable.cs +++ b/FileLiberator/IStreamable.cs @@ -3,7 +3,7 @@ using Dinah.Core.Net.Http; namespace FileLiberator { - public interface IStreamable + public interface IStreamable : IFileLiberator { event EventHandler StreamingBegin; event EventHandler StreamingProgressChanged; diff --git a/LibationLauncher/LibationLauncher.csproj b/LibationLauncher/LibationLauncher.csproj index b381edd2..b0816399 100644 --- a/LibationLauncher/LibationLauncher.csproj +++ b/LibationLauncher/LibationLauncher.csproj @@ -13,7 +13,7 @@ win-x64 - 5.4.9.274 + 5.4.9.279 diff --git a/LibationWinForms/BookLiberation/AudioConvertForm.cs b/LibationWinForms/BookLiberation/AudioConvertForm.cs index 82a586f1..29020425 100644 --- a/LibationWinForms/BookLiberation/AudioConvertForm.cs +++ b/LibationWinForms/BookLiberation/AudioConvertForm.cs @@ -3,9 +3,9 @@ using System; namespace LibationWinForms.BookLiberation { - class AudioConvertForm : AudioDecodeBaseForm + class AudioConvertForm : AudioDecodeForm { - #region AudioDecodeBaseForm overrides + #region AudioDecodeForm overrides public override string DecodeActionName => "Converting"; #endregion diff --git a/LibationWinForms/BookLiberation/BaseForms/AudioDecodeBaseForm.Designer.cs b/LibationWinForms/BookLiberation/AudioDecodeForm.Designer.cs similarity index 99% rename from LibationWinForms/BookLiberation/BaseForms/AudioDecodeBaseForm.Designer.cs rename to LibationWinForms/BookLiberation/AudioDecodeForm.Designer.cs index d38e4bbb..b16425dd 100644 --- a/LibationWinForms/BookLiberation/BaseForms/AudioDecodeBaseForm.Designer.cs +++ b/LibationWinForms/BookLiberation/AudioDecodeForm.Designer.cs @@ -1,6 +1,6 @@ namespace LibationWinForms.BookLiberation { - partial class AudioDecodeBaseForm + partial class AudioDecodeForm { /// /// Required designer variable. diff --git a/LibationWinForms/BookLiberation/BaseForms/AudioDecodeBaseForm.cs b/LibationWinForms/BookLiberation/AudioDecodeForm.cs similarity index 59% rename from LibationWinForms/BookLiberation/BaseForms/AudioDecodeBaseForm.cs rename to LibationWinForms/BookLiberation/AudioDecodeForm.cs index a982958b..1e0dd1a9 100644 --- a/LibationWinForms/BookLiberation/BaseForms/AudioDecodeBaseForm.cs +++ b/LibationWinForms/BookLiberation/AudioDecodeForm.cs @@ -1,15 +1,20 @@ using DataLayer; using Dinah.Core.Net.Http; using Dinah.Core.Windows.Forms; -using FileLiberator; +using LibationWinForms.BookLiberation.BaseForms; using System; namespace LibationWinForms.BookLiberation { - public partial class AudioDecodeBaseForm : ProcessBaseForm + public partial class AudioDecodeForm +#if DEBUG + : DebugIntermediate +#else + : LiberationBaseForm +#endif { public virtual string DecodeActionName { get; } = "Decoding"; - public AudioDecodeBaseForm() => InitializeComponent(); + public AudioDecodeForm() => InitializeComponent(); private Func GetCoverArtDelegate; @@ -18,41 +23,6 @@ namespace LibationWinForms.BookLiberation private string authorNames; private string narratorNames; - #region ProcessBaseForm overrides - public override void SetProcessable(IStreamable streamProcessable, LogMe logMe) - { - base.SetProcessable(streamProcessable, logMe); - - if (Streamable is not null && Streamable is IAudioDecodable audioDecodable) - { - OnUnsubscribeAll(this, EventArgs.Empty); - - audioDecodable.RequestCoverArt += OnRequestCoverArt; - audioDecodable.TitleDiscovered += OnTitleDiscovered; - audioDecodable.AuthorsDiscovered += OnAuthorsDiscovered; - audioDecodable.NarratorsDiscovered += OnNarratorsDiscovered; - audioDecodable.CoverImageDiscovered += OnCoverImageDiscovered; - - Disposed += OnUnsubscribeAll; - } - } - #endregion - - private void OnUnsubscribeAll(object sender, EventArgs e) - { - if (Streamable is IAudioDecodable audioDecodable) - { - Disposed -= OnUnsubscribeAll; - audioDecodable.RequestCoverArt -= OnRequestCoverArt; - audioDecodable.TitleDiscovered -= OnTitleDiscovered; - audioDecodable.AuthorsDiscovered -= OnAuthorsDiscovered; - audioDecodable.NarratorsDiscovered -= OnNarratorsDiscovered; - audioDecodable.CoverImageDiscovered -= OnCoverImageDiscovered; - - audioDecodable.Cancel(); - } - } - #region IProcessable event handler overrides public override void OnBegin(object sender, LibraryBook libraryBook) { @@ -74,6 +44,7 @@ namespace LibationWinForms.BookLiberation #endregion #region IStreamable event handler overrides + public override void OnStreamingBegin(object sender, string beginString) { } public override void OnStreamingProgressChanged(object sender, DownloadProgress downloadProgress) { if (!downloadProgress.ProgressPercentage.HasValue) @@ -87,32 +58,34 @@ namespace LibationWinForms.BookLiberation public override void OnStreamingTimeRemaining(object sender, TimeSpan timeRemaining) => updateRemainingTime((int)timeRemaining.TotalSeconds); + + public override void OnStreamingCompleted(object sender, string completedString) { } #endregion #region IAudioDecodable event handlers - public virtual void OnRequestCoverArt(object sender, Action setCoverArtDelegate) + public override void OnRequestCoverArt(object sender, Action setCoverArtDelegate) => setCoverArtDelegate(GetCoverArtDelegate?.Invoke()); - public virtual void OnTitleDiscovered(object sender, string title) + public override void OnTitleDiscovered(object sender, string title) { this.UIThread(() => this.Text = DecodeActionName + " " + title); this.title = title; updateBookInfo(); } - public virtual void OnAuthorsDiscovered(object sender, string authors) + public override void OnAuthorsDiscovered(object sender, string authors) { authorNames = authors; updateBookInfo(); } - public virtual void OnNarratorsDiscovered(object sender, string narrators) + public override void OnNarratorsDiscovered(object sender, string narrators) { narratorNames = narrators; updateBookInfo(); } - public virtual void OnCoverImageDiscovered(object sender, byte[] coverArt) + public override void OnCoverImageDiscovered(object sender, byte[] coverArt) => pictureBox1.UIThread(() => pictureBox1.Image = Dinah.Core.Drawing.ImageReader.ToImage(coverArt)); #endregion diff --git a/LibationWinForms/BookLiberation/BaseForms/AudioDecodeBaseForm.resx b/LibationWinForms/BookLiberation/AudioDecodeForm.resx similarity index 100% rename from LibationWinForms/BookLiberation/BaseForms/AudioDecodeBaseForm.resx rename to LibationWinForms/BookLiberation/AudioDecodeForm.resx diff --git a/LibationWinForms/BookLiberation/AudioDecryptForm.cs b/LibationWinForms/BookLiberation/AudioDecryptForm.cs index a27b936d..b28e106d 100644 --- a/LibationWinForms/BookLiberation/AudioDecryptForm.cs +++ b/LibationWinForms/BookLiberation/AudioDecryptForm.cs @@ -3,9 +3,9 @@ using System; namespace LibationWinForms.BookLiberation { - class AudioDecryptForm : AudioDecodeBaseForm + class AudioDecryptForm : AudioDecodeForm { - #region AudioDecodeBaseForm overrides + #region AudioDecodeForm overrides public override string DecodeActionName => "Decrypting"; #endregion diff --git a/LibationWinForms/BookLiberation/BaseForms/LiberationBaseForm.cs b/LibationWinForms/BookLiberation/BaseForms/LiberationBaseForm.cs new file mode 100644 index 00000000..496ccd6f --- /dev/null +++ b/LibationWinForms/BookLiberation/BaseForms/LiberationBaseForm.cs @@ -0,0 +1,189 @@ +using DataLayer; +using Dinah.Core.Net.Http; +using Dinah.Core.Windows.Forms; +using FileLiberator; +using System; +using System.ComponentModel; +using System.Threading; +using System.Windows.Forms; + +namespace LibationWinForms.BookLiberation.BaseForms +{ + public abstract class LiberationBaseForm : Form + { + protected IFileLiberator Liberation { get; private set; } + protected LogMe LogMe { get; private set; } + + private int InstanceThreadId { get; } = Thread.CurrentThread.ManagedThreadId; + public new bool InvokeRequired => Thread.CurrentThread.ManagedThreadId != InstanceThreadId; + private SynchronizationContext SyncContext { get; } + + public LiberationBaseForm() + { + //Will be null if set outside constructor. + SyncContext = SynchronizationContext.Current; + } + + public void RegisterLiberation(IFileLiberator liberation, LogMe logMe = null) + { + if (liberation is null) return; + + Liberation = liberation; + LogMe = logMe; + + if (Liberation is IStreamable streamable) + Subscribe(streamable); + if (Liberation is IProcessable processable) + Subscribe(processable); + if (Liberation is IAudioDecodable audioDecodable) + Subscribe(audioDecodable); + } + + #region Event Subscribers and Unsubscribers + private void Subscribe(IStreamable streamable) + { + UnsubscribeStreamable(this, EventArgs.Empty); + + streamable.StreamingBegin += ShowFormHandler; + streamable.StreamingBegin += OnStreamingBegin; + streamable.StreamingProgressChanged += OnStreamingProgressChanged; + streamable.StreamingTimeRemaining += OnStreamingTimeRemaining; + streamable.StreamingCompleted += OnStreamingCompleted; + streamable.StreamingCompleted += OnStreamingCompletedClose; + + FormClosed += UnsubscribeStreamable; + } + private void Subscribe(IProcessable processable) + { + UnsubscribeProcessable(this, null); + + processable.Begin += OnBegin; + processable.StatusUpdate += OnStatusUpdate; + processable.Completed += OnCompleted; + + //The form is created on IProcessable.Begin and we + //dispose of it on IProcessable.Completed + processable.Completed += OnCompletedDispose; + + //Don't unsubscribe from Dispose because it fires when + //IStreamable.StreamingCompleted closes the form, and + //the IProcessable events need to live past that event. + processable.Completed += UnsubscribeProcessable; + } + private void Subscribe(IAudioDecodable audioDecodable) + { + UnsubscribeAudioDecodable(this, EventArgs.Empty); + + audioDecodable.RequestCoverArt += OnRequestCoverArt; + audioDecodable.TitleDiscovered += OnTitleDiscovered; + audioDecodable.AuthorsDiscovered += OnAuthorsDiscovered; + audioDecodable.NarratorsDiscovered += OnNarratorsDiscovered; + audioDecodable.CoverImageDiscovered += OnCoverImageDiscovered; + + Disposed += UnsubscribeAudioDecodable; + } + private void UnsubscribeStreamable(object sender, EventArgs e) + { + if (Liberation is not IStreamable streamable) + return; + + FormClosed -= UnsubscribeStreamable; + + streamable.StreamingBegin -= ShowFormHandler; + streamable.StreamingBegin -= OnStreamingBegin; + streamable.StreamingProgressChanged -= OnStreamingProgressChanged; + streamable.StreamingTimeRemaining -= OnStreamingTimeRemaining; + streamable.StreamingCompleted -= OnStreamingCompleted; + streamable.StreamingCompleted -= OnStreamingCompletedClose; + } + private void UnsubscribeProcessable(object sender, LibraryBook e) + { + if (Liberation is not IProcessable processable) + return; + + processable.Completed -= UnsubscribeProcessable; + processable.Completed -= OnCompletedDispose; + processable.Completed -= OnCompleted; + processable.StatusUpdate -= OnStatusUpdate; + processable.Begin -= OnBegin; + } + private void UnsubscribeAudioDecodable(object sender, EventArgs e) + { + if (Liberation is not IAudioDecodable audioDecodable) + return; + + Disposed -= UnsubscribeAudioDecodable; + audioDecodable.RequestCoverArt -= OnRequestCoverArt; + audioDecodable.TitleDiscovered -= OnTitleDiscovered; + audioDecodable.AuthorsDiscovered -= OnAuthorsDiscovered; + audioDecodable.NarratorsDiscovered -= OnNarratorsDiscovered; + audioDecodable.CoverImageDiscovered -= OnCoverImageDiscovered; + + audioDecodable.Cancel(); + } + #endregion + + #region Form creation and disposal handling + + /// + /// If the form was shown using Show (not ShowDialog), Form.Close calls Form.Dispose + /// + private void OnStreamingCompletedClose(object sender, string completedString) => this.UIThread(() => Close()); + private void OnCompletedDispose(object sender, LibraryBook e) => this.UIThread(() => Dispose()); + + /// + /// If StreamingBegin is fired from a worker thread, the window will be created on + /// that UI thread. We need to make certain that we show the window on the same + /// thread that created form, otherwise the form and the window handle will be on + /// different threads. Form.BeginInvoke won't work until the form is created + /// (ie. shown) because control doesn't get a window handle until it is Shown. + /// + private void ShowFormHandler(object sender, string beginString) + { + static void sendCallback(object asyncArgs) + { + var e = asyncArgs as AsyncCompletedEventArgs; + ((Action)e.UserState)(); + } + + Action show = Show; + + if (InvokeRequired) + SyncContext.Send( + sendCallback, + new AsyncCompletedEventArgs(null, false, show)); + else + show(); + } + #endregion + + #region IStreamable event handlers + public virtual void OnStreamingBegin(object sender, string 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){ } + #endregion + + #region IProcessable event handlers + public virtual void OnBegin(object sender, LibraryBook libraryBook){ } + public virtual void OnStatusUpdate(object sender, string statusUpdate){ } + public virtual void OnCompleted(object sender, LibraryBook libraryBook){ } + #endregion + + #region IAudioDecodable event handlers + public virtual void OnRequestCoverArt(object sender, Action setCoverArtDelegate){ } + public virtual void OnTitleDiscovered(object sender, string title){ } + public virtual void OnAuthorsDiscovered(object sender, string authors){ } + public virtual void OnNarratorsDiscovered(object sender, string narrators){ } + public virtual void OnCoverImageDiscovered(object sender, byte[] coverArt){ } + #endregion + } + + #region VS Design View Hack + /// + /// This class is a hack so that VS designer will work wif an abstract base class. + /// https://stackoverflow.com/questions/1620847/how-can-i-get-visual-studio-2008-windows-forms-designer-to-render-a-form-that-im/2406058#2406058 + /// + public class DebugIntermediate : LiberationBaseForm { } + #endregion +} diff --git a/LibationWinForms/BookLiberation/BaseForms/ProcessBaseForm.cs b/LibationWinForms/BookLiberation/BaseForms/ProcessBaseForm.cs deleted file mode 100644 index fd9d657c..00000000 --- a/LibationWinForms/BookLiberation/BaseForms/ProcessBaseForm.cs +++ /dev/null @@ -1,54 +0,0 @@ -using DataLayer; -using Dinah.Core.Windows.Forms; -using FileLiberator; -using System; - -namespace LibationWinForms.BookLiberation -{ - public class ProcessBaseForm : StreamBaseForm - { - protected LogMe LogMe { get; private set; } - public virtual void SetProcessable(IStreamable streamable, LogMe logMe) - { - LogMe = logMe; - SetStreamable(streamable); - - if (Streamable is not null && Streamable is IProcessable processable) - { - OnUnsubscribeAll(this, null); - - processable.Begin += OnBegin; - processable.Completed += OnCompleted; - processable.StatusUpdate += OnStatusUpdate; - - //The form is created on IProcessable.Begin and we - //dispose of it on IProcessable.Completed - processable.Completed += OnCompletedDispose; - - //Don't unsubscribe from Dispose because it fires when - //IStreamable.StreamingCompleted closes the form, and - //the IProcessable events need to live past that event. - processable.Completed += OnUnsubscribeAll; - } - } - private void OnCompletedDispose(object sender, LibraryBook e) => this.UIThread(() => Dispose()); - - private void OnUnsubscribeAll(object sender, LibraryBook e) - { - if (Streamable is IProcessable processable) - { - processable.Completed -= OnUnsubscribeAll; - processable.Completed -= OnCompletedDispose; - processable.Begin -= OnBegin; - processable.Completed -= OnCompleted; - processable.StatusUpdate -= OnStatusUpdate; - } - } - - #region IProcessable event handlers - public virtual void OnBegin(object sender, LibraryBook libraryBook) => LogMe.Info($"Begin: {libraryBook.Book}"); - public virtual void OnStatusUpdate(object sender, string statusUpdate) => LogMe.Info("- " + statusUpdate); - public virtual void OnCompleted(object sender, LibraryBook libraryBook) => LogMe.Info($"Completed: {libraryBook.Book}{Environment.NewLine}"); - #endregion - } -} diff --git a/LibationWinForms/BookLiberation/BaseForms/ProcessBaseForm.resx b/LibationWinForms/BookLiberation/BaseForms/ProcessBaseForm.resx deleted file mode 100644 index e8ae276d..00000000 --- a/LibationWinForms/BookLiberation/BaseForms/ProcessBaseForm.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/LibationWinForms/BookLiberation/BaseForms/StreamBaseForm.cs b/LibationWinForms/BookLiberation/BaseForms/StreamBaseForm.cs deleted file mode 100644 index a11fce86..00000000 --- a/LibationWinForms/BookLiberation/BaseForms/StreamBaseForm.cs +++ /dev/null @@ -1,90 +0,0 @@ -using Dinah.Core.Net.Http; -using Dinah.Core.Windows.Forms; -using FileLiberator; -using System; -using System.ComponentModel; -using System.Threading; -using System.Windows.Forms; - -namespace LibationWinForms.BookLiberation -{ - public class StreamBaseForm : Form - { - private int InstanceThreadId { get; } = Thread.CurrentThread.ManagedThreadId; - public new bool InvokeRequired => Thread.CurrentThread.ManagedThreadId != InstanceThreadId; - private SynchronizationContext SyncContext { get; } - - public StreamBaseForm() - { - //Will be null if set outside constructor. - SyncContext = SynchronizationContext.Current; - } - - protected IStreamable Streamable { get; private set; } - public void SetStreamable(IStreamable streamable) - { - Streamable = streamable; - - if (Streamable is null) return; - - OnUnsubscribeAll(this, EventArgs.Empty); - - Streamable.StreamingBegin += ShowFormHandler; - Streamable.StreamingBegin += OnStreamingBegin; - Streamable.StreamingProgressChanged += OnStreamingProgressChanged; - Streamable.StreamingTimeRemaining += OnStreamingTimeRemaining; - Streamable.StreamingCompleted += OnStreamingCompleted; - Streamable.StreamingCompleted += CloseFormHandler; - - FormClosed += OnUnsubscribeAll; - } - - private void OnUnsubscribeAll(object sender, EventArgs e) - { - FormClosed -= OnUnsubscribeAll; - - Streamable.StreamingBegin -= ShowFormHandler; - Streamable.StreamingBegin -= OnStreamingBegin; - Streamable.StreamingProgressChanged -= OnStreamingProgressChanged; - Streamable.StreamingTimeRemaining -= OnStreamingTimeRemaining; - Streamable.StreamingCompleted -= OnStreamingCompleted; - Streamable.StreamingCompleted -= CloseFormHandler; - } - - private void ShowFormHandler(object sender, string beginString) - { - //If StreamingBegin is fired from a worker thread, the window will be created on - //that UI thread. We need to make certain that we show the window on the same - //thread that created form, otherwise the form and the window handle will be on - //different threads. Form.BeginInvoke won't work until the form is created - //(ie. shown) because control doesn't get a window handle until it is Shown. - static void sendCallback(object asyncArgs) - { - var e = asyncArgs as AsyncCompletedEventArgs; - ((Action)e.UserState)(); - } - - Action show = Show; - - if (InvokeRequired) - SyncContext.Send( - sendCallback, - new AsyncCompletedEventArgs(null, false, show)); - else - show(); - } - - /// - /// If the form was shown using Show (not ShowDialog), Form.Close calls Form.Dispose - /// - private void CloseFormHandler(object sender, string completedString) => this.UIThread(() => Close()); - - - #region IStreamable event handlers - public virtual void OnStreamingBegin(object sender, string 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) { } - #endregion - } -} diff --git a/LibationWinForms/BookLiberation/BaseForms/StreamBaseForm.resx b/LibationWinForms/BookLiberation/BaseForms/StreamBaseForm.resx deleted file mode 100644 index e8ae276d..00000000 --- a/LibationWinForms/BookLiberation/BaseForms/StreamBaseForm.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/LibationWinForms/BookLiberation/DownloadForm.Designer.cs b/LibationWinForms/BookLiberation/DownloadForm.Designer.cs index 7f5f80c3..b6746fe5 100644 --- a/LibationWinForms/BookLiberation/DownloadForm.Designer.cs +++ b/LibationWinForms/BookLiberation/DownloadForm.Designer.cs @@ -1,4 +1,7 @@ -namespace LibationWinForms.BookLiberation +using DataLayer; +using System; + +namespace LibationWinForms.BookLiberation { partial class DownloadForm { @@ -95,9 +98,10 @@ } - #endregion - private System.Windows.Forms.Label filenameLbl; + #endregion + + private System.Windows.Forms.Label filenameLbl; private System.Windows.Forms.ProgressBar progressBar1; private System.Windows.Forms.Label progressLbl; private System.Windows.Forms.Label lastUpdateLbl; diff --git a/LibationWinForms/BookLiberation/DownloadForm.cs b/LibationWinForms/BookLiberation/DownloadForm.cs index 563a68fd..1eb50c9e 100644 --- a/LibationWinForms/BookLiberation/DownloadForm.cs +++ b/LibationWinForms/BookLiberation/DownloadForm.cs @@ -1,13 +1,18 @@ -using DataLayer; -using Dinah.Core.Net.Http; +using Dinah.Core.Net.Http; using Dinah.Core.Windows.Forms; +using LibationWinForms.BookLiberation.BaseForms; using System; using System.Linq; using System.Windows.Forms; namespace LibationWinForms.BookLiberation { - public partial class DownloadForm : ProcessBaseForm + public partial class DownloadForm +#if DEBUG + : DebugIntermediate +#else + : LiberationBaseForm +#endif { public DownloadForm() { @@ -17,11 +22,11 @@ namespace LibationWinForms.BookLiberation filenameLbl.Text = ""; } + #region IStreamable event handler overrides public override void OnStreamingBegin(object sender, string beginString) { filenameLbl.UIThread(() => filenameLbl.Text = beginString); - base.OnStreamingBegin(sender, beginString); } public override void OnStreamingProgressChanged(object sender, DownloadProgress downloadProgress) { diff --git a/LibationWinForms/BookLiberation/ProcessorAutomationController.cs b/LibationWinForms/BookLiberation/ProcessorAutomationController.cs index c911243d..04359a42 100644 --- a/LibationWinForms/BookLiberation/ProcessorAutomationController.cs +++ b/LibationWinForms/BookLiberation/ProcessorAutomationController.cs @@ -1,6 +1,7 @@ using DataLayer; using Dinah.Core; using FileLiberator; +using LibationWinForms.BookLiberation.BaseForms; using System; using System.Linq; using System.Threading.Tasks; @@ -126,15 +127,15 @@ namespace LibationWinForms.BookLiberation } /// - /// Create a new and links it to a new . + /// Create a new and links it to a new . /// /// The derrived type to create. - /// The derrived Form to create on , Show on , and Close & Dispose on + /// The derrived 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 TStrProc CreateStreamProcessable(LogMe logMe, EventHandler completedAction = null) - where TForm : ProcessBaseForm, new() + where TForm : LiberationBaseForm, new() where TStrProc : IStreamProcessable, new() { var strProc = new TStrProc(); @@ -142,7 +143,7 @@ namespace LibationWinForms.BookLiberation strProc.Begin += (sender, libraryBook) => { var processForm = new TForm(); - processForm.SetProcessable(strProc, logMe); + processForm.RegisterLiberation(strProc, logMe); processForm.OnBegin(sender, libraryBook); }; @@ -153,20 +154,20 @@ namespace LibationWinForms.BookLiberation } /// - /// Creates a new and links it to a new + /// Creates a new and links it to a new /// /// The derrived type to create. - /// The derrived Form to create, which will Show on and Close & Dispose on . + /// The derrived Form to create, which will Show on and Close, Dispose on . /// An additional event handler to handle /// A new of type private static TStr CreateStreamable(EventHandler completedAction = null) - where TForm : StreamBaseForm, new() + where TForm : LiberationBaseForm, new() where TStr : IStreamable, new() { var streamable = new TStr(); var streamForm = new TForm(); - streamForm.SetStreamable(streamable); + streamForm.RegisterLiberation(streamable); if (completedAction != null) streamable.StreamingCompleted += completedAction;