streamline indexing ui workflow

This commit is contained in:
Robert McRackan 2019-11-12 12:54:54 -05:00
parent 0b42b8ee49
commit 01a914c390
8 changed files with 25 additions and 151 deletions

View File

@ -1,8 +0,0 @@
namespace LibationWinForm
{
public interface IIndexLibraryDialog : IRunnableDialog
{
int TotalBooksProcessed { get; }
int NewBooksAdded { get; }
}
}

View File

@ -1,20 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LibationWinForm
{
public interface IRunnableDialog
{
IButtonControl AcceptButton { get; set; }
Control.ControlCollection Controls { get; }
Task DoMainWorkAsync();
string SuccessMessage { get; }
DialogResult ShowDialog();
DialogResult DialogResult { get; set; }
void Close();
}
}

View File

@ -1,76 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using Dinah.Core.Windows.Forms;
namespace LibationWinForm
{
public static class IRunnableDialogExt
{
public static DialogResult RunDialog(this IRunnableDialog dialog)
{
// hook up runner before dialog.ShowDialog for all
var acceptButton = (ButtonBase)dialog.AcceptButton;
acceptButton.Click += acceptButton_Click;
return dialog.ShowDialog();
}
// running/workflow logic is in IndexDialogRunner.Run()
private static async void acceptButton_Click(object sender, EventArgs e)
{
var form = ((Control)sender).FindForm();
var iRunnableDialog = form as IRunnableDialog;
try
{
await iRunnableDialog.Run();
}
catch (Exception ex)
{
throw new Exception("Did the database get created correctly? Including seed data. Eg: Update-Database", ex);
}
}
public static async Task Run(this IRunnableDialog dialog)
{
// get top level controls only. If Enabled, disable and push on stack
var disabledStack = disable(dialog);
// lazy-man's async. also violates the intent of async/await.
// use here for now simply for UI responsiveness
await dialog.DoMainWorkAsync().ConfigureAwait(true);
// after running, unwind and re-enable
enable(disabledStack);
MessageBox.Show(dialog.SuccessMessage);
dialog.DialogResult = DialogResult.OK;
dialog.Close();
}
static Stack<Control> disable(IRunnableDialog dialog)
{
var disableStack = new Stack<Control>();
foreach (Control ctrl in dialog.Controls)
{
if (ctrl.Enabled)
{
disableStack.Push(ctrl);
ctrl.Enabled = false;
}
}
return disableStack;
}
static void enable(Stack<Control> disabledStack)
{
while (disabledStack.Count > 0)
{
var ctrl = disabledStack.Pop();
ctrl.Enabled = true;
}
}
}
}

View File

@ -51,7 +51,6 @@
this.MinimizeBox = false;
this.Name = "IndexLibraryDialog";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Scan Library";
this.ResumeLayout(false);

View File

@ -1,40 +1,24 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms;
using ApplicationServices;
namespace LibationWinForm
{
public partial class IndexLibraryDialog : Form, IIndexLibraryDialog
public partial class IndexLibraryDialog : Form
{
public IndexLibraryDialog()
{
InitializeComponent();
var btn = new Button();
AcceptButton = btn;
btn.Location = new System.Drawing.Point(this.Size.Width + 10, 0);
// required for FindForm() to work
this.Controls.Add(btn);
this.Shown += (_, __) => AcceptButton.PerformClick();
}
List<string> successMessages { get; } = new List<string>();
public string SuccessMessage => string.Join("\r\n", successMessages);
public int NewBooksAdded { get; private set; }
public int TotalBooksProcessed { get; private set; }
public async Task DoMainWorkAsync()
public IndexLibraryDialog()
{
var callback = new Login.WinformResponder();
(TotalBooksProcessed, NewBooksAdded) = await LibraryCommands.IndexLibraryAsync(callback);
InitializeComponent();
this.Shown += IndexLibraryDialog_Shown;
}
successMessages.Add($"Total processed: {TotalBooksProcessed}");
successMessages.Add($"New: {NewBooksAdded}");
private async void IndexLibraryDialog_Shown(object sender, System.EventArgs e)
{
(TotalBooksProcessed, NewBooksAdded) = await LibraryCommands.IndexLibraryAsync(new Login.WinformResponder());
this.Close();
}
}
}

View File

@ -251,22 +251,25 @@ namespace LibationWinForm
#region index menu
private async void scanLibraryToolStripMenuItem_Click(object sender, EventArgs e)
{
var dialog = new IndexLibraryDialog();
using var dialog = new IndexLibraryDialog();
dialog.ShowDialog();
if (dialog.RunDialog().In(DialogResult.Abort, DialogResult.Cancel, DialogResult.None))
return;
var totalProcessed = dialog.TotalBooksProcessed;
var newAdded = dialog.NewBooksAdded;
// update backup counts if we have new library items
if (dialog.NewBooksAdded > 0)
await setBackupCountsAsync();
MessageBox.Show($"Total processed: {totalProcessed}\r\nNew: {newAdded}");
if (dialog.TotalBooksProcessed > 0)
// update backup counts if we have new library items
if (newAdded > 0)
await setBackupCountsAsync();
if (totalProcessed > 0)
reloadGrid();
}
#endregion
}
#endregion
#region liberate menu
private async void setBackupCountsAsync(object _, string __) => await setBackupCountsAsync();
#region liberate menu
private async void setBackupCountsAsync(object _, string __) => await setBackupCountsAsync();
private async void beginBookBackupsToolStripMenuItem_Click(object sender, EventArgs e)
{

View File

@ -51,7 +51,6 @@
this.MinimizeBox = false;
this.Name = "IndexLibraryDialog";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Scan Library";
this.ResumeLayout(false);

View File

@ -1,11 +1,4 @@
-- begin BETA ---------------------------------------------------------------------------------------------------------------------
if db present but no search files -- re-create
when library scan complete: close "Scan Library" dialog and THEN show results dialog
make sure the new "if (dataGridView.Rows.Count == 0)" doesn't break filtering if all are invisible
- load products. do a search with 0 results. do a search with results
throttle needed for downloading images, pdf.s
no mdf,ldf files created in C:\Users\[username]