From 31812bc2d9518196b0f1ba902a653ab2085d2484 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Wed, 8 Jun 2022 09:24:06 -0600 Subject: [PATCH] Refactoring --- Source/LibationWinForms/GridView/GridEntry.cs | 25 ++++---- .../GridView/LibraryBookEntry.cs | 11 ++-- .../LibationWinForms/GridView/SeriesEntry.cs | 12 +++- .../ProcessQueue/ProcessQueueControl.cs | 59 ++++--------------- 4 files changed, 40 insertions(+), 67 deletions(-) diff --git a/Source/LibationWinForms/GridView/GridEntry.cs b/Source/LibationWinForms/GridView/GridEntry.cs index 69a23e10..8e5702e1 100644 --- a/Source/LibationWinForms/GridView/GridEntry.cs +++ b/Source/LibationWinForms/GridView/GridEntry.cs @@ -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 /// The View Model base for the DataGridView 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 - /// - /// This information should not change during lifetime, so call only once. - /// + /// This information should not change during lifetime, so call only once. protected static string GetDescriptionDisplay(Book book) { var doc = new HtmlAgilityPack.HtmlDocument(); diff --git a/Source/LibationWinForms/GridView/LibraryBookEntry.cs b/Source/LibationWinForms/GridView/LibraryBookEntry.cs index cddde1f5..5cda59ea 100644 --- a/Source/LibationWinForms/GridView/LibraryBookEntry.cs +++ b/Source/LibationWinForms/GridView/LibraryBookEntry.cs @@ -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 /// The View Model for a LibraryBook that is ContentType.Product or ContentType.Episode 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); diff --git a/Source/LibationWinForms/GridView/SeriesEntry.cs b/Source/LibationWinForms/GridView/SeriesEntry.cs index e6882d77..c22368cb 100644 --- a/Source/LibationWinForms/GridView/SeriesEntry.cs +++ b/Source/LibationWinForms/GridView/SeriesEntry.cs @@ -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 /// The View Model for a LibraryBook that is ContentType.Parent public class SeriesEntry : GridEntry { - public List Children { get; } - public override DateTime DateAdded => Children.Max(c => c.DateAdded); - public override string DisplayTags { get; } = string.Empty; + [Browsable(false)] public List 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) { diff --git a/Source/LibationWinForms/ProcessQueue/ProcessQueueControl.cs b/Source/LibationWinForms/ProcessQueue/ProcessQueueControl.cs index 7da03da5..f698e29b 100644 --- a/Source/LibationWinForms/ProcessQueue/ProcessQueueControl.cs +++ b/Source/LibationWinForms/ProcessQueue/ProcessQueueControl.cs @@ -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() { libraryBook }); + + public void AddDownloadDecrypt(DataLayer.LibraryBook libraryBook) + => AddDownloadDecrypt(new List() { libraryBook }); + + public void AddConvertMp3(DataLayer.LibraryBook libraryBook) + => AddConvertMp3(new List() { libraryBook }); + public void AddDownloadPdf(IEnumerable entries) { List 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 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)