Refactoring
This commit is contained in:
parent
30ba69eca7
commit
31812bc2d9
@ -6,6 +6,7 @@ using LibationFileManager;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
@ -14,11 +15,16 @@ namespace LibationWinForms.GridView
|
|||||||
/// <summary>The View Model base for the DataGridView</summary>
|
/// <summary>The View Model base for the DataGridView</summary>
|
||||||
public abstract class GridEntry : AsyncNotifyPropertyChanged, IMemberComparable
|
public abstract class GridEntry : AsyncNotifyPropertyChanged, IMemberComparable
|
||||||
{
|
{
|
||||||
public string AudibleProductId => Book.AudibleProductId;
|
[Browsable(false)] public string AudibleProductId => Book.AudibleProductId;
|
||||||
public LibraryBook LibraryBook { get; protected set; }
|
[Browsable(false)] public LibraryBook LibraryBook { get; protected set; }
|
||||||
protected Book Book => LibraryBook.Book;
|
[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
|
#region Model properties exposed to the view
|
||||||
|
|
||||||
|
public abstract LiberateButtonStatus Liberate { get; }
|
||||||
public Image Cover
|
public Image Cover
|
||||||
{
|
{
|
||||||
get => _cover;
|
get => _cover;
|
||||||
@ -28,10 +34,7 @@ namespace LibationWinForms.GridView
|
|||||||
NotifyPropertyChanged();
|
NotifyPropertyChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public float SeriesIndex { get; protected set; }
|
|
||||||
public string ProductRating { get; protected set; }
|
|
||||||
public string PurchaseDate { get; protected set; }
|
public string PurchaseDate { get; protected set; }
|
||||||
public string MyRating { get; protected set; }
|
|
||||||
public string Series { get; protected set; }
|
public string Series { get; protected set; }
|
||||||
public string Title { get; protected set; }
|
public string Title { get; protected set; }
|
||||||
public string Length { get; protected set; }
|
public string Length { get; protected set; }
|
||||||
@ -40,10 +43,10 @@ namespace LibationWinForms.GridView
|
|||||||
public string Category { get; protected set; }
|
public string Category { get; protected set; }
|
||||||
public string Misc { get; protected set; }
|
public string Misc { get; protected set; }
|
||||||
public string Description { get; protected set; }
|
public string Description { get; protected set; }
|
||||||
public string LongDescription { get; protected set; }
|
public string ProductRating { get; protected set; }
|
||||||
public abstract DateTime DateAdded { get; }
|
public string MyRating { get; protected set; }
|
||||||
public abstract string DisplayTags { get; }
|
public abstract string DisplayTags { get; }
|
||||||
public abstract LiberateButtonStatus Liberate { get; }
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Sorting
|
#region Sorting
|
||||||
@ -98,9 +101,7 @@ namespace LibationWinForms.GridView
|
|||||||
|
|
||||||
#region Static library display functions
|
#region Static library display functions
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>This information should not change during <see cref="GridEntry"/> lifetime, so call only once.</summary>
|
||||||
/// This information should not change during <see cref="GridEntry"/> lifetime, so call only once.
|
|
||||||
/// </summary>
|
|
||||||
protected static string GetDescriptionDisplay(Book book)
|
protected static string GetDescriptionDisplay(Book book)
|
||||||
{
|
{
|
||||||
var doc = new HtmlAgilityPack.HtmlDocument();
|
var doc = new HtmlAgilityPack.HtmlDocument();
|
||||||
|
|||||||
@ -3,6 +3,7 @@ using DataLayer;
|
|||||||
using Dinah.Core;
|
using Dinah.Core;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace LibationWinForms.GridView
|
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>
|
/// <summary>The View Model for a LibraryBook that is ContentType.Product or ContentType.Episode</summary>
|
||||||
public class LibraryBookEntry : GridEntry
|
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
|
#region Model properties exposed to the view
|
||||||
|
|
||||||
private DateTime lastStatusUpdate = default;
|
private DateTime lastStatusUpdate = default;
|
||||||
private LiberatedStatus _bookStatus;
|
private LiberatedStatus _bookStatus;
|
||||||
private LiberatedStatus? _pdfStatus;
|
private LiberatedStatus? _pdfStatus;
|
||||||
|
|
||||||
public override DateTime DateAdded => LibraryBook.DateAdded;
|
|
||||||
public override string DisplayTags => string.Join("\r\n", Book.UserDefinedItem.TagsEnumerated);
|
|
||||||
|
|
||||||
public override LiberateButtonStatus Liberate
|
public override LiberateButtonStatus Liberate
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -33,11 +35,10 @@ namespace LibationWinForms.GridView
|
|||||||
return new LiberateButtonStatus { BookStatus = _bookStatus, PdfStatus = _pdfStatus, IsSeries = false };
|
return new LiberateButtonStatus { BookStatus = _bookStatus, PdfStatus = _pdfStatus, IsSeries = false };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public override string DisplayTags => string.Join("\r\n", Book.UserDefinedItem.TagsEnumerated);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public SeriesEntry Parent { get; init; }
|
|
||||||
|
|
||||||
public LibraryBookEntry(LibraryBook libraryBook)
|
public LibraryBookEntry(LibraryBook libraryBook)
|
||||||
{
|
{
|
||||||
setLibraryBook(libraryBook);
|
setLibraryBook(libraryBook);
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
using Dinah.Core;
|
using Dinah.Core;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace LibationWinForms.GridView
|
namespace LibationWinForms.GridView
|
||||||
@ -9,10 +10,15 @@ namespace LibationWinForms.GridView
|
|||||||
/// <summary>The View Model for a LibraryBook that is ContentType.Parent</summary>
|
/// <summary>The View Model for a LibraryBook that is ContentType.Parent</summary>
|
||||||
public class SeriesEntry : GridEntry
|
public class SeriesEntry : GridEntry
|
||||||
{
|
{
|
||||||
public List<LibraryBookEntry> Children { get; }
|
[Browsable(false)] public List<LibraryBookEntry> Children { get; }
|
||||||
public override DateTime DateAdded => Children.Max(c => c.DateAdded);
|
[Browsable(false)] public override DateTime DateAdded => Children.Max(c => c.DateAdded);
|
||||||
public override string DisplayTags { get; } = string.Empty;
|
|
||||||
|
#region Model properties exposed to the view
|
||||||
|
|
||||||
public override LiberateButtonStatus Liberate { get; }
|
public override LiberateButtonStatus Liberate { get; }
|
||||||
|
public override string DisplayTags { get; } = string.Empty;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
private SeriesEntry(LibraryBook parent)
|
private SeriesEntry(LibraryBook parent)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -80,6 +80,15 @@ namespace LibationWinForms.ProcessQueue
|
|||||||
private bool isBookInQueue(DataLayer.LibraryBook libraryBook)
|
private bool isBookInQueue(DataLayer.LibraryBook libraryBook)
|
||||||
=> Queue.Any(b => b?.LibraryBook?.Book?.AudibleProductId == libraryBook.Book.AudibleProductId);
|
=> 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)
|
public void AddDownloadPdf(IEnumerable<DataLayer.LibraryBook> entries)
|
||||||
{
|
{
|
||||||
List<ProcessBook> procs = new();
|
List<ProcessBook> procs = new();
|
||||||
@ -132,40 +141,6 @@ namespace LibationWinForms.ProcessQueue
|
|||||||
AddToQueue(procs);
|
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)
|
private void AddToQueue(IEnumerable<ProcessBook> pbook)
|
||||||
{
|
{
|
||||||
syncContext.Post(_ =>
|
syncContext.Post(_ =>
|
||||||
@ -177,21 +152,11 @@ namespace LibationWinForms.ProcessQueue
|
|||||||
null);
|
null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddToQueue(ProcessBook pbook)
|
|
||||||
{
|
|
||||||
syncContext.Post(_ =>
|
|
||||||
{
|
|
||||||
Queue.Enqueue(pbook);
|
|
||||||
if (!Running)
|
|
||||||
QueueRunner = QueueLoop();
|
|
||||||
},
|
|
||||||
null);
|
|
||||||
}
|
|
||||||
|
|
||||||
DateTime StartintTime;
|
DateTime StartingTime;
|
||||||
private async Task QueueLoop()
|
private async Task QueueLoop()
|
||||||
{
|
{
|
||||||
StartintTime = DateTime.Now;
|
StartingTime = DateTime.Now;
|
||||||
counterTimer.Start();
|
counterTimer.Start();
|
||||||
|
|
||||||
while (Queue.MoveNext())
|
while (Queue.MoveNext())
|
||||||
@ -273,7 +238,7 @@ namespace LibationWinForms.ProcessQueue
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Running)
|
if (Running)
|
||||||
runningTimeLbl.Text = timeToStr(DateTime.Now - StartintTime);
|
runningTimeLbl.Text = timeToStr(DateTime.Now - StartingTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearLogBtn_Click(object sender, EventArgs e)
|
private void clearLogBtn_Click(object sender, EventArgs e)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user