Refinment
This commit is contained in:
parent
1c239dc546
commit
79ed92f303
@ -13,7 +13,7 @@
|
||||
<!-- <PublishSingleFile>true</PublishSingleFile> -->
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
|
||||
<Version>5.4.9.252</Version>
|
||||
<Version>5.4.9.253</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
|
||||
@ -63,7 +63,6 @@ namespace LibationLauncher
|
||||
#if !DEBUG
|
||||
checkForUpdate(config);
|
||||
#endif
|
||||
|
||||
Application.Run(new Form1());
|
||||
}
|
||||
|
||||
|
||||
@ -71,7 +71,6 @@ namespace LibationWinForms.BookLiberation
|
||||
var backupBook = CreateBackupBook(completedAction, logMe);
|
||||
|
||||
await new BackupLoop(logMe, backupBook, automatedBackupsForm).RunBackupAsync();
|
||||
|
||||
}
|
||||
|
||||
public static async Task ConvertAllBooksAsync()
|
||||
@ -86,6 +85,33 @@ namespace LibationWinForms.BookLiberation
|
||||
await new BackupLoop(logMe, convertBook, automatedBackupsForm).RunBackupAsync();
|
||||
}
|
||||
|
||||
public static async Task BackupAllPdfsAsync(EventHandler<LibraryBook> completedAction = null)
|
||||
{
|
||||
Serilog.Log.Logger.Information("Begin " + nameof(BackupAllPdfsAsync));
|
||||
|
||||
var automatedBackupsForm = new AutomatedBackupsForm();
|
||||
LogMe logMe = LogMe.RegisterForm(automatedBackupsForm);
|
||||
|
||||
var downloadPdf = CreateStreamProcessable<DownloadPdf, PdfDownloadForm>(completedAction, logMe);
|
||||
|
||||
await new BackupLoop(logMe, downloadPdf, automatedBackupsForm).RunBackupAsync();
|
||||
}
|
||||
|
||||
public static void DownloadFile(string url, string destination, bool showDownloadCompletedDialog = false)
|
||||
{
|
||||
void onDownloadFileStreamingCompleted(object o, string s)
|
||||
{
|
||||
if (showDownloadCompletedDialog)
|
||||
MessageBox.Show("File downloaded to:\r\n\r\n" + s);
|
||||
}
|
||||
|
||||
DownloadFile downloadFile = CreateStreamable<DownloadFile, DownloadForm>(onDownloadFileStreamingCompleted);
|
||||
|
||||
new System.Threading.Thread(() => downloadFile.PerformDownloadFileAsync(url, destination).GetAwaiter().GetResult())
|
||||
{ IsBackground = true }
|
||||
.Start();
|
||||
}
|
||||
|
||||
private static IProcessable CreateBackupBook(EventHandler<LibraryBook> completedAction, LogMe logMe)
|
||||
{
|
||||
var downloadPdf = CreateStreamProcessable<DownloadPdf, PdfDownloadForm>(null, logMe);
|
||||
@ -102,39 +128,11 @@ namespace LibationWinForms.BookLiberation
|
||||
return downloadDecryptBook;
|
||||
}
|
||||
|
||||
public static async Task BackupAllPdfsAsync(EventHandler<LibraryBook> completedAction = null)
|
||||
{
|
||||
Serilog.Log.Logger.Information("Begin " + nameof(BackupAllPdfsAsync));
|
||||
|
||||
var automatedBackupsForm = new AutomatedBackupsForm();
|
||||
LogMe logMe = LogMe.RegisterForm(automatedBackupsForm);
|
||||
|
||||
var downloadPdf = CreateStreamProcessable<DownloadPdf, DownloadForm>(completedAction, logMe);
|
||||
|
||||
await new BackupLoop(logMe, downloadPdf, automatedBackupsForm).RunBackupAsync();
|
||||
}
|
||||
|
||||
public static void DownloadFile(string url, string destination, bool showDownloadCompletedDialog = false)
|
||||
{
|
||||
void OnCompleted(object o, string s)
|
||||
{
|
||||
if (showDownloadCompletedDialog)
|
||||
MessageBox.Show("File downloaded to:\r\n\r\n" + s);
|
||||
}
|
||||
|
||||
(DownloadFile downloadFile, DownloadForm downloadForm) = CreateStreamable<DownloadFile, DownloadForm>(OnCompleted);
|
||||
|
||||
new System.Threading.Thread(() =>downloadFile.PerformDownloadFileAsync(url, destination).GetAwaiter().GetResult())
|
||||
{ IsBackground = true }
|
||||
.Start();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="IStreamProcessable"/> and links it to a new <see cref="ProcessBaseForm"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="TStrProc">The <see cref="IStreamProcessable"/> derrived type to create.</typeparam>
|
||||
/// <typeparam name="TForm">The <see cref="ProcessBaseForm"/> derrived form to create on <see cref="IProcessable.Begin"/> and and be Shown on <see cref="IStreamable.StreamingBegin"/></typeparam>
|
||||
/// <typeparam name="TForm">The <see cref="ProcessBaseForm"/> derrived Form to create on <see cref="IProcessable.Begin"/> and and be Shown on <see cref="IStreamable.StreamingBegin"/></typeparam>
|
||||
/// <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>
|
||||
private static TStrProc CreateStreamProcessable<TStrProc, TForm>(EventHandler<LibraryBook> completedAction = null, LogMe logMe = null)
|
||||
@ -146,7 +144,6 @@ namespace LibationWinForms.BookLiberation
|
||||
strProc.Begin += (sender, libraryBook) =>
|
||||
{
|
||||
var processForm = new TForm();
|
||||
Action<string> logAction = logMe is null ? (s) => { } : logMe.Info;
|
||||
processForm.SetProcessable(strProc, logMe);
|
||||
processForm.OnBegin(sender, libraryBook);
|
||||
};
|
||||
@ -161,21 +158,21 @@ namespace LibationWinForms.BookLiberation
|
||||
/// Creates a new <see cref="IStreamable"/> and links it to a new <see cref="StreamBaseForm"/>
|
||||
/// </summary>
|
||||
/// <typeparam name="TStrProc">The <see cref="IStreamable"/> derrived type to create.</typeparam>
|
||||
/// <typeparam name="TForm">The <see cref="StreamBaseForm"/> derrived form to create, which will be Shown on <see cref="IStreamable.StreamingBegin"/>.</typeparam>
|
||||
/// <typeparam name="TForm">The <see cref="StreamBaseForm"/> derrived Form to create, which will be Shown on <see cref="IStreamable.StreamingBegin"/>.</typeparam>
|
||||
/// <param name="completedAction">An additional event handler to handle <see cref="IStreamable.StreamingCompleted"/></param>
|
||||
private static (TStrProc, TForm) CreateStreamable<TStrProc, TForm>(EventHandler<string> completedAction = null)
|
||||
private static TStrProc CreateStreamable<TStrProc, TForm>(EventHandler<string> completedAction = null)
|
||||
where TForm : StreamBaseForm, new()
|
||||
where TStrProc : IStreamable, new()
|
||||
{
|
||||
var strProc = new TStrProc();
|
||||
var streamable = new TStrProc();
|
||||
|
||||
var streamForm = new TForm();
|
||||
streamForm.SetStreamable(strProc);
|
||||
streamForm.SetStreamable(streamable);
|
||||
|
||||
if (completedAction != null)
|
||||
strProc.StreamingCompleted += completedAction;
|
||||
streamable.StreamingCompleted += completedAction;
|
||||
|
||||
return (strProc, streamForm);
|
||||
return streamable;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user