From 01a914c39018edd1d92e767de93c5411d78cba3a Mon Sep 17 00:00:00 2001 From: Robert McRackan Date: Tue, 12 Nov 2019 12:54:54 -0500 Subject: [PATCH] streamline indexing ui workflow --- .../IndexDialogs/IIndexLibraryDialog.cs | 8 -- .../Dialogs/IndexDialogs/IRunnableDialog.cs | 20 ----- .../IndexDialogs/IRunnableDialogExt.cs | 76 ------------------- .../Dialogs/IndexLibraryDialog.Designer.cs | 1 - .../UNTESTED/Dialogs/IndexLibraryDialog.cs | 38 +++------- LibationWinForm/UNTESTED/Form1.cs | 25 +++--- .../Dialogs/IndexLibraryDialog.Designer.cs | 1 - __TODO.txt | 7 -- 8 files changed, 25 insertions(+), 151 deletions(-) delete mode 100644 LibationWinForm/UNTESTED/Dialogs/IndexDialogs/IIndexLibraryDialog.cs delete mode 100644 LibationWinForm/UNTESTED/Dialogs/IndexDialogs/IRunnableDialog.cs delete mode 100644 LibationWinForm/UNTESTED/Dialogs/IndexDialogs/IRunnableDialogExt.cs diff --git a/LibationWinForm/UNTESTED/Dialogs/IndexDialogs/IIndexLibraryDialog.cs b/LibationWinForm/UNTESTED/Dialogs/IndexDialogs/IIndexLibraryDialog.cs deleted file mode 100644 index 96a812a9..00000000 --- a/LibationWinForm/UNTESTED/Dialogs/IndexDialogs/IIndexLibraryDialog.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace LibationWinForm -{ - public interface IIndexLibraryDialog : IRunnableDialog - { - int TotalBooksProcessed { get; } - int NewBooksAdded { get; } - } -} diff --git a/LibationWinForm/UNTESTED/Dialogs/IndexDialogs/IRunnableDialog.cs b/LibationWinForm/UNTESTED/Dialogs/IndexDialogs/IRunnableDialog.cs deleted file mode 100644 index 49cb173a..00000000 --- a/LibationWinForm/UNTESTED/Dialogs/IndexDialogs/IRunnableDialog.cs +++ /dev/null @@ -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(); - } -} diff --git a/LibationWinForm/UNTESTED/Dialogs/IndexDialogs/IRunnableDialogExt.cs b/LibationWinForm/UNTESTED/Dialogs/IndexDialogs/IRunnableDialogExt.cs deleted file mode 100644 index 8f87f28c..00000000 --- a/LibationWinForm/UNTESTED/Dialogs/IndexDialogs/IRunnableDialogExt.cs +++ /dev/null @@ -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 disable(IRunnableDialog dialog) - { - var disableStack = new Stack(); - foreach (Control ctrl in dialog.Controls) - { - if (ctrl.Enabled) - { - disableStack.Push(ctrl); - ctrl.Enabled = false; - } - } - return disableStack; - } - static void enable(Stack disabledStack) - { - while (disabledStack.Count > 0) - { - var ctrl = disabledStack.Pop(); - ctrl.Enabled = true; - } - } - } -} diff --git a/LibationWinForm/UNTESTED/Dialogs/IndexLibraryDialog.Designer.cs b/LibationWinForm/UNTESTED/Dialogs/IndexLibraryDialog.Designer.cs index 6d11b629..2f641c0f 100644 --- a/LibationWinForm/UNTESTED/Dialogs/IndexLibraryDialog.Designer.cs +++ b/LibationWinForm/UNTESTED/Dialogs/IndexLibraryDialog.Designer.cs @@ -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); diff --git a/LibationWinForm/UNTESTED/Dialogs/IndexLibraryDialog.cs b/LibationWinForm/UNTESTED/Dialogs/IndexLibraryDialog.cs index d35ad17e..ca48a098 100644 --- a/LibationWinForm/UNTESTED/Dialogs/IndexLibraryDialog.cs +++ b/LibationWinForm/UNTESTED/Dialogs/IndexLibraryDialog.cs @@ -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 successMessages { get; } = new List(); - 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(); } } } diff --git a/LibationWinForm/UNTESTED/Form1.cs b/LibationWinForm/UNTESTED/Form1.cs index 6b1e486a..ea3487ae 100644 --- a/LibationWinForm/UNTESTED/Form1.cs +++ b/LibationWinForm/UNTESTED/Form1.cs @@ -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) { diff --git a/WinFormsDesigner/Dialogs/IndexLibraryDialog.Designer.cs b/WinFormsDesigner/Dialogs/IndexLibraryDialog.Designer.cs index c7087173..dbdd940f 100644 --- a/WinFormsDesigner/Dialogs/IndexLibraryDialog.Designer.cs +++ b/WinFormsDesigner/Dialogs/IndexLibraryDialog.Designer.cs @@ -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); diff --git a/__TODO.txt b/__TODO.txt index 0733e560..f33a8918 100644 --- a/__TODO.txt +++ b/__TODO.txt @@ -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]