Add error handling around all ui click handlers for book downloads.
This commit is contained in:
parent
0fe07695b2
commit
76b5e09f72
@ -88,5 +88,13 @@ namespace DataLayer
|
|||||||
s.Series.AudibleSeriesId == parent.Book.AudibleProductId
|
s.Series.AudibleSeriesId == parent.Book.AudibleProductId
|
||||||
) == true
|
) == true
|
||||||
).ToList();
|
).ToList();
|
||||||
|
|
||||||
|
public static IEnumerable<LibraryBook> UnLiberated(this IEnumerable<LibraryBook> bookList)
|
||||||
|
=> bookList
|
||||||
|
.Where(
|
||||||
|
lb =>
|
||||||
|
lb.Book.UserDefinedItem.BookStatus is LiberatedStatus.NotLiberated or LiberatedStatus.PartialDownload
|
||||||
|
|| lb.Book.UserDefinedItem.PdfStatus is LiberatedStatus.NotLiberated or LiberatedStatus.PartialDownload
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using DataLayer;
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
@ -10,11 +11,24 @@ namespace LibationWinForms
|
|||||||
private void Configure_Liberate() { }
|
private void Configure_Liberate() { }
|
||||||
|
|
||||||
//GetLibrary_Flat_NoTracking() may take a long time on a hugh library. so run in new thread
|
//GetLibrary_Flat_NoTracking() may take a long time on a hugh library. so run in new thread
|
||||||
private async void beginBookBackupsToolStripMenuItem_Click(object _ = null, EventArgs __ = null)
|
private void beginBookBackupsToolStripMenuItem_Click(object _ = null, EventArgs __ = null)
|
||||||
{
|
{
|
||||||
SetQueueCollapseState(false);
|
try
|
||||||
await Task.Run(() => processBookQueue1.AddDownloadDecrypt(ApplicationServices.DbContexts.GetLibrary_Flat_NoTracking()
|
{
|
||||||
.Where(lb => lb.Book.UserDefinedItem.PdfStatus is DataLayer.LiberatedStatus.NotLiberated || lb.Book.UserDefinedItem.BookStatus is DataLayer.LiberatedStatus.NotLiberated)));
|
SetQueueCollapseState(false);
|
||||||
|
|
||||||
|
Serilog.Log.Logger.Information("Begin backing up all library books");
|
||||||
|
|
||||||
|
processBookQueue1.AddDownloadDecrypt(
|
||||||
|
ApplicationServices.DbContexts
|
||||||
|
.GetLibrary_Flat_NoTracking()
|
||||||
|
.UnLiberated()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Serilog.Log.Logger.Error(ex, "An error occurred while backing up all library books");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void beginPdfBackupsToolStripMenuItem_Click(object sender, EventArgs e)
|
private async void beginPdfBackupsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
|||||||
@ -22,27 +22,36 @@ namespace LibationWinForms
|
|||||||
this.Width = width;
|
this.Width = width;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProductsDisplay_LiberateClicked(object sender, LibraryBook e)
|
private void ProductsDisplay_LiberateClicked(object sender, LibraryBook libraryBook)
|
||||||
{
|
{
|
||||||
if (e.Book.UserDefinedItem.BookStatus != LiberatedStatus.Liberated)
|
try
|
||||||
{
|
{
|
||||||
SetQueueCollapseState(false);
|
if (libraryBook.Book.UserDefinedItem.BookStatus is LiberatedStatus.NotLiberated or LiberatedStatus.PartialDownload)
|
||||||
processBookQueue1.AddDownloadDecrypt(e);
|
|
||||||
}
|
|
||||||
else if (e.Book.UserDefinedItem.PdfStatus is not null and LiberatedStatus.NotLiberated)
|
|
||||||
{
|
|
||||||
SetQueueCollapseState(false);
|
|
||||||
processBookQueue1.AddDownloadPdf(e);
|
|
||||||
}
|
|
||||||
else if (e.Book.Audio_Exists())
|
|
||||||
{
|
|
||||||
// liberated: open explorer to file
|
|
||||||
var filePath = AudibleFileStorage.Audio.GetPath(e.Book.AudibleProductId);
|
|
||||||
if (!Go.To.File(filePath?.ShortPathName))
|
|
||||||
{
|
{
|
||||||
var suffix = string.IsNullOrWhiteSpace(filePath) ? "" : $":\r\n{filePath}";
|
Serilog.Log.Logger.Information("Begin single book backup of {libraryBook}", libraryBook);
|
||||||
MessageBox.Show($"File not found" + suffix);
|
SetQueueCollapseState(false);
|
||||||
|
processBookQueue1.AddDownloadDecrypt(libraryBook);
|
||||||
}
|
}
|
||||||
|
else if (libraryBook.Book.UserDefinedItem.PdfStatus is LiberatedStatus.NotLiberated)
|
||||||
|
{
|
||||||
|
Serilog.Log.Logger.Information("Begin single pdf backup of {libraryBook}", libraryBook);
|
||||||
|
SetQueueCollapseState(false);
|
||||||
|
processBookQueue1.AddDownloadPdf(libraryBook);
|
||||||
|
}
|
||||||
|
else if (libraryBook.Book.Audio_Exists())
|
||||||
|
{
|
||||||
|
// liberated: open explorer to file
|
||||||
|
var filePath = AudibleFileStorage.Audio.GetPath(libraryBook.Book.AudibleProductId);
|
||||||
|
if (!Go.To.File(filePath?.ShortPathName))
|
||||||
|
{
|
||||||
|
var suffix = string.IsNullOrWhiteSpace(filePath) ? "" : $":\r\n{filePath}";
|
||||||
|
MessageBox.Show($"File not found" + suffix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Serilog.Log.Logger.Error(ex, "An error occurred while handling the stop light button click for {libraryBook}", libraryBook);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@ using System.Linq;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using ApplicationServices;
|
using ApplicationServices;
|
||||||
|
using DataLayer;
|
||||||
using Dinah.Core.Threading;
|
using Dinah.Core.Threading;
|
||||||
using LibationWinForms.Dialogs;
|
using LibationWinForms.Dialogs;
|
||||||
|
|
||||||
@ -48,10 +49,24 @@ namespace LibationWinForms
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void liberateVisible(object sender, EventArgs e)
|
private void liberateVisible(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
SetQueueCollapseState(false);
|
try
|
||||||
await Task.Run(() => processBookQueue1.AddDownloadDecrypt(productsDisplay.GetVisible()));
|
{
|
||||||
|
SetQueueCollapseState(false);
|
||||||
|
|
||||||
|
Serilog.Log.Logger.Information("Begin backing up visible library books");
|
||||||
|
|
||||||
|
processBookQueue1.AddDownloadDecrypt(
|
||||||
|
productsDisplay
|
||||||
|
.GetVisible()
|
||||||
|
.UnLiberated()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Serilog.Log.Logger.Error(ex, "An error occurred while backing up visible library books");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void replaceTagsToolStripMenuItem_Click(object sender, EventArgs e)
|
private void replaceTagsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user