streamline indexing ui workflow
This commit is contained in:
parent
0b42b8ee49
commit
01a914c390
@ -1,8 +0,0 @@
|
||||
namespace LibationWinForm
|
||||
{
|
||||
public interface IIndexLibraryDialog : IRunnableDialog
|
||||
{
|
||||
int TotalBooksProcessed { get; }
|
||||
int NewBooksAdded { get; }
|
||||
}
|
||||
}
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -251,16 +251,19 @@ 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;
|
||||
|
||||
MessageBox.Show($"Total processed: {totalProcessed}\r\nNew: {newAdded}");
|
||||
|
||||
// update backup counts if we have new library items
|
||||
if (dialog.NewBooksAdded > 0)
|
||||
if (newAdded > 0)
|
||||
await setBackupCountsAsync();
|
||||
|
||||
if (dialog.TotalBooksProcessed > 0)
|
||||
if (totalProcessed > 0)
|
||||
reloadGrid();
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user