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; } }
public async Task <bool> HandleControlKeys(KeyEventArgs context) { switch (context.Key) { case Key.Enter when SelectedFoundItem == null: return(true); case Key.Enter when SelectedFoundItem is SlashCommand slashCommand: await RunSlashCommand(slashCommand); return(true); case Key.Enter: var process = new Process { StartInfo = new ProcessStartInfo { Arguments = SelectedFoundItem.Arguments, FileName = SelectedFoundItem.Path } }; if (!string.IsNullOrWhiteSpace(SelectedFoundItem.WorkingDirectory)) { process.StartInfo.WorkingDirectory = SelectedFoundItem.WorkingDirectory; } ClearSearchAndHide(); process.Start(); return(true); case Key.Down: SelectedFoundItem = FoundItems[Math.Min( FoundItems.Count - 1, Array.IndexOf(FoundItems.ToArray(), SelectedFoundItem) + 1 )]; return(true); case Key.Up: SelectedFoundItem = FoundItems[Math.Max( 0, Array.IndexOf(FoundItems.ToArray(), SelectedFoundItem) - 1 )]; return(true); case Key.Escape: ClearSearchAndHide(); return(true); case Key.PageUp: var windowManager = new WindowManager(); windowManager.ShowDialog(new ScratchpadViewModel()); return(true); default: return(false); } }
private async void SearchAsync() { _priority = new Priority(); _visited = new HashSet <string>(); _isSearching = true; RaisePropertyChanged(nameof(SearchCommand)); FoundItems.Clear(); var job = _search.CreateSearchJob(_searchWords, _depth); _queue.Enqueue(job, _priority.GetBestPrio()); await Task.Factory.StartNew(Consume); }
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; } }
public ListSearchControl() { this.InitializeComponent(); this.WhenActivated(disposables => { this.WhenAnyValue(v => v.ViewModel) .BindTo(this, v => v.DataContext) .DisposeWith(disposables); this.Bind(this.ViewModel, vm => vm.FilterItem, v => v.FilterItemViewHost.ViewModel) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.FindNext, v => v.FindNextButton) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.FindPrevious, v => v.FindPreviousButton) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.StopSearch, v => v.StopSearchButton) .DisposeWith(disposables); this.BindCommand(this.ViewModel, vm => vm.Clear, v => v.ClearSearchButton) .DisposeWith(disposables); this.OneWayBind(this.ViewModel, vm => vm.IsSearchInitialized, v => v.FoundItemsCountTextBlock.IsVisible) .DisposeWith(disposables); Observable.CombineLatest( this.ViewModel !.FoundItems.ToObservableChangeSet().Count(), this.WhenAnyValue(v => v.ViewModel !.CurrentIndex), this.WhenAnyValue(v => v.ViewModel !.TotalSearchedItemsCount), this.FoundItemsCountMessage) .BindTo(this, v => v.FoundItemsCountTextBlock.Text) .DisposeWith(disposables); this.OneWayBind(this.ViewModel, vm => vm.SearchResults, v => v.SearchResults.Items) .DisposeWith(disposables); this.Bind(this.ViewModel, vm => vm.CurrentResult, v => v.SearchResults.SelectedItem) .DisposeWith(disposables); this.WhenAnyValue(v => v.SearchResults.SelectedItem) .WhereNotNull() .Subscribe(this.SearchResults.ScrollIntoView) .DisposeWith(disposables); }); }
private async void AddAllFilesToLibrary() { mode = Mode.ADDING_FILES; UpdateAddAllFilesToLibraryButton(); List <LibraryFile> filesToAdd = FoundItems.Where(foundItem => !foundItem.ExistsInLibrary).Select(foundItem => new LibraryFile { FilePath = Path.Combine(scanDirectory, foundItem.RelativeFilePath), ArchiveEntry = null, ObjectType = foundItem.LibgenObjectType, ObjectId = foundItem.ObjectId }).ToList(); await MainModel.AddFiles(filesToAdd); mode = Mode.FILES_ADDED; UpdateAddAllFilesToLibraryButton(); }
private async void GetInvoices() { if (!string.IsNullOrWhiteSpace(SearchTerm)) { MessageToDisplay = "Searching..."; IsBusy = true; ButtonEnabled = false; IsLoading = true; GetInvoicesCommand.RaiseCanExecuteChanged(); var proxy = _serviceFactory.CreateClient <IInvoiceService>(); using (proxy) { var invoices = proxy.FindInvoicesByCompanyAsync((Company)CurrentCompany, SearchTerm); await invoices; // FoundItems = new ObservableCollection<Invoice>(orders.Result); if (invoices.Result.Count > 0) { foreach (var invoice in invoices.Result) { FoundItems.Add(Map(invoice)); } SelectedItem = FoundItems[0]; SelectedItemIndex = 0; } } MessageToDisplay = FoundItems.Count.ToString() + " invoice(s) found"; ButtonEnabled = true; GetInvoicesCommand.RaiseCanExecuteChanged(); //RaisePropertyChanged(nameof(FoundSome)); //RaisePropertyChanged(nameof(FoundSomeNo)); } else { MessageToDisplay = "You must enter a search term in order to find an invoice"; } IsLoading = false; IsBusy = false; }
private async void GetOrders() { if (!string.IsNullOrWhiteSpace(SearchTerm)) { MessageToDisplay = "Searching..."; IsBusy = true; ButtonEnabled = false; IsLoading = true; GetOrdersCommand.RaiseCanExecuteChanged(); var proxy = _serviceFactory.CreateClient <IOrderService>(); using (proxy) { var orders = proxy.FindOrdersByCompanyAsync((Company)CurrentCompany, SearchTerm); await orders; if (orders.Result.Count > 0) { foreach (var order in orders.Result) { FoundItems.Add(Map(order)); } SelectedItem = FoundItems[0]; SelectedItemIndex = 0; } } MessageToDisplay = FoundItems.Count.ToString() + " order(s) found"; ButtonEnabled = true; GetOrdersCommand.RaiseCanExecuteChanged(); } else { MessageToDisplay = "You must enter a search term in order to find an order"; } IsLoading = false; IsBusy = false; }
private async void GetAccounts() { if (!string.IsNullOrWhiteSpace(SearchTerm)) { IsBusy = true; IsLoading = true; var account_service = _serviceFactory.CreateClient <IAccountService>(); using (account_service) { try { var results = account_service.FindAccountByCompanyAsync((Company)CurrentCompany, SearchTerm); await results; foreach (var account in results.Result) { FoundItems.Add(Map(account)); } MessageToDisplay = FoundItems.Count.ToString() + " account(s) found"; } catch (Exception ex) { MessageToDisplay = ex.Message; return; } } } else { MessageToDisplay = "You must enter a search term in order to find an account"; } IsLoading = false; IsBusy = false; }
public void ClearItems() { FoundItems.Clear(); }
public void RemoveItem(FoundNotepadItemViewModel doc) { FoundItems.Remove(doc); }
public void AddItem(FoundNotepadItemViewModel doc) { FoundItems.Add(doc); }
/// <summary> /// This button is Search and Stop button, but never at the same time. /// When the button's content is showing 'Search' than it'll start(over) the searching algorithms (in a /// separate task). /// When the button's content is showing 'Stop' than it'll stop the algorithms and jump out of the separate task. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void searchBTN_Click(object sender, RoutedEventArgs e) { if (ModeManager.CurrentMode != RunningMode.Stop) // If the current search button is in fact the 'Stop'-Button, we'll stop, when clicked again. { ModeManager.CurrentMode = RunningMode.Stop; return; } if (!PathIsValid && !Directory.Exists(PathTb.Text)) { MessageBox.Show("Path not set", "Error", new MessageBoxButton(), MessageBoxImage.Error); return; } FoundItems.Items.Clear(); var check = SubfolderCkbx.IsChecked ?? false; var path = PathTb.Text; var searchText = SearchForTb.Text; var extension = ExtensionTb.Text; ModeManager.CurrentMode = RunningMode.Run; Task.Factory.StartNew(() => { //SearchBtn.Dispatcher.Invoke(() => SearchBtn.Content = "Stop"); foreach ( var file in _thatsHowIGatherFiles(path, searchText, extension, check).Where(x => x != null)) { while (ModeManager.CurrentMode == RunningMode.Pause) { } // While we are paused, we'd stuck in an endless loop if (ModeManager.CurrentMode == RunningMode.Stop) { return; // If we should stop, than we jump out of this Task } try { if (!_thatsHowISearch(file, searchText)) { continue; } // If the file doesn't contain the content we wish to see, than we'll continue with other files } catch (Exception ex) { #if DEBUG Console.WriteLine(ex.Message); #endif } FoundItems.Dispatcher.Invoke( () => // Just some invoking, because we're in an other task than the control { FoundItems.Items.Add(file); FoundItems.SelectedIndex = FoundItems.Items.Count - 1; FoundItems.ScrollIntoView(FoundItems.SelectedItem); }); } SearchBtn.Dispatcher.Invoke( () => // Same invoke thingy going on here, which is because we'll change properties of the 'SearchBtn' and the 'PauseBtn' { PauseBtn.Dispatcher.Invoke(() => { ModeManager.CurrentMode = RunningMode.Stop; }); }); // Notify the user, that we are finished now: MessageBox.Show("Done searching"); }); }
private void ClearFoundItemsAndHeader() { SelectedFoundItem = null; FoundItems.Clear(); Header = $"Search - {Version}"; }
/// <summary> /// Limpia la búsqueda /// </summary> public void Clear() { FoundItems.Clear(); OpenedViews.Clear(); }