private async void Scan <T>(Func <string, Progress <object>, Task> scanFunction) where T : LibgenObject { SelectFolderDialogParameters selectFolderDialogParameters = new SelectFolderDialogParameters { DialogTitle = Localization.BrowseDirectoryDialogTitle }; SelectFolderDialogResult selectFolderDialogResult = WindowManager.ShowSelectFolderDialog(selectFolderDialogParameters); if (selectFolderDialogResult.DialogResult) { mode = Mode.SCANNING; FoundItems = new ObservableCollection <ScanResultItemViewModel>(); NotFoundItems = new ObservableCollection <string>(); UpdateResultTabHeaders(); UpdateAddAllFilesToLibraryButton(); IsScanLogTabSelected = true; AreScanButtonsVisible = false; IsResultsPanelVisible = true; scanDirectory = selectFolderDialogResult.SelectedFolderPath; ScanLogs.Add(Localization.GetScanStartedString(scanDirectory)); Progress <object> scanProgressHandler = new Progress <object>(HandleScanProgress <T>); await scanFunction(scanDirectory, scanProgressHandler); mode = Mode.SCAN_COMPLETE; hasFilesToAdd = foundItems.Any(foundItem => !foundItem.ExistsInLibrary); UpdateAddAllFilesToLibraryButton(); } }
private void HandleScanProgress(object progress) { switch (progress) { case GenericProgress genericProgress: switch (genericProgress.ProgressEvent) { case GenericProgress.Event.SCAN_CREATING_INDEXES: ScanLogs.Add(Localization.CreatingIndexes); break; } break; case ScanProgress scanProgress: if (scanProgress.Error) { ScanLogs.Add($"{scanProgress.RelativeFilePath} — {Localization.Error}."); } else if (scanProgress.Found) { FoundItems.Add(new ScanResultItemViewModel(LibgenObjectType.NON_FICTION_BOOK, 0, null, scanProgress.RelativeFilePath, scanProgress.Authors, scanProgress.Title)); } else { NotFoundItems.Add(scanProgress.RelativeFilePath); } UpdateResultTabHeaders(); break; case ScanCompleteProgress scanCompleteProgress: ScanLogs.Add(Localization.GetScanCompleteString(scanCompleteProgress.Found, scanCompleteProgress.NotFound, scanCompleteProgress.Errors)); break; } }
private void HandleScanProgress <T>(object progress) where T : LibgenObject { switch (progress) { case GenericProgress genericProgress: switch (genericProgress.ProgressEvent) { case GenericProgress.Event.SCAN_CREATING_INDEXES: ScanLogs.Add(Localization.CreatingIndexes); break; } break; case ScanProgress <T> scanProgress: switch (scanProgress.LibgenObject) { case NonFictionBook nonFictionBook: FoundItems.Add(new NonFictionScanResultItemViewModel(scanProgress.RelativeFilePath, nonFictionBook)); break; case FictionBook fictionBook: FoundItems.Add(new FictionScanResultItemViewModel(scanProgress.RelativeFilePath, fictionBook)); break; case SciMagArticle sciMagArticle: FoundItems.Add(new SciMagScanResultItemViewModel(scanProgress.RelativeFilePath, sciMagArticle)); break; } UpdateResultTabHeaders(); break; case ScanUnknownProgress scanUnknownProgress: if (scanUnknownProgress.Error) { var error = new ScanResultErrorItemViewModel(scanUnknownProgress.RelativeFilePath, scanUnknownProgress.ErrorType); ResolveErrorDescription(error); Errors.Add(error); UpdateResultTabHeaders(); } else { NotFoundItems.Add(scanUnknownProgress.RelativeFilePath); UpdateResultTabHeaders(); } break; case ScanCompleteProgress scanCompleteProgress: ScanLogs.Add(Localization.GetScanCompleteString(scanCompleteProgress.Found, scanCompleteProgress.NotFound, scanCompleteProgress.Errors)); break; } }
private async void Scan() { SelectFolderDialogParameters selectFolderDialogParameters = new SelectFolderDialogParameters { DialogTitle = Localization.BrowseDirectoryDialogTitle }; SelectFolderDialogResult selectFolderDialogResult = WindowManager.ShowSelectFolderDialog(selectFolderDialogParameters); if (selectFolderDialogResult.DialogResult) { FoundItems = new ObservableCollection <ScanResultItemViewModel>(); NotFoundItems = new ObservableCollection <string>(); UpdateResultTabHeaders(); IsScanLogTabSelected = true; IsScanButtonVisible = false; IsResultsPanelVisible = true; string scanDirectory = selectFolderDialogResult.SelectedFolderPath; ScanLogs.Add(Localization.GetScanStartedString(scanDirectory)); Progress <object> scanProgressHandler = new Progress <object>(HandleScanProgress); await MainModel.ScanAsync(scanDirectory, scanProgressHandler); } }