private async void btnSearch_Click(object sender, EventArgs e) { var directory = txbDirectory.Text.Trim(); var searchString = txbSearchString.Text; if (string.IsNullOrEmpty(directory)) { MessageBox.Show("Please, specify directory"); return; } if (string.IsNullOrEmpty(searchString)) { MessageBox.Show("Please, specify search string"); return; } lblResult.Text = string.Empty; lbxResult.Items.Clear(); btnStop.Enabled = true; btnSearch.Enabled = false; prbSearchingProgress.Value = 0; prbSearchingProgress.Visible = true; _timer.Start(); var fileSearchResult = await Task.Factory.StartNew(() => _fileSearcher.SearchFiles(new FileSearcherQuery { TargetDirectory = directory, SearchString = searchString })); _timer.Stop(); lblResult.Text = string.Format("Found {0} files \n", fileSearchResult.Files.Count()); prbSearchingProgress.Visible = false; WriteResult(fileSearchResult); btnSearch.Enabled = true; btnStop.Enabled = false; }
public JsonResult SearchFiles(SearchViewModel search) { _profileHelper.SetProfileValue <string>(User.Identity.Name, ProfileKeyLastSearch, search.searchString); _profileHelper.SetProfileValue <bool>(User.Identity.Name, ProfileSearchFileNamesOnly, search.searchFileNamesOnly); var results = _templateSearcher.SearchFiles(search.searchString, search.searchFileNamesOnly); return(Json(new { total = results.Count, data = results }, JsonRequestBehavior.AllowGet)); }