Refactoring

This commit is contained in:
Michael Bucari-Tovo 2022-06-08 09:24:06 -06:00
parent 30ba69eca7
commit 31812bc2d9
4 changed files with 40 additions and 67 deletions

View File

@ -6,6 +6,7 @@ using LibationFileManager;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
@ -14,11 +15,16 @@ namespace LibationWinForms.GridView
/// <summary>The View Model base for the DataGridView</summary>
public abstract class GridEntry : AsyncNotifyPropertyChanged, IMemberComparable
{
public string AudibleProductId => Book.AudibleProductId;
public LibraryBook LibraryBook { get; protected set; }
protected Book Book => LibraryBook.Book;
[Browsable(false)] public string AudibleProductId => Book.AudibleProductId;
[Browsable(false)] public LibraryBook LibraryBook { get; protected set; }
[Browsable(false)] public float SeriesIndex { get; protected set; }
[Browsable(false)] public string LongDescription { get; protected set; }
[Browsable(false)] public abstract DateTime DateAdded { get; }
[Browsable(false)] protected Book Book => LibraryBook.Book;
#region Model properties exposed to the view
public abstract LiberateButtonStatus Liberate { get; }
public Image Cover
{
get => _cover;
@ -28,10 +34,7 @@ namespace LibationWinForms.GridView
NotifyPropertyChanged();
}
}
public float SeriesIndex { get; protected set; }
public string ProductRating { get; protected set; }
public string PurchaseDate { get; protected set; }
public string MyRating { get; protected set; }
public string Series { get; protected set; }
public string Title { get; protected set; }
public string Length { get; protected set; }
@ -40,10 +43,10 @@ namespace LibationWinForms.GridView
public string Category { get; protected set; }
public string Misc { get; protected set; }
public string Description { get; protected set; }
public string LongDescription { get; protected set; }
public abstract DateTime DateAdded { get; }
public string ProductRating { get; protected set; }
public string MyRating { get; protected set; }
public abstract string DisplayTags { get; }
public abstract LiberateButtonStatus Liberate { get; }
#endregion
#region Sorting
@ -98,9 +101,7 @@ namespace LibationWinForms.GridView
#region Static library display functions
/// <summary>
/// This information should not change during <see cref="GridEntry"/> lifetime, so call only once.
/// </summary>
/// <summary>This information should not change during <see cref="GridEntry"/> lifetime, so call only once.</summary>
protected static string GetDescriptionDisplay(Book book)
{
var doc = new HtmlAgilityPack.HtmlDocument();

View File

@ -3,6 +3,7 @@ using DataLayer;
using Dinah.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
namespace LibationWinForms.GridView
@ -10,15 +11,16 @@ namespace LibationWinForms.GridView
/// <summary>The View Model for a LibraryBook that is ContentType.Product or ContentType.Episode</summary>
public class LibraryBookEntry : GridEntry
{
[Browsable(false)] public override DateTime DateAdded => LibraryBook.DateAdded;
[Browsable(false)] public SeriesEntry Parent { get; init; }
#region Model properties exposed to the view
private DateTime lastStatusUpdate = default;
private LiberatedStatus _bookStatus;
private LiberatedStatus? _pdfStatus;
public override DateTime DateAdded => LibraryBook.DateAdded;
public override string DisplayTags => string.Join("\r\n", Book.UserDefinedItem.TagsEnumerated);
public override LiberateButtonStatus Liberate
{
get
@ -33,11 +35,10 @@ namespace LibationWinForms.GridView
return new LiberateButtonStatus { BookStatus = _bookStatus, PdfStatus = _pdfStatus, IsSeries = false };
}
}
public override string DisplayTags => string.Join("\r\n", Book.UserDefinedItem.TagsEnumerated);
#endregion
public SeriesEntry Parent { get; init; }
public LibraryBookEntry(LibraryBook libraryBook)
{
setLibraryBook(libraryBook);

View File

@ -2,6 +2,7 @@
using Dinah.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
namespace LibationWinForms.GridView
@ -9,10 +10,15 @@ namespace LibationWinForms.GridView
/// <summary>The View Model for a LibraryBook that is ContentType.Parent</summary>
public class SeriesEntry : GridEntry
{
public List<LibraryBookEntry> Children { get; }
public override DateTime DateAdded => Children.Max(c => c.DateAdded);
public override string DisplayTags { get; } = string.Empty;
[Browsable(false)] public List<LibraryBookEntry> Children { get; }
[Browsable(false)] public override DateTime DateAdded => Children.Max(c => c.DateAdded);
#region Model properties exposed to the view
public override LiberateButtonStatus Liberate { get; }
public override string DisplayTags { get; } = string.Empty;
#endregion
private SeriesEntry(LibraryBook parent)
{

View File

@ -80,6 +80,15 @@ namespace LibationWinForms.ProcessQueue
private bool isBookInQueue(DataLayer.LibraryBook libraryBook)
=> Queue.Any(b => b?.LibraryBook?.Book?.AudibleProductId == libraryBook.Book.AudibleProductId);
public void AddDownloadPdf(DataLayer.LibraryBook libraryBook)
=> AddDownloadPdf(new List<DataLayer.LibraryBook>() { libraryBook });
public void AddDownloadDecrypt(DataLayer.LibraryBook libraryBook)
=> AddDownloadDecrypt(new List<DataLayer.LibraryBook>() { libraryBook });
public void AddConvertMp3(DataLayer.LibraryBook libraryBook)
=> AddConvertMp3(new List<DataLayer.LibraryBook>() { libraryBook });
public void AddDownloadPdf(IEnumerable<DataLayer.LibraryBook> entries)
{
List<ProcessBook> procs = new();
@ -132,40 +141,6 @@ namespace LibationWinForms.ProcessQueue
AddToQueue(procs);
}
public void AddDownloadPdf(DataLayer.LibraryBook libraryBook)
{
if (isBookInQueue(libraryBook))
return;
ProcessBook pbook = new(libraryBook, Logger);
pbook.PropertyChanged += Pbook_DataAvailable;
pbook.AddDownloadPdf();
AddToQueue(pbook);
}
public void AddDownloadDecrypt(DataLayer.LibraryBook libraryBook)
{
if (isBookInQueue(libraryBook))
return;
ProcessBook pbook = new(libraryBook, Logger);
pbook.PropertyChanged += Pbook_DataAvailable;
pbook.AddDownloadDecryptBook();
pbook.AddDownloadPdf();
AddToQueue(pbook);
}
public void AddConvertMp3(DataLayer.LibraryBook libraryBook)
{
if (isBookInQueue(libraryBook))
return;
ProcessBook pbook = new(libraryBook, Logger);
pbook.PropertyChanged += Pbook_DataAvailable;
pbook.AddConvertToMp3();
AddToQueue(pbook);
}
private void AddToQueue(IEnumerable<ProcessBook> pbook)
{
syncContext.Post(_ =>
@ -177,21 +152,11 @@ namespace LibationWinForms.ProcessQueue
null);
}
private void AddToQueue(ProcessBook pbook)
{
syncContext.Post(_ =>
{
Queue.Enqueue(pbook);
if (!Running)
QueueRunner = QueueLoop();
},
null);
}
DateTime StartintTime;
DateTime StartingTime;
private async Task QueueLoop()
{
StartintTime = DateTime.Now;
StartingTime = DateTime.Now;
counterTimer.Start();
while (Queue.MoveNext())
@ -273,7 +238,7 @@ namespace LibationWinForms.ProcessQueue
}
if (Running)
runningTimeLbl.Text = timeToStr(DateTime.Now - StartintTime);
runningTimeLbl.Text = timeToStr(DateTime.Now - StartingTime);
}
private void clearLogBtn_Click(object sender, EventArgs e)