Documentation and organization
This commit is contained in:
parent
a8bca3de98
commit
7f08da96bb
@ -1,6 +1,6 @@
|
||||
namespace LibationWinForms.ProcessQueue
|
||||
{
|
||||
partial class ProcessBookQueue
|
||||
partial class ProcessQueueControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
@ -28,13 +28,15 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ProcessBookQueue));
|
||||
this.components = new System.ComponentModel.Container();
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ProcessQueueControl));
|
||||
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
|
||||
this.toolStripProgressBar1 = new System.Windows.Forms.ToolStripProgressBar();
|
||||
this.queueNumberLbl = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.completedNumberLbl = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.errorNumberLbl = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.runningTimeLbl = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.tabControl1 = new System.Windows.Forms.TabControl();
|
||||
this.tabPage1 = new System.Windows.Forms.TabPage();
|
||||
this.panel3 = new System.Windows.Forms.Panel();
|
||||
@ -47,6 +49,7 @@
|
||||
this.panel2 = new System.Windows.Forms.Panel();
|
||||
this.clearLogBtn = new System.Windows.Forms.Button();
|
||||
this.logMeTbox = new System.Windows.Forms.TextBox();
|
||||
this.counterTimer = new System.Windows.Forms.Timer(this.components);
|
||||
this.statusStrip1.SuspendLayout();
|
||||
this.tabControl1.SuspendLayout();
|
||||
this.tabPage1.SuspendLayout();
|
||||
@ -63,12 +66,13 @@
|
||||
this.queueNumberLbl,
|
||||
this.completedNumberLbl,
|
||||
this.errorNumberLbl,
|
||||
this.toolStripStatusLabel1});
|
||||
this.toolStripStatusLabel1,
|
||||
this.runningTimeLbl});
|
||||
this.statusStrip1.Location = new System.Drawing.Point(0, 483);
|
||||
this.statusStrip1.Name = "statusStrip1";
|
||||
this.statusStrip1.Size = new System.Drawing.Size(404, 25);
|
||||
this.statusStrip1.TabIndex = 1;
|
||||
this.statusStrip1.Text = "statusStrip1";
|
||||
this.statusStrip1.Text = "baseStatusStrip";
|
||||
//
|
||||
// toolStripProgressBar1
|
||||
//
|
||||
@ -99,9 +103,16 @@
|
||||
// toolStripStatusLabel1
|
||||
//
|
||||
this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
|
||||
this.toolStripStatusLabel1.Size = new System.Drawing.Size(118, 20);
|
||||
this.toolStripStatusLabel1.Size = new System.Drawing.Size(77, 20);
|
||||
this.toolStripStatusLabel1.Spring = true;
|
||||
//
|
||||
// runningTimeLbl
|
||||
//
|
||||
this.runningTimeLbl.AutoSize = false;
|
||||
this.runningTimeLbl.Name = "runningTimeLbl";
|
||||
this.runningTimeLbl.Size = new System.Drawing.Size(41, 20);
|
||||
this.runningTimeLbl.Text = "[TIME]";
|
||||
//
|
||||
// tabControl1
|
||||
//
|
||||
this.tabControl1.Controls.Add(this.tabPage1);
|
||||
@ -167,7 +178,7 @@
|
||||
this.btnCleanFinished.TabIndex = 3;
|
||||
this.btnCleanFinished.Text = "Clear Finished";
|
||||
this.btnCleanFinished.UseVisualStyleBackColor = true;
|
||||
this.btnCleanFinished.Click += new System.EventHandler(this.btnCleanFinished_Click);
|
||||
this.btnCleanFinished.Click += new System.EventHandler(this.btnClearFinished_Click);
|
||||
//
|
||||
// cancelAllBtn
|
||||
//
|
||||
@ -236,6 +247,11 @@
|
||||
this.logMeTbox.Size = new System.Drawing.Size(390, 449);
|
||||
this.logMeTbox.TabIndex = 0;
|
||||
//
|
||||
// counterTimer
|
||||
//
|
||||
this.counterTimer.Interval = 950;
|
||||
this.counterTimer.Tick += new System.EventHandler(this.CounterTimer_Tick);
|
||||
//
|
||||
// ProcessBookQueue
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
@ -277,5 +293,7 @@
|
||||
private System.Windows.Forms.ToolStripStatusLabel errorNumberLbl;
|
||||
private System.Windows.Forms.Panel panel3;
|
||||
private System.Windows.Forms.Panel panel4;
|
||||
private System.Windows.Forms.ToolStripStatusLabel runningTimeLbl;
|
||||
private System.Windows.Forms.Timer counterTimer;
|
||||
}
|
||||
}
|
||||
@ -8,7 +8,7 @@ using System.Windows.Forms;
|
||||
|
||||
namespace LibationWinForms.ProcessQueue
|
||||
{
|
||||
internal partial class ProcessBookQueue : UserControl, ILogForm
|
||||
internal partial class ProcessQueueControl : UserControl, ILogForm
|
||||
{
|
||||
private TrackedQueue<ProcessBook> Queue = new();
|
||||
private readonly LogMe Logger;
|
||||
@ -45,15 +45,12 @@ namespace LibationWinForms.ProcessQueue
|
||||
|
||||
public ToolStripButton popoutBtn = new();
|
||||
|
||||
private int FirstVisible = 0;
|
||||
private int NumVisible = 0;
|
||||
private IReadOnlyList<ProcessBookControl> Panels;
|
||||
|
||||
public ProcessBookQueue()
|
||||
public ProcessQueueControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
Logger = LogMe.RegisterForm(this);
|
||||
|
||||
runningTimeLbl.Text = string.Empty;
|
||||
popoutBtn.DisplayStyle = ToolStripItemDisplayStyle.Text;
|
||||
popoutBtn.Name = "popoutBtn";
|
||||
popoutBtn.Text = "Pop Out";
|
||||
@ -74,6 +71,85 @@ namespace LibationWinForms.ProcessQueue
|
||||
CompletedCount = 0;
|
||||
}
|
||||
|
||||
public void AddDownloadDecrypt(IEnumerable<GridEntry> entries)
|
||||
{
|
||||
foreach (var entry in entries)
|
||||
AddDownloadDecrypt(entry);
|
||||
}
|
||||
|
||||
public void AddConvertMp3(IEnumerable<GridEntry> entries)
|
||||
{
|
||||
foreach (var entry in entries)
|
||||
AddConvertMp3(entry);
|
||||
}
|
||||
|
||||
public void AddDownloadDecrypt(GridEntry gridEntry)
|
||||
{
|
||||
if (Queue.Any(b => b?.LibraryBook?.Book?.AudibleProductId == gridEntry.AudibleProductId))
|
||||
return;
|
||||
|
||||
ProcessBook pbook = new(gridEntry.LibraryBook, gridEntry.Cover, Logger);
|
||||
pbook.DataAvailable += Pbook_DataAvailable;
|
||||
|
||||
pbook.AddDownloadDecryptBook();
|
||||
pbook.AddDownloadPdf();
|
||||
|
||||
Queue.Enqueue(pbook);
|
||||
|
||||
if (!Running)
|
||||
{
|
||||
QueueRunner = QueueLoop();
|
||||
}
|
||||
}
|
||||
|
||||
public void AddConvertMp3(GridEntry gridEntry)
|
||||
{
|
||||
if (Queue.Any(b => b?.LibraryBook?.Book?.AudibleProductId == gridEntry.AudibleProductId))
|
||||
return;
|
||||
|
||||
ProcessBook pbook = new(gridEntry.LibraryBook, gridEntry.Cover, Logger);
|
||||
pbook.DataAvailable += Pbook_DataAvailable;
|
||||
|
||||
pbook.AddConvertToMp3();
|
||||
|
||||
Queue.Enqueue(pbook);
|
||||
|
||||
if (!Running)
|
||||
{
|
||||
QueueRunner = QueueLoop();
|
||||
}
|
||||
}
|
||||
|
||||
DateTime StartintTime;
|
||||
private async Task QueueLoop()
|
||||
{
|
||||
StartintTime = DateTime.Now;
|
||||
counterTimer.Start();
|
||||
|
||||
while (Queue.MoveNext())
|
||||
{
|
||||
var nextBook = Queue.Current;
|
||||
|
||||
var result = await nextBook.ProcessOneAsync();
|
||||
|
||||
if (result == ProcessBookResult.FailedRetry)
|
||||
Queue.Enqueue(nextBook);
|
||||
else if (result == ProcessBookResult.FailedAbort)
|
||||
return;
|
||||
}
|
||||
|
||||
Queue_CompletedCountChanged(this, 0);
|
||||
counterTimer.Stop();
|
||||
}
|
||||
|
||||
public void WriteLine(string text)
|
||||
{
|
||||
if (!IsDisposed)
|
||||
logMeTbox.UIThreadAsync(() => logMeTbox.AppendText($"{DateTime.Now} {text}{Environment.NewLine}"));
|
||||
}
|
||||
|
||||
#region Control event handlers
|
||||
|
||||
private void Queue_CompletedCountChanged(object sender, int e)
|
||||
{
|
||||
int errCount = Queue.Completed.Count(p => p.Result is ProcessBookResult.FailedAbort or ProcessBookResult.FailedSkip or ProcessBookResult.ValidationFail);
|
||||
@ -94,45 +170,70 @@ namespace LibationWinForms.ProcessQueue
|
||||
toolStripProgressBar1.Maximum = Queue.Count;
|
||||
toolStripProgressBar1.Value = Queue.Completed.Count;
|
||||
}
|
||||
private void VirtualFlowControl2_ButtonClicked(int itemIndex, string buttonName, ProcessBookControl panelClicked)
|
||||
|
||||
private void cancelAllBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
ProcessBook item = Queue[itemIndex];
|
||||
if (buttonName == "cancelBtn")
|
||||
{
|
||||
item.Cancel();
|
||||
Queue.RemoveQueued(item);
|
||||
virtualFlowControl2.VirtualControlCount = Queue.Count;
|
||||
UpdateControl(itemIndex);
|
||||
}
|
||||
else if (buttonName == "moveFirstBtn")
|
||||
{
|
||||
Queue.MoveQueuePosition(item, QueuePosition.Fisrt);
|
||||
UpdateAllControls();
|
||||
}
|
||||
else if (buttonName == "moveUpBtn")
|
||||
{
|
||||
Queue.MoveQueuePosition(item, QueuePosition.OneUp);
|
||||
UpdateControl(itemIndex - 1);
|
||||
UpdateControl(itemIndex);
|
||||
}
|
||||
else if (buttonName == "moveDownBtn")
|
||||
{
|
||||
Queue.MoveQueuePosition(item, QueuePosition.OneDown);
|
||||
UpdateControl(itemIndex + 1);
|
||||
UpdateControl(itemIndex);
|
||||
}
|
||||
else if (buttonName == "moveLastBtn")
|
||||
{
|
||||
Queue.MoveQueuePosition(item, QueuePosition.Last);
|
||||
UpdateAllControls();
|
||||
}
|
||||
Queue.ClearQueue();
|
||||
Queue.Current?.Cancel();
|
||||
virtualFlowControl2.VirtualControlCount = Queue.Count;
|
||||
UpdateAllControls();
|
||||
}
|
||||
|
||||
private void btnClearFinished_Click(object sender, EventArgs e)
|
||||
{
|
||||
Queue.ClearCompleted();
|
||||
virtualFlowControl2.VirtualControlCount = Queue.Count;
|
||||
UpdateAllControls();
|
||||
|
||||
if (!Running)
|
||||
runningTimeLbl.Text = string.Empty;
|
||||
}
|
||||
|
||||
private void CounterTimer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
string timeToStr(TimeSpan time)
|
||||
{
|
||||
string minsSecs = $"{time:mm\\:ss}";
|
||||
if (time.TotalHours >= 1)
|
||||
return $"{time.TotalHours:F0}:{minsSecs}";
|
||||
return minsSecs;
|
||||
}
|
||||
|
||||
if (Running)
|
||||
runningTimeLbl.Text = timeToStr(DateTime.Now - StartintTime);
|
||||
}
|
||||
|
||||
private void clearLogBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
logMeTbox.Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region View-Model update event handling
|
||||
|
||||
/// <summary>
|
||||
/// Index of the first <see cref="ProcessBook"/> visible in the <see cref="VirtualFlowControl"/>
|
||||
/// </summary>
|
||||
private int FirstVisible = 0;
|
||||
/// <summary>
|
||||
/// Number of <see cref="ProcessBook"/> visible in the <see cref="VirtualFlowControl"/>
|
||||
/// </summary>
|
||||
private int NumVisible = 0;
|
||||
/// <summary>
|
||||
/// Controls displaying the <see cref="ProcessBook"/> state, starting with <see cref="FirstVisible"/>
|
||||
/// </summary>
|
||||
private IReadOnlyList<ProcessBookControl> Panels;
|
||||
|
||||
/// <summary>
|
||||
/// Updates the display of a single <see cref="ProcessBookControl"/> at <paramref name="queueIndex"/> within <see cref="Queue"/>
|
||||
/// </summary>
|
||||
/// <param name="queueIndex">index of the <see cref="ProcessBook"/> within the <see cref="Queue"/></param>
|
||||
private void UpdateControl(int queueIndex)
|
||||
{
|
||||
int i = queueIndex - FirstVisible;
|
||||
|
||||
if (i < 0 || i > NumVisible) return;
|
||||
if (i > NumVisible || i < 0) return;
|
||||
|
||||
var proc = Queue[queueIndex];
|
||||
|
||||
@ -163,6 +264,49 @@ namespace LibationWinForms.ProcessQueue
|
||||
UpdateControl(FirstVisible + i);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// View notified the model that a botton was clicked
|
||||
/// </summary>
|
||||
/// <param name="queueIndex">index of the <see cref="ProcessBook"/> within <see cref="Queue"/></param>
|
||||
/// <param name="panelClicked">The clicked control to update</param>
|
||||
private void VirtualFlowControl2_ButtonClicked(int queueIndex, string buttonName, ProcessBookControl panelClicked)
|
||||
{
|
||||
ProcessBook item = Queue[queueIndex];
|
||||
if (buttonName == "cancelBtn")
|
||||
{
|
||||
item.Cancel();
|
||||
Queue.RemoveQueued(item);
|
||||
virtualFlowControl2.VirtualControlCount = Queue.Count;
|
||||
UpdateControl(queueIndex);
|
||||
}
|
||||
else if (buttonName == "moveFirstBtn")
|
||||
{
|
||||
Queue.MoveQueuePosition(item, QueuePosition.Fisrt);
|
||||
UpdateAllControls();
|
||||
}
|
||||
else if (buttonName == "moveUpBtn")
|
||||
{
|
||||
Queue.MoveQueuePosition(item, QueuePosition.OneUp);
|
||||
UpdateControl(queueIndex - 1);
|
||||
UpdateControl(queueIndex);
|
||||
}
|
||||
else if (buttonName == "moveDownBtn")
|
||||
{
|
||||
Queue.MoveQueuePosition(item, QueuePosition.OneDown);
|
||||
UpdateControl(queueIndex + 1);
|
||||
UpdateControl(queueIndex);
|
||||
}
|
||||
else if (buttonName == "moveLastBtn")
|
||||
{
|
||||
Queue.MoveQueuePosition(item, QueuePosition.Last);
|
||||
UpdateAllControls();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// View needs updating
|
||||
/// </summary>
|
||||
private void VirtualFlowControl1_RequestData(int firstIndex, int numVisible, IReadOnlyList<ProcessBookControl> panelsToFill)
|
||||
{
|
||||
FirstVisible = firstIndex;
|
||||
@ -171,78 +315,15 @@ namespace LibationWinForms.ProcessQueue
|
||||
UpdateAllControls();
|
||||
}
|
||||
|
||||
public void AddDownloadDecrypt(IEnumerable<GridEntry> entries)
|
||||
{
|
||||
foreach (var entry in entries)
|
||||
AddDownloadDecrypt(entry);
|
||||
}
|
||||
|
||||
public void AddDownloadDecrypt(GridEntry gridEntry)
|
||||
{
|
||||
if (Queue.Any(b => b?.LibraryBook?.Book?.AudibleProductId == gridEntry.AudibleProductId))
|
||||
return;
|
||||
|
||||
ProcessBook pbook = new(gridEntry.LibraryBook, gridEntry.Cover, Logger);
|
||||
pbook.DataAvailable += Pbook_DataAvailable;
|
||||
|
||||
pbook.AddDownloadDecryptBook();
|
||||
pbook.AddDownloadPdf();
|
||||
|
||||
Queue.Enqueue(pbook);
|
||||
|
||||
if (!Running)
|
||||
{
|
||||
QueueRunner = QueueLoop();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Model updates the view
|
||||
/// </summary>
|
||||
private void Pbook_DataAvailable(object sender, EventArgs e)
|
||||
{
|
||||
int index = Queue.IndexOf((ProcessBook)sender);
|
||||
UpdateControl(index);
|
||||
}
|
||||
|
||||
private async Task QueueLoop()
|
||||
{
|
||||
while (Queue.MoveNext())
|
||||
{
|
||||
var nextBook = Queue.Current;
|
||||
|
||||
var result = await nextBook.ProcessOneAsync();
|
||||
|
||||
if (result == ProcessBookResult.FailedRetry)
|
||||
Queue.Enqueue(nextBook);
|
||||
else if (result == ProcessBookResult.FailedAbort)
|
||||
return;
|
||||
}
|
||||
|
||||
Queue_CompletedCountChanged(this, 0);
|
||||
}
|
||||
|
||||
private void cancelAllBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
Queue.ClearQueue();
|
||||
Queue.Current?.Cancel();
|
||||
virtualFlowControl2.VirtualControlCount = Queue.Count;
|
||||
UpdateAllControls();
|
||||
}
|
||||
|
||||
private void btnCleanFinished_Click(object sender, EventArgs e)
|
||||
{
|
||||
Queue.ClearCompleted();
|
||||
virtualFlowControl2.VirtualControlCount = Queue.Count;
|
||||
UpdateAllControls();
|
||||
}
|
||||
|
||||
private void clearLogBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
logMeTbox.Clear();
|
||||
}
|
||||
|
||||
public void WriteLine(string text)
|
||||
{
|
||||
if (!IsDisposed)
|
||||
logMeTbox.UIThreadAsync(() => logMeTbox.AppendText($"{DateTime.Now} {text}{Environment.NewLine}"));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -630,4 +630,7 @@
|
||||
w1EmAAAAAElFTkSuQmCC
|
||||
</value>
|
||||
</data>
|
||||
<metadata name="counterTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>133, 17</value>
|
||||
</metadata>
|
||||
</root>
|
||||
Loading…
x
Reference in New Issue
Block a user