Replaced LiberatedState with LiberatedStatus and PdfState with LiberatedStatus?

This commit is contained in:
Michael Bucari-Tovo 2021-08-21 16:27:33 -06:00
parent c8e2418af7
commit 1369ee575a
4 changed files with 36 additions and 37 deletions

View File

@ -11,13 +11,6 @@ using Serilog;
namespace ApplicationServices namespace ApplicationServices
{ {
// subtly different from DataLayer.LiberatedStatus
// - DataLayer.LiberatedStatus: has no concept of partially downloaded
// - ApplicationServices.LiberatedState: has no concept of Error/skipped
public enum LiberatedState { NotDownloaded, PartialDownload, Liberated }
public enum PdfState { NoPdf, Downloaded, NotDownloaded }
public static class LibraryCommands public static class LibraryCommands
{ {
private static LibraryOptions.ResponseGroupOptions LibraryResponseGroups = LibraryOptions.ResponseGroupOptions.ALL_OPTIONS; private static LibraryOptions.ResponseGroupOptions LibraryResponseGroups = LibraryOptions.ResponseGroupOptions.ALL_OPTIONS;
@ -257,15 +250,15 @@ namespace ApplicationServices
// below are queries, not commands. maybe I should make a LibraryQueries. except there's already one of those... // below are queries, not commands. maybe I should make a LibraryQueries. except there's already one of those...
public static LiberatedState Liberated_Status(Book book) public static LiberatedStatus Liberated_Status(Book book)
=> book.Audio_Exists ? LiberatedState.Liberated => book.Audio_Exists ? LiberatedStatus.Liberated
: FileManager.AudibleFileStorage.AaxcExists(book.AudibleProductId) ? LiberatedState.PartialDownload : FileManager.AudibleFileStorage.AaxcExists(book.AudibleProductId) ? LiberatedStatus.PartialDownload
: LiberatedState.NotDownloaded; : LiberatedStatus.NotLiberated;
public static PdfState Pdf_Status(Book book) public static LiberatedStatus? Pdf_Status(Book book)
=> !book.Supplements.Any() ? PdfState.NoPdf => !book.Supplements.Any() ? null
: book.PDF_Exists ? PdfState.Downloaded : book.PDF_Exists ? LiberatedStatus.Liberated
: PdfState.NotDownloaded; : LiberatedStatus.NotLiberated;
public record LibraryStats(int booksFullyBackedUp, int booksDownloadedOnly, int booksNoProgress, int pdfsDownloaded, int pdfsNotDownloaded) { } public record LibraryStats(int booksFullyBackedUp, int booksDownloadedOnly, int booksNoProgress, int pdfsDownloaded, int pdfsNotDownloaded) { }
public static LibraryStats GetCounts() public static LibraryStats GetCounts()
@ -276,9 +269,9 @@ namespace ApplicationServices
.AsParallel() .AsParallel()
.Select(lb => Liberated_Status(lb.Book)) .Select(lb => Liberated_Status(lb.Book))
.ToList(); .ToList();
var booksFullyBackedUp = results.Count(r => r == LiberatedState.Liberated); var booksFullyBackedUp = results.Count(r => r == LiberatedStatus.Liberated);
var booksDownloadedOnly = results.Count(r => r == LiberatedState.PartialDownload); var booksDownloadedOnly = results.Count(r => r == LiberatedStatus.PartialDownload);
var booksNoProgress = results.Count(r => r == LiberatedState.NotDownloaded); var booksNoProgress = results.Count(r => r == LiberatedStatus.NotLiberated);
Log.Logger.Information("Book counts. {@DebugInfo}", new { total = results.Count, booksFullyBackedUp, booksDownloadedOnly, booksNoProgress }); Log.Logger.Information("Book counts. {@DebugInfo}", new { total = results.Count, booksFullyBackedUp, booksDownloadedOnly, booksNoProgress });
@ -287,8 +280,8 @@ namespace ApplicationServices
.Where(lb => lb.Book.Supplements.Any()) .Where(lb => lb.Book.Supplements.Any())
.Select(lb => Pdf_Status(lb.Book)) .Select(lb => Pdf_Status(lb.Book))
.ToList(); .ToList();
var pdfsDownloaded = boolResults.Count(r => r == PdfState.Downloaded); var pdfsDownloaded = boolResults.Count(r => r == LiberatedStatus.Liberated);
var pdfsNotDownloaded = boolResults.Count(r => r == PdfState.NotDownloaded); var pdfsNotDownloaded = boolResults.Count(r => r == LiberatedStatus.NotLiberated);
Log.Logger.Information("PDF counts. {@DebugInfo}", new { total = boolResults.Count, pdfsDownloaded, pdfsNotDownloaded }); Log.Logger.Information("PDF counts. {@DebugInfo}", new { total = boolResults.Count, pdfsDownloaded, pdfsNotDownloaded });

View File

@ -14,7 +14,11 @@ namespace DataLayer
NotLiberated = 0, NotLiberated = 0,
Liberated = 1, Liberated = 1,
/// <summary>Error occurred during liberation. Don't retry</summary> /// <summary>Error occurred during liberation. Don't retry</summary>
Error = 2 Error = 2,
/// <summary>Application-state only. Not a valid persistence state.</summary>
PartialDownload = 0x1000
} }
public class UserDefinedItem public class UserDefinedItem

View File

@ -71,7 +71,6 @@ namespace LibationWinForms
} }
#region Data Source properties #region Data Source properties
public Image Cover public Image Cover
{ {
get get
@ -97,7 +96,7 @@ namespace LibationWinForms
public string Misc { get; } public string Misc { get; }
public string Description { get; } public string Description { get; }
public string DisplayTags => string.Join("\r\n", Book.UserDefinedItem.TagsEnumerated); public string DisplayTags => string.Join("\r\n", Book.UserDefinedItem.TagsEnumerated);
public (LiberatedState, PdfState) Liberate => (LibraryCommands.Liberated_Status(Book), LibraryCommands.Pdf_Status(Book)); public (LiberatedStatus BookStatus, LiberatedStatus? PdfStatus) Liberate => (LibraryCommands.Liberated_Status(Book), LibraryCommands.Pdf_Status(Book));
#endregion #endregion
#region Data Sorting #region Data Sorting
@ -121,7 +120,7 @@ namespace LibationWinForms
{ nameof(Category), () => Category }, { nameof(Category), () => Category },
{ nameof(Misc), () => Misc }, { nameof(Misc), () => Misc },
{ nameof(DisplayTags), () => DisplayTags }, { nameof(DisplayTags), () => DisplayTags },
{ nameof(Liberate), () => Liberate.Item1 } { nameof(Liberate), () => Liberate.BookStatus }
}; };
// Instantiate comparers for every exposed member object type. // Instantiate comparers for every exposed member object type.
@ -131,7 +130,7 @@ namespace LibationWinForms
{ typeof(int), new ObjectComparer<int>() }, { typeof(int), new ObjectComparer<int>() },
{ typeof(float), new ObjectComparer<float>() }, { typeof(float), new ObjectComparer<float>() },
{ typeof(DateTime), new ObjectComparer<DateTime>() }, { typeof(DateTime), new ObjectComparer<DateTime>() },
{ typeof(LiberatedState), new ObjectComparer<LiberatedState>() }, { typeof(LiberatedStatus), new ObjectComparer<LiberatedStatus>() },
}; };
public virtual object GetMemberValue(string memberName) => _memberValues[memberName](); public virtual object GetMemberValue(string memberName) => _memberValues[memberName]();

View File

@ -3,6 +3,7 @@ using System;
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using System.Linq; using System.Linq;
using DataLayer;
namespace LibationWinForms namespace LibationWinForms
{ {
@ -20,9 +21,11 @@ namespace LibationWinForms
{ {
base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, null, null, null, cellStyle, advancedBorderStyle, paintParts); base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, null, null, null, cellStyle, advancedBorderStyle, paintParts);
if (value is (LiberatedState liberatedState, PdfState pdfState)) if (value is (LiberatedStatus, LiberatedStatus) or (LiberatedStatus, null))
{ {
(string mouseoverText, Bitmap buttonImage) = GetLiberateDisplay(liberatedState, pdfState); var (bookState, pdfState) = ((LiberatedStatus bookState, LiberatedStatus? pdfState))value;
(string mouseoverText, Bitmap buttonImage) = GetLiberateDisplay(bookState, pdfState);
DrawButtonImage(graphics, buttonImage, cellBounds); DrawButtonImage(graphics, buttonImage, cellBounds);
@ -30,29 +33,29 @@ namespace LibationWinForms
} }
} }
private static (string mouseoverText, Bitmap buttonImage) GetLiberateDisplay(LiberatedState liberatedStatus, PdfState pdfStatus) private static (string mouseoverText, Bitmap buttonImage) GetLiberateDisplay(LiberatedStatus liberatedStatus, LiberatedStatus? pdfStatus)
{ {
(string libState, string image_lib) = liberatedStatus switch (string libState, string image_lib) = liberatedStatus switch
{ {
LiberatedState.Liberated => ("Liberated", "green"), LiberatedStatus.Liberated => ("Liberated", "green"),
LiberatedState.PartialDownload => ("File has been at least\r\npartially downloaded", "yellow"), LiberatedStatus.PartialDownload => ("File has been at least\r\npartially downloaded", "yellow"),
LiberatedState.NotDownloaded => ("Book NOT downloaded", "red"), LiberatedStatus.NotLiberated => ("Book NOT downloaded", "red"),
_ => throw new Exception("Unexpected liberation state") _ => throw new Exception("Unexpected liberation state")
}; };
(string pdfState, string image_pdf) = pdfStatus switch (string pdfState, string image_pdf) = pdfStatus switch
{ {
PdfState.Downloaded => ("\r\nPDF downloaded", "_pdf_yes"), LiberatedStatus.Liberated => ("\r\nPDF downloaded", "_pdf_yes"),
PdfState.NotDownloaded => ("\r\nPDF NOT downloaded", "_pdf_no"), LiberatedStatus.NotLiberated => ("\r\nPDF NOT downloaded", "_pdf_no"),
PdfState.NoPdf => ("", ""), null => ("", ""),
_ => throw new Exception("Unexpected PDF state") _ => throw new Exception("Unexpected PDF state")
}; };
var mouseoverText = libState + pdfState; var mouseoverText = libState + pdfState;
if (liberatedStatus == LiberatedState.NotDownloaded || if (liberatedStatus == LiberatedStatus.NotLiberated ||
liberatedStatus == LiberatedState.PartialDownload || liberatedStatus == LiberatedStatus.PartialDownload ||
pdfStatus == PdfState.NotDownloaded) pdfStatus == LiberatedStatus.NotLiberated)
mouseoverText += "\r\nClick to complete"; mouseoverText += "\r\nClick to complete";
var buttonImage = (Bitmap)Properties.Resources.ResourceManager.GetObject($"liberate_{image_lib}{image_pdf}"); var buttonImage = (Bitmap)Properties.Resources.ResourceManager.GetObject($"liberate_{image_lib}{image_pdf}");