Example #1
0
        private void SearchCode(string searchPattern, string filePathPattern, bool immediate)
        {
            var maxResults = GlobalSettings.SearchCodeMaxResults;
            var request    = CreateSearchCodeRequest(searchPattern, filePathPattern, maxResults);

            SearchWorker(new SearchWorkerParams {
                OperationName = OperationsIds.SearchCode,
                HintText      = "Searching for matching text in files...",
                Delay         = TimeSpan.FromMilliseconds(immediate ? 0 : GlobalSettings.AutoSearchDelayMsec),
                TypedRequest  = request,
                ProcessError  = (errorResponse, stopwatch) => {
                    var viewModel = CreateErrorResponseViewModel(errorResponse);
                    ViewModel.SetSearchCodeResult(viewModel);
                    _searchResultDocumentChangeTracker.Disable();
                },
                ProcessResponse = (typedResponse, stopwatch) => {
                    var response = ((SearchCodeResponse)typedResponse);
                    var msg      = string.Format("Found {0:n0} results among {1:n0} files ({2:0.00} seconds) matching text \"{3}\"",
                                                 response.HitCount,
                                                 response.SearchedFileCount,
                                                 stopwatch.Elapsed.TotalSeconds,
                                                 searchPattern);
                    if (ViewModel.MatchCase)
                    {
                        msg += ", Match case";
                    }
                    if (ViewModel.MatchWholeWord)
                    {
                        msg += ", Whole word";
                    }
                    if (ViewModel.UseRegex)
                    {
                        msg += ", Regular expression";
                    }
                    if (!string.IsNullOrEmpty(filePathPattern))
                    {
                        msg += string.Format(", File Paths: \"{0}\"", filePathPattern);
                    }
                    var limitMsg   = CreateMaxResultsHitMessage(response.HitCount, maxResults);
                    bool expandAll = response.HitCount < HardCodedSettings.SearchCodeExpandMaxResults;
                    var result     = CreateSearchCodeResultViewModel(response.SearchResults, msg, limitMsg, ViewModel.ExpandAll);
                    ViewModel.SetSearchCodeResult(result);
                    _searchResultDocumentChangeTracker.Enable(response.SearchResults);

                    // Perform additional search if few results and search was restrictive
                    if (response.HitCount <= HardCodedSettings.LowHitCountWarrantingAdditionalSearch)
                    {
                        if (request.SearchParams.MatchCase || request.SearchParams.MatchWholeWord)
                        {
                            SearchCodeLessRestrictive(searchPattern, filePathPattern, response.HitCount);
                        }
                    }
                }
            });
        }
Example #2
0
 private void SearchCode(string searchPattern, string filePathPattern, bool immediate)
 {
     SearchWorker(new SearchWorkerParams {
         OperationName = OperationsIds.SearchCode,
         HintText      = "Searching for matching text in files...",
         Delay         = TimeSpan.FromMilliseconds(immediate ? 0 : GlobalSettings.AutoSearchDelayMsec),
         TypedRequest  = new SearchCodeRequest {
             SearchParams = new SearchParams {
                 SearchString    = searchPattern,
                 FilePathPattern = filePathPattern,
                 MaxResults      = GlobalSettings.SearchCodeMaxResults,
                 MatchCase       = ViewModel.MatchCase,
                 MatchWholeWord  = ViewModel.MatchWholeWord,
                 IncludeSymLinks = ViewModel.IncludeSymLinks,
                 UseRe2Engine    = true,
                 Regex           = ViewModel.UseRegex,
             }
         },
         ProcessError = (errorResponse, stopwatch) => {
             var viewModel = CreateErrorResponseViewModel(errorResponse);
             ViewModel.SetSearchCodeResult(viewModel);
             _searchResultDocumentChangeTracker.Disable();
         },
         ProcessResponse = (typedResponse, stopwatch) => {
             var response = ((SearchCodeResponse)typedResponse);
             var msg      = string.Format("Found {0:n0} results among {1:n0} files ({2:0.00} seconds) matching text \"{3}\"",
                                          response.HitCount,
                                          response.SearchedFileCount,
                                          stopwatch.Elapsed.TotalSeconds,
                                          searchPattern);
             if (ViewModel.MatchCase)
             {
                 msg += ", Match case";
             }
             if (ViewModel.MatchWholeWord)
             {
                 msg += ", Whole word";
             }
             if (ViewModel.UseRegex)
             {
                 msg += ", Regular expression";
             }
             if (!string.IsNullOrEmpty(filePathPattern))
             {
                 msg += string.Format(", File Paths: \"{0}\"", filePathPattern);
             }
             bool expandAll = response.HitCount < HardCodedSettings.SearchCodeExpandMaxResults;
             var result     = CreateSearchCodeResultViewModel(response.SearchResults, msg, expandAll);
             ViewModel.SetSearchCodeResult(result);
             _searchResultDocumentChangeTracker.Enable(response.SearchResults);
         }
     });
 }