Remove IStreamProcessable. IProcessible inherits IStreamable.
This commit is contained in:
parent
f925d10d2b
commit
081878b6f7
@ -6,7 +6,7 @@ using Dinah.Core.Net.Http;
|
|||||||
|
|
||||||
namespace FileLiberator
|
namespace FileLiberator
|
||||||
{
|
{
|
||||||
public abstract class DownloadableBase : IStreamProcessable
|
public abstract class DownloadableBase : IProcessable
|
||||||
{
|
{
|
||||||
public event EventHandler<LibraryBook> Begin;
|
public event EventHandler<LibraryBook> Begin;
|
||||||
public event EventHandler<LibraryBook> Completed;
|
public event EventHandler<LibraryBook> Completed;
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace FileLiberator
|
namespace FileLiberator
|
||||||
{
|
{
|
||||||
public interface IAudioDecodable : IStreamProcessable
|
public interface IAudioDecodable : IProcessable
|
||||||
{
|
{
|
||||||
event EventHandler<Action<byte[]>> RequestCoverArt;
|
event EventHandler<Action<byte[]>> RequestCoverArt;
|
||||||
event EventHandler<string> TitleDiscovered;
|
event EventHandler<string> TitleDiscovered;
|
||||||
|
|||||||
@ -1,4 +0,0 @@
|
|||||||
namespace FileLiberator
|
|
||||||
{
|
|
||||||
public interface IFileLiberator { }
|
|
||||||
}
|
|
||||||
@ -5,7 +5,7 @@ using Dinah.Core.ErrorHandling;
|
|||||||
|
|
||||||
namespace FileLiberator
|
namespace FileLiberator
|
||||||
{
|
{
|
||||||
public interface IProcessable : IFileLiberator
|
public interface IProcessable : IStreamable
|
||||||
{
|
{
|
||||||
event EventHandler<LibraryBook> Begin;
|
event EventHandler<LibraryBook> Begin;
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +0,0 @@
|
|||||||
|
|
||||||
namespace FileLiberator
|
|
||||||
{
|
|
||||||
public interface IStreamProcessable : IStreamable, IProcessable { }
|
|
||||||
}
|
|
||||||
@ -3,7 +3,7 @@ using Dinah.Core.Net.Http;
|
|||||||
|
|
||||||
namespace FileLiberator
|
namespace FileLiberator
|
||||||
{
|
{
|
||||||
public interface IStreamable : IFileLiberator
|
public interface IStreamable
|
||||||
{
|
{
|
||||||
event EventHandler<string> StreamingBegin;
|
event EventHandler<string> StreamingBegin;
|
||||||
event EventHandler<DownloadProgress> StreamingProgressChanged;
|
event EventHandler<DownloadProgress> StreamingProgressChanged;
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
<!-- <PublishSingleFile>true</PublishSingleFile> -->
|
<!-- <PublishSingleFile>true</PublishSingleFile> -->
|
||||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||||
|
|
||||||
<Version>5.4.9.279</Version>
|
<Version>5.4.9.280</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
|
|||||||
@ -11,7 +11,7 @@ namespace LibationWinForms.BookLiberation.BaseForms
|
|||||||
{
|
{
|
||||||
public abstract class LiberationBaseForm : Form
|
public abstract class LiberationBaseForm : Form
|
||||||
{
|
{
|
||||||
protected IFileLiberator FileLiberator { get; private set; }
|
protected IStreamable Streamable { get; private set; }
|
||||||
protected LogMe LogMe { get; private set; }
|
protected LogMe LogMe { get; private set; }
|
||||||
|
|
||||||
private int InstanceThreadId { get; } = Thread.CurrentThread.ManagedThreadId;
|
private int InstanceThreadId { get; } = Thread.CurrentThread.ManagedThreadId;
|
||||||
@ -24,19 +24,19 @@ namespace LibationWinForms.BookLiberation.BaseForms
|
|||||||
SyncContext = SynchronizationContext.Current;
|
SyncContext = SynchronizationContext.Current;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RegisterFileLiberator(IFileLiberator fileLiberator, LogMe logMe = null)
|
public void RegisterFileLiberator(IStreamable streamable, LogMe logMe = null)
|
||||||
{
|
{
|
||||||
//IFileLiberator must at least be IStreamable, otherwise the Form won't ever Show()
|
//IFileLiberator must at least be IStreamable, otherwise the Form won't ever Show()
|
||||||
if (fileLiberator is null || fileLiberator is not IStreamable streamable) return;
|
if (streamable is null) return;
|
||||||
|
|
||||||
FileLiberator = fileLiberator;
|
Streamable = streamable;
|
||||||
LogMe = logMe;
|
LogMe = logMe;
|
||||||
|
|
||||||
Subscribe(streamable);
|
Subscribe(streamable);
|
||||||
|
|
||||||
if (FileLiberator is IProcessable processable)
|
if (Streamable is IProcessable processable)
|
||||||
Subscribe(processable);
|
Subscribe(processable);
|
||||||
if (FileLiberator is IAudioDecodable audioDecodable)
|
if (Streamable is IAudioDecodable audioDecodable)
|
||||||
Subscribe(audioDecodable);
|
Subscribe(audioDecodable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,21 +85,18 @@ namespace LibationWinForms.BookLiberation.BaseForms
|
|||||||
}
|
}
|
||||||
private void UnsubscribeStreamable(object sender, EventArgs e)
|
private void UnsubscribeStreamable(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (FileLiberator is not IStreamable streamable)
|
|
||||||
return;
|
|
||||||
|
|
||||||
FormClosed -= UnsubscribeStreamable;
|
FormClosed -= UnsubscribeStreamable;
|
||||||
|
|
||||||
streamable.StreamingBegin -= OnStreamingBeginShow;
|
Streamable.StreamingBegin -= OnStreamingBeginShow;
|
||||||
streamable.StreamingBegin -= OnStreamingBegin;
|
Streamable.StreamingBegin -= OnStreamingBegin;
|
||||||
streamable.StreamingProgressChanged -= OnStreamingProgressChanged;
|
Streamable.StreamingProgressChanged -= OnStreamingProgressChanged;
|
||||||
streamable.StreamingTimeRemaining -= OnStreamingTimeRemaining;
|
Streamable.StreamingTimeRemaining -= OnStreamingTimeRemaining;
|
||||||
streamable.StreamingCompleted -= OnStreamingCompleted;
|
Streamable.StreamingCompleted -= OnStreamingCompleted;
|
||||||
streamable.StreamingCompleted -= OnStreamingCompletedClose;
|
Streamable.StreamingCompleted -= OnStreamingCompletedClose;
|
||||||
}
|
}
|
||||||
private void UnsubscribeProcessable(object sender, LibraryBook e)
|
private void UnsubscribeProcessable(object sender, LibraryBook e)
|
||||||
{
|
{
|
||||||
if (FileLiberator is not IProcessable processable)
|
if (Streamable is not IProcessable processable)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
processable.Completed -= UnsubscribeProcessable;
|
processable.Completed -= UnsubscribeProcessable;
|
||||||
@ -110,7 +107,7 @@ namespace LibationWinForms.BookLiberation.BaseForms
|
|||||||
}
|
}
|
||||||
private void UnsubscribeAudioDecodable(object sender, EventArgs e)
|
private void UnsubscribeAudioDecodable(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (FileLiberator is not IAudioDecodable audioDecodable)
|
if (Streamable is not IAudioDecodable audioDecodable)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Disposed -= UnsubscribeAudioDecodable;
|
Disposed -= UnsubscribeAudioDecodable;
|
||||||
|
|||||||
@ -79,7 +79,7 @@ namespace LibationWinForms.BookLiberation
|
|||||||
var automatedBackupsForm = new AutomatedBackupsForm();
|
var automatedBackupsForm = new AutomatedBackupsForm();
|
||||||
var logMe = LogMe.RegisterForm(automatedBackupsForm);
|
var logMe = LogMe.RegisterForm(automatedBackupsForm);
|
||||||
|
|
||||||
var convertBook = CreateStreamProcessable<ConvertToMp3, AudioConvertForm>(logMe);
|
var convertBook = CreateProcessable<ConvertToMp3, AudioConvertForm>(logMe);
|
||||||
|
|
||||||
await new BackupLoop(logMe, convertBook, automatedBackupsForm).RunBackupAsync();
|
await new BackupLoop(logMe, convertBook, automatedBackupsForm).RunBackupAsync();
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ namespace LibationWinForms.BookLiberation
|
|||||||
var automatedBackupsForm = new AutomatedBackupsForm();
|
var automatedBackupsForm = new AutomatedBackupsForm();
|
||||||
var logMe = LogMe.RegisterForm(automatedBackupsForm);
|
var logMe = LogMe.RegisterForm(automatedBackupsForm);
|
||||||
|
|
||||||
var downloadPdf = CreateStreamProcessable<DownloadPdf, PdfDownloadForm>(logMe, completedAction);
|
var downloadPdf = CreateProcessable<DownloadPdf, PdfDownloadForm>(logMe, completedAction);
|
||||||
|
|
||||||
await new BackupLoop(logMe, downloadPdf, automatedBackupsForm).RunBackupAsync();
|
await new BackupLoop(logMe, downloadPdf, automatedBackupsForm).RunBackupAsync();
|
||||||
}
|
}
|
||||||
@ -113,7 +113,7 @@ namespace LibationWinForms.BookLiberation
|
|||||||
|
|
||||||
private static IProcessable CreateBackupBook(EventHandler<LibraryBook> completedAction, LogMe logMe)
|
private static IProcessable CreateBackupBook(EventHandler<LibraryBook> completedAction, LogMe logMe)
|
||||||
{
|
{
|
||||||
var downloadPdf = CreateStreamProcessable<DownloadPdf, PdfDownloadForm>(logMe);
|
var downloadPdf = CreateProcessable<DownloadPdf, PdfDownloadForm>(logMe);
|
||||||
|
|
||||||
//Chain pdf download on DownloadDecryptBook.Completed
|
//Chain pdf download on DownloadDecryptBook.Completed
|
||||||
async void onDownloadDecryptBookCompleted(object sender, LibraryBook e)
|
async void onDownloadDecryptBookCompleted(object sender, LibraryBook e)
|
||||||
@ -122,21 +122,21 @@ namespace LibationWinForms.BookLiberation
|
|||||||
completedAction(sender, e);
|
completedAction(sender, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
var downloadDecryptBook = CreateStreamProcessable<DownloadDecryptBook, AudioDecryptForm>(logMe, onDownloadDecryptBookCompleted);
|
var downloadDecryptBook = CreateProcessable<DownloadDecryptBook, AudioDecryptForm>(logMe, onDownloadDecryptBookCompleted);
|
||||||
return downloadDecryptBook;
|
return downloadDecryptBook;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new <see cref="IStreamProcessable"/> and links it to a new <see cref="LiberationBaseForm"/>.
|
/// Create a new <see cref="IProcessable"/> and links it to a new <see cref="LiberationBaseForm"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TStrProc">The <see cref="IStreamProcessable"/> derrived type to create.</typeparam>
|
/// <typeparam name="TStrProc">The <see cref="IProcessable"/> derrived type to create.</typeparam>
|
||||||
/// <typeparam name="TForm">The <see cref="LiberationBaseForm"/> derrived Form to create on <see cref="IProcessable.Begin"/>, Show on <see cref="IStreamable.StreamingBegin"/>, Close on <see cref="IStreamable.StreamingCompleted"/>, and Dispose on <see cref="IProcessable.Completed"/> </typeparam>
|
/// <typeparam name="TForm">The <see cref="LiberationBaseForm"/> derrived Form to create on <see cref="IProcessable.Begin"/>, Show on <see cref="IStreamable.StreamingBegin"/>, Close on <see cref="IStreamable.StreamingCompleted"/>, and Dispose on <see cref="IProcessable.Completed"/> </typeparam>
|
||||||
/// <param name="logMe">The logger</param>
|
/// <param name="logMe">The logger</param>
|
||||||
/// <param name="completedAction">An additional event handler to handle <see cref="IProcessable.Completed"/></param>
|
/// <param name="completedAction">An additional event handler to handle <see cref="IProcessable.Completed"/></param>
|
||||||
/// <returns>A new <see cref="IStreamProcessable"/> of type <typeparamref name="TStrProc"/></returns>
|
/// <returns>A new <see cref="IProcessable"/> of type <typeparamref name="TStrProc"/></returns>
|
||||||
private static TStrProc CreateStreamProcessable<TStrProc, TForm>(LogMe logMe, EventHandler<LibraryBook> completedAction = null)
|
private static TStrProc CreateProcessable<TStrProc, TForm>(LogMe logMe, EventHandler<LibraryBook> completedAction = null)
|
||||||
where TForm : LiberationBaseForm, new()
|
where TForm : LiberationBaseForm, new()
|
||||||
where TStrProc : IStreamProcessable, new()
|
where TStrProc : IProcessable, new()
|
||||||
{
|
{
|
||||||
var strProc = new TStrProc();
|
var strProc = new TStrProc();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user