Change log to gridview and new INotifyPropertyChanged event

This commit is contained in:
Michael Bucari-Tovo 2022-05-14 13:52:54 -06:00
parent a7b7e3efea
commit 50c35ed519
4 changed files with 121 additions and 60 deletions

View File

@ -37,7 +37,7 @@
this.ClientSize = new System.Drawing.Size(522, 638);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
this.Name = "ProcessBookForm";
this.Text = "ProcessBookForm";
this.Text = "Book Processing Queue";
this.ResumeLayout(false);
}

View File

@ -30,6 +30,7 @@
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ProcessQueueControl));
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.toolStripProgressBar1 = new System.Windows.Forms.ToolStripProgressBar();
this.queueNumberLbl = new System.Windows.Forms.ToolStripStatusLabel();
@ -45,16 +46,20 @@
this.btnCleanFinished = new System.Windows.Forms.Button();
this.cancelAllBtn = new System.Windows.Forms.Button();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.logDGV = new System.Windows.Forms.DataGridView();
this.timestampColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.logEntryColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.panel4 = new System.Windows.Forms.Panel();
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.logCopyBtn = new System.Windows.Forms.Button();
this.statusStrip1.SuspendLayout();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.panel1.SuspendLayout();
this.tabPage2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.logDGV)).BeginInit();
this.panel2.SuspendLayout();
this.SuspendLayout();
//
@ -193,9 +198,9 @@
//
// tabPage2
//
this.tabPage2.Controls.Add(this.logDGV);
this.tabPage2.Controls.Add(this.panel4);
this.tabPage2.Controls.Add(this.panel2);
this.tabPage2.Controls.Add(this.logMeTbox);
this.tabPage2.Location = new System.Drawing.Point(4, 24);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
@ -204,6 +209,41 @@
this.tabPage2.Text = "Log";
this.tabPage2.UseVisualStyleBackColor = true;
//
// logDGV
//
this.logDGV.AllowUserToAddRows = false;
this.logDGV.AllowUserToDeleteRows = false;
this.logDGV.AllowUserToOrderColumns = true;
this.logDGV.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells;
this.logDGV.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.logDGV.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.timestampColumn,
this.logEntryColumn});
this.logDGV.Dock = System.Windows.Forms.DockStyle.Fill;
this.logDGV.Location = new System.Drawing.Point(3, 3);
this.logDGV.Name = "logDGV";
this.logDGV.RowHeadersVisible = false;
this.logDGV.RowTemplate.Height = 40;
this.logDGV.Size = new System.Drawing.Size(390, 419);
this.logDGV.TabIndex = 3;
this.logDGV.Resize += new System.EventHandler(this.LogDGV_Resize);
//
// timestampColumn
//
this.timestampColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
this.timestampColumn.HeaderText = "Timestamp";
this.timestampColumn.Name = "timestampColumn";
this.timestampColumn.ReadOnly = true;
this.timestampColumn.Width = 91;
//
// logEntryColumn
//
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.logEntryColumn.DefaultCellStyle = dataGridViewCellStyle1;
this.logEntryColumn.HeaderText = "Log";
this.logEntryColumn.Name = "logEntryColumn";
this.logEntryColumn.ReadOnly = true;
//
// panel4
//
this.panel4.Dock = System.Windows.Forms.DockStyle.Bottom;
@ -216,6 +256,7 @@
//
this.panel2.BackColor = System.Drawing.SystemColors.Control;
this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel2.Controls.Add(this.logCopyBtn);
this.panel2.Controls.Add(this.clearLogBtn);
this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel2.Location = new System.Drawing.Point(3, 427);
@ -228,38 +269,36 @@
this.clearLogBtn.Dock = System.Windows.Forms.DockStyle.Left;
this.clearLogBtn.Location = new System.Drawing.Point(0, 0);
this.clearLogBtn.Name = "clearLogBtn";
this.clearLogBtn.Size = new System.Drawing.Size(75, 23);
this.clearLogBtn.Size = new System.Drawing.Size(60, 23);
this.clearLogBtn.TabIndex = 0;
this.clearLogBtn.Text = "Clear Log";
this.clearLogBtn.Text = "Clear";
this.clearLogBtn.UseVisualStyleBackColor = true;
this.clearLogBtn.Click += new System.EventHandler(this.clearLogBtn_Click);
//
// logMeTbox
//
this.logMeTbox.Dock = System.Windows.Forms.DockStyle.Fill;
this.logMeTbox.Location = new System.Drawing.Point(3, 3);
this.logMeTbox.Margin = new System.Windows.Forms.Padding(3, 3, 3, 0);
this.logMeTbox.MaxLength = 10000000;
this.logMeTbox.Multiline = true;
this.logMeTbox.Name = "logMeTbox";
this.logMeTbox.ReadOnly = true;
this.logMeTbox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
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
// logCopyBtn
//
this.logCopyBtn.Dock = System.Windows.Forms.DockStyle.Right;
this.logCopyBtn.Location = new System.Drawing.Point(331, 0);
this.logCopyBtn.Name = "logCopyBtn";
this.logCopyBtn.Size = new System.Drawing.Size(57, 23);
this.logCopyBtn.TabIndex = 1;
this.logCopyBtn.Text = "Copy";
this.logCopyBtn.UseVisualStyleBackColor = true;
this.logCopyBtn.Click += new System.EventHandler(this.LogCopyBtn_Click);
//
// ProcessQueueControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.Controls.Add(this.tabControl1);
this.Controls.Add(this.statusStrip1);
this.Name = "ProcessBookQueue";
this.Name = "ProcessQueueControl";
this.Size = new System.Drawing.Size(404, 508);
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
@ -267,7 +306,7 @@
this.tabPage1.ResumeLayout(false);
this.panel1.ResumeLayout(false);
this.tabPage2.ResumeLayout(false);
this.tabPage2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.logDGV)).EndInit();
this.panel2.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
@ -281,7 +320,6 @@
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.TextBox logMeTbox;
private System.Windows.Forms.Button btnCleanFinished;
private System.Windows.Forms.Button cancelAllBtn;
private System.Windows.Forms.Panel panel2;
@ -295,5 +333,9 @@
private System.Windows.Forms.Panel panel4;
private System.Windows.Forms.ToolStripStatusLabel runningTimeLbl;
private System.Windows.Forms.Timer counterTimer;
private System.Windows.Forms.DataGridView logDGV;
private System.Windows.Forms.DataGridViewTextBoxColumn timestampColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn logEntryColumn;
private System.Windows.Forms.Button logCopyBtn;
}
}

View File

@ -1,7 +1,7 @@
using Dinah.Core.Threading;
using LibationWinForms.BookLiberation;
using LibationWinForms.BookLiberation;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
@ -42,7 +42,6 @@ namespace LibationWinForms.ProcessQueue
public Task QueueRunner { get; private set; }
public bool Running => !QueueRunner?.IsCompleted ?? false;
public ToolStripButton popoutBtn = new();
public ProcessQueueControl()
@ -71,47 +70,43 @@ namespace LibationWinForms.ProcessQueue
CompletedCount = 0;
}
public void AddDownloadDecrypt(IEnumerable<GridEntry> entries)
public void AddDownloadDecrypt(IEnumerable<DataLayer.LibraryBook> entries)
{
foreach (var entry in entries)
AddDownloadDecrypt(entry);
}
public void AddConvertMp3(IEnumerable<GridEntry> entries)
public void AddConvertMp3(IEnumerable<DataLayer.LibraryBook> entries)
{
foreach (var entry in entries)
AddConvertMp3(entry);
}
public void AddDownloadDecrypt(GridEntry gridEntry)
public void AddDownloadDecrypt(DataLayer.LibraryBook libraryBook)
{
if (Queue.Any(b => b?.LibraryBook?.Book?.AudibleProductId == gridEntry.AudibleProductId))
if (Queue.Any(b => b?.LibraryBook?.Book?.AudibleProductId == libraryBook.Book.AudibleProductId))
return;
ProcessBook pbook = new(gridEntry.LibraryBook, gridEntry.Cover, Logger);
pbook.DataAvailable += Pbook_DataAvailable;
ProcessBook pbook = new(libraryBook, Logger);
pbook.PropertyChanged += Pbook_DataAvailable;
pbook.AddDownloadDecryptBook();
pbook.AddDownloadPdf();
Queue.Enqueue(pbook);
if (!Running)
{
QueueRunner = QueueLoop();
}
AddToQueue(pbook);
}
public void AddConvertMp3(GridEntry gridEntry)
public void AddConvertMp3(DataLayer.LibraryBook libraryBook)
{
if (Queue.Any(b => b?.LibraryBook?.Book?.AudibleProductId == gridEntry.AudibleProductId))
if (Queue.Any(b => b?.LibraryBook?.Book?.AudibleProductId == libraryBook.Book.AudibleProductId))
return;
ProcessBook pbook = new(gridEntry.LibraryBook, gridEntry.Cover, Logger);
pbook.DataAvailable += Pbook_DataAvailable;
ProcessBook pbook = new(libraryBook, Logger);
pbook.PropertyChanged += Pbook_DataAvailable;
pbook.AddConvertToMp3();
AddToQueue(pbook);
}
private void AddToQueue(ProcessBook pbook)
{
Queue.Enqueue(pbook);
if (!Running)
@ -144,8 +139,10 @@ namespace LibationWinForms.ProcessQueue
public void WriteLine(string text)
{
if (!IsDisposed)
logMeTbox.UIThreadAsync(() => logMeTbox.AppendText($"{DateTime.Now} {text}{Environment.NewLine}"));
if (IsDisposed) return;
var timeStamp = DateTime.Now;
logDGV.Rows.Add(timeStamp, text.Trim());
}
#region Control event handlers
@ -205,7 +202,18 @@ namespace LibationWinForms.ProcessQueue
private void clearLogBtn_Click(object sender, EventArgs e)
{
logMeTbox.Clear();
logDGV.Rows.Clear();
}
private void LogCopyBtn_Click(object sender, EventArgs e)
{
string logText = string.Join("\r\n", logDGV.Rows.Cast<DataGridViewRow>().Select(r => $"{r.Cells[0].Value}\t{r.Cells[1].Value}"));
Clipboard.SetDataObject(logText, false, 5, 150);
}
private void LogDGV_Resize(object sender, EventArgs e)
{
logDGV.Columns[1].Width = logDGV.Width - logDGV.Columns[0].Width;
}
#endregion
@ -229,7 +237,7 @@ namespace LibationWinForms.ProcessQueue
/// 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)
private void UpdateControl(int queueIndex, string propertyName = null)
{
int i = queueIndex - FirstVisible;
@ -240,7 +248,9 @@ namespace LibationWinForms.ProcessQueue
Panels[i].Invoke(() =>
{
Panels[i].SuspendLayout();
if (propertyName is null || propertyName == nameof(proc.Cover))
Panels[i].SetCover(proc.Cover);
if (propertyName is null || propertyName == nameof(proc.BookText))
Panels[i].SetBookInfo(proc.BookText);
if (proc.Result != ProcessBookResult.None)
@ -249,8 +259,11 @@ namespace LibationWinForms.ProcessQueue
return;
}
if (propertyName is null || propertyName == nameof(proc.Status))
Panels[i].SetStatus(proc.Status);
if (propertyName is null || propertyName == nameof(proc.Progress))
Panels[i].SetProgrss(proc.Progress);
if (propertyName is null || propertyName == nameof(proc.TimeRemaining))
Panels[i].SetRemainingTime(proc.TimeRemaining);
Panels[i].ResumeLayout();
});
@ -273,31 +286,31 @@ namespace LibationWinForms.ProcessQueue
private void VirtualFlowControl2_ButtonClicked(int queueIndex, string buttonName, ProcessBookControl panelClicked)
{
ProcessBook item = Queue[queueIndex];
if (buttonName == "cancelBtn")
if (buttonName == nameof(panelClicked.cancelBtn))
{
item.Cancel();
Queue.RemoveQueued(item);
virtualFlowControl2.VirtualControlCount = Queue.Count;
UpdateControl(queueIndex);
}
else if (buttonName == "moveFirstBtn")
else if (buttonName == nameof(panelClicked.moveFirstBtn))
{
Queue.MoveQueuePosition(item, QueuePosition.Fisrt);
UpdateAllControls();
}
else if (buttonName == "moveUpBtn")
else if (buttonName == nameof(panelClicked.moveUpBtn))
{
Queue.MoveQueuePosition(item, QueuePosition.OneUp);
UpdateControl(queueIndex - 1);
UpdateControl(queueIndex);
}
else if (buttonName == "moveDownBtn")
else if (buttonName == nameof(panelClicked.moveDownBtn))
{
Queue.MoveQueuePosition(item, QueuePosition.OneDown);
UpdateControl(queueIndex + 1);
UpdateControl(queueIndex);
}
else if (buttonName == "moveLastBtn")
else if (buttonName == nameof(panelClicked.moveLastBtn))
{
Queue.MoveQueuePosition(item, QueuePosition.Last);
UpdateAllControls();
@ -318,10 +331,10 @@ namespace LibationWinForms.ProcessQueue
/// <summary>
/// Model updates the view
/// </summary>
private void Pbook_DataAvailable(object sender, EventArgs e)
private void Pbook_DataAvailable(object sender, PropertyChangedEventArgs e)
{
int index = Queue.IndexOf((ProcessBook)sender);
UpdateControl(index);
UpdateControl(index, e.PropertyName);
}
#endregion

View File

@ -630,6 +630,12 @@
w1EmAAAAAElFTkSuQmCC
</value>
</data>
<metadata name="timestampColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="logEntryColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="counterTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>133, 17</value>
</metadata>