diff --git a/ApplicationServices/UNTESTED/LibraryCommands.cs b/ApplicationServices/UNTESTED/LibraryCommands.cs new file mode 100644 index 00000000..5aa52f85 --- /dev/null +++ b/ApplicationServices/UNTESTED/LibraryCommands.cs @@ -0,0 +1,40 @@ +using System; +using System.Threading.Tasks; +using AudibleApi; +using DataLayer; +using DtoImporterService; +using InternalUtilities; + +namespace ApplicationServices +{ + public static class LibraryCommands + { + public static async Task<(int totalCount, int newCount)> IndexLibraryAsync(ILoginCallback callback) + { + var audibleApiActions = new AudibleApiActions(); + var items = await audibleApiActions.GetAllLibraryItemsAsync(callback); + var totalCount = items.Count; + + var libImporter = new LibraryImporter(); + var newCount = await Task.Run(() => libImporter.Import(items)); + + await Task.Run(() => SearchEngineCommands.FullReIndex()); + + return (totalCount, newCount); + } + + public static int IndexChangedTags(Book book) + { + // update disconnected entity + using var context = LibationContext.Create(); + context.Update(book); + var qtyChanges = context.SaveChanges(); + + // this part is tags-specific + if (qtyChanges > 0) + SearchEngineCommands.UpdateBookTags(book); + + return qtyChanges; + } + } +} diff --git a/ApplicationServices/UNTESTED/LibraryIndexer.cs b/ApplicationServices/UNTESTED/LibraryIndexer.cs deleted file mode 100644 index 9bdcd4b5..00000000 --- a/ApplicationServices/UNTESTED/LibraryIndexer.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Threading.Tasks; -using AudibleApi; -using DtoImporterService; -using InternalUtilities; - -namespace ApplicationServices -{ - public class LibraryIndexer - { - public async Task<(int totalCount, int newCount)> IndexAsync(ILoginCallback callback) - { - var audibleApiActions = new AudibleApiActions(); - var items = await audibleApiActions.GetAllLibraryItemsAsync(callback); - var totalCount = items.Count; - - var libImporter = new LibraryImporter(); - var newCount = await Task.Run(() => libImporter.Import(items)); - - await SearchEngineActions.FullReIndexAsync(); - - return (totalCount, newCount); - } - } -} diff --git a/ApplicationServices/UNTESTED/SearchEngineActions.cs b/ApplicationServices/UNTESTED/SearchEngineActions.cs deleted file mode 100644 index 2d8781e3..00000000 --- a/ApplicationServices/UNTESTED/SearchEngineActions.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Threading.Tasks; -using DataLayer; - -namespace ApplicationServices -{ - public static class SearchEngineActions - { - public static async Task FullReIndexAsync() - { - var engine = new LibationSearchEngine.SearchEngine(); - await engine.CreateNewIndexAsync().ConfigureAwait(false); - } - - public static void UpdateBookTags(Book book) - { - var engine = new LibationSearchEngine.SearchEngine(); - engine.UpdateTags(book.AudibleProductId, book.UserDefinedItem.Tags); - } - } -} diff --git a/ApplicationServices/UNTESTED/SearchEngineCommands.cs b/ApplicationServices/UNTESTED/SearchEngineCommands.cs new file mode 100644 index 00000000..63e5d4a9 --- /dev/null +++ b/ApplicationServices/UNTESTED/SearchEngineCommands.cs @@ -0,0 +1,43 @@ +using System.Threading.Tasks; +using DataLayer; +using LibationSearchEngine; + +namespace ApplicationServices +{ + public static class SearchEngineCommands + { + public static void FullReIndex() + { + var engine = new SearchEngine(); + engine.CreateNewIndex(); + } + + public static SearchResultSet Search(string searchString) + { + var engine = new SearchEngine(); + try + { + return engine.Search(searchString); + } + catch (System.IO.FileNotFoundException) + { + FullReIndex(); + return engine.Search(searchString); + } + } + + public static void UpdateBookTags(Book book) + { + var engine = new SearchEngine(); + try + { + engine.UpdateTags(book.AudibleProductId, book.UserDefinedItem.Tags); + } + catch (System.IO.FileNotFoundException) + { + FullReIndex(); + engine.UpdateTags(book.AudibleProductId, book.UserDefinedItem.Tags); + } + } + } +} diff --git a/ApplicationServices/UNTESTED/TagUpdater.cs b/ApplicationServices/UNTESTED/TagUpdater.cs deleted file mode 100644 index ddef5057..00000000 --- a/ApplicationServices/UNTESTED/TagUpdater.cs +++ /dev/null @@ -1,21 +0,0 @@ -using DataLayer; - -namespace ApplicationServices -{ - public static class TagUpdater - { - public static int IndexChangedTags(Book book) - { - // update disconnected entity - using var context = LibationContext.Create(); - context.Update(book); - var qtyChanges = context.SaveChanges(); - - // this part is tags-specific - if (qtyChanges > 0) - SearchEngineActions.UpdateBookTags(book); - - return qtyChanges; - } - } -} diff --git a/LibationSearchEngine/UNTESTED/SearchEngine.cs b/LibationSearchEngine/UNTESTED/SearchEngine.cs index ad41ae39..2a9e42d1 100644 --- a/LibationSearchEngine/UNTESTED/SearchEngine.cs +++ b/LibationSearchEngine/UNTESTED/SearchEngine.cs @@ -160,8 +160,7 @@ namespace LibationSearchEngine private Directory getIndex() => FSDirectory.Open(SearchEngineDirectory); - public async Task CreateNewIndexAsync() => await Task.Run(() => createNewIndex(true)); - private void createNewIndex(bool overwrite) + public void CreateNewIndex(bool overwrite = true) { // 300 products // 1st run after app is started: 400ms diff --git a/LibationWinForm/UNTESTED/Dialogs/IndexLibraryDialog.cs b/LibationWinForm/UNTESTED/Dialogs/IndexLibraryDialog.cs index 9c173522..d35ad17e 100644 --- a/LibationWinForm/UNTESTED/Dialogs/IndexLibraryDialog.cs +++ b/LibationWinForm/UNTESTED/Dialogs/IndexLibraryDialog.cs @@ -31,8 +31,7 @@ namespace LibationWinForm public async Task DoMainWorkAsync() { var callback = new Login.WinformResponder(); - var indexer = new LibraryIndexer(); - (TotalBooksProcessed, NewBooksAdded) = await indexer.IndexAsync(callback); + (TotalBooksProcessed, NewBooksAdded) = await LibraryCommands.IndexLibraryAsync(callback); successMessages.Add($"Total processed: {TotalBooksProcessed}"); successMessages.Add($"New: {NewBooksAdded}"); diff --git a/LibationWinForm/UNTESTED/ProductsGrid.cs b/LibationWinForm/UNTESTED/ProductsGrid.cs index d97ab57b..611fe881 100644 --- a/LibationWinForm/UNTESTED/ProductsGrid.cs +++ b/LibationWinForm/UNTESTED/ProductsGrid.cs @@ -2,9 +2,10 @@ using System.Drawing; using System.Linq; using System.Windows.Forms; -using Dinah.Core.DataBinding; +using ApplicationServices; using DataLayer; using Dinah.Core.Collections.Generic; +using Dinah.Core.DataBinding; namespace LibationWinForm { @@ -189,7 +190,7 @@ namespace LibationWinForm { book.UserDefinedItem.Tags = newTags; - var qtyChanges = ApplicationServices.TagUpdater.IndexChangedTags(book); + var qtyChanges = LibraryCommands.IndexChangedTags(book); return qtyChanges; } @@ -238,7 +239,7 @@ namespace LibationWinForm if (dataGridView.Rows.Count == 0) return; - var searchResults = new LibationSearchEngine.SearchEngine().Search(searchString); + var searchResults = SearchEngineCommands.Search(searchString); var productIds = searchResults.Docs.Select(d => d.ProductId).ToList(); // https://stackoverflow.com/a/18942430 diff --git a/__TODO.txt b/__TODO.txt index 97176baa..0733e560 100644 --- a/__TODO.txt +++ b/__TODO.txt @@ -1,21 +1,18 @@ -- 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 -libation errors on another computer: - copy pw, LibationSettings.json - file not found. probably about file locations. the bottom right and bottom left counts don't update - ONLY file in libation files: IdentityTokens.json. no other files OR folders -exception after library scan - file not found. same file? -no mdf,ldf files created in C:\Users\[username] - throttle needed for downloading images, pdf.s +no mdf,ldf files created in C:\Users\[username] + Warn of known performance issues - Library import + incl image d/l. need to throttle - Tag add/edit - Grid is slow to respond loading when books aren't liberated - get decrypt key -- unavoidable @@ -27,7 +24,7 @@ https://dotnetcoretutorials.com/2019/06/20/publishing-a-single-exe-file-in-net-c -- begin ENHANCEMENT, IMPORT UI --------------------------------------------------------------------------------------------------------------------- scan library in background? can include a notice somewhere that it's in-process -why block the UI? +why block the UI at all? -- end ENHANCEMENT, IMPORT UI --------------------------------------------------------------------------------------------------------------------- -- begin BUG, FILE DOWNLOAD ---------------------------------------------------------------------------------------------------------------------