Beispiel #1
0
        /// <summary>
        /// Handles search completion.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event arguments.</param>
        private void searchWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            IsSearching = false;
            if (e.Result != null)
            {
                var result = (Tuple <IEnumerable <ISearchHit>, int, string>)e.Result;

                if (result.Item2 > 0)
                {
                    // Start background worker, which will count the total number of matches
                    if (!mRequery)
                    {
                        if (mCountMatches)
                        {
                            IsCountingMatches = true;
                            if (mSearchHitCountWorker != null)
                            {
                                mSearchHitCountWorker.CancelAsync();
                                DetachFromSearchHitCountBackgroundWorker();
                            }
                            mSearchHitCountWorker = new BackgroundWorker();
                            mSearchHitCountWorker.WorkerReportsProgress      = true;
                            mSearchHitCountWorker.WorkerSupportsCancellation = true;
                            mSearchHitCountWorker.DoWork             += searchHitCounter_DoWork;
                            mSearchHitCountWorker.RunWorkerCompleted += searchHitCounter_RunWorkerCompleted;
                            mSearchHitCountWorker.ProgressChanged    += searchHitCounter_ProgressChanged;
                            mSearchHitCountWorker.RunWorkerAsync(result.Item1);
                        }
                    }
                    var resultsEnumerable = new ObservableEnumerable();
                    resultsEnumerable.Enumerable = CreateViewModelsForSearchResults(result.Item1, resultsEnumerable);
                    SearchResults = resultsEnumerable;
                }
                else
                {
                    SearchResults   = new SearchHitViewModel[] {};
                    TotalMatchCount = 0;
                }

                // Set results.
                SearchResultCount  = result.Item2;
                SearchResultsQuery = result.Item3;
            }
            else
            {
                // Set results.
                SearchResultCount = 0;
                TotalMatchCount   = 0;
                SearchResults     = null;
            }

            // Restart search if requested.
            if (mRequery)
            {
                mRequery = false;
                StartSearch(mSearchType, mSearchQuery, mUseFileTypeFilter ? FileTypeFilter.AllowedFileTypes : null, mUseDirectoryFilter ? DirectoryFilter.AllowedDirectories : null);
            }
        }
        /// <summary>
        /// Returns an existing or creates a new view model for the specified search hit.
        /// </summary>
        /// <param name="searchHit">Search hit for which a view model should be returned, or created.</param>
        /// <param name="parent">Parent enumerable</param>
        /// <returns>Created or existing view model.</returns>
        public static SearchHitViewModel GetOrCreateSearchHitViewModel(Engine.Interfaces.ISearchHit searchHit, ObservableEnumerable parent)
        {
            SearchHitViewModel viewModel = null;

            if (!mViewModels.TryGetValue(searchHit, out viewModel))
            {
                viewModel = new SearchHitViewModel(searchHit, parent);
                mViewModels.Add(searchHit, viewModel);
            }
            return(viewModel);
        }
 /// <summary>
 /// Initialization constructor.
 /// </summary>
 /// <param name="searchHit">Underlying search hit.</param>
 private SearchHitViewModel(Engine.Interfaces.ISearchHit searchHit, ObservableEnumerable parent)
 {
     mParent    = parent;
     mSearchHit = searchHit;
 }
Beispiel #4
0
        /// <summary>
        /// Processes search results and creates a SearchHitViewModel for each search result.
        /// </summary>
        /// <param name="searchResults">Search results, for which view models should be created.</param>
        /// <returns></returns>
        private static IEnumerable CreateViewModelsForSearchResults(IEnumerable <ISearchHit> searchResults, ObservableEnumerable parent)
        {
            if (searchResults != null)
            {
                foreach (var searchResult in searchResults)
                {
                    SearchHitViewModel viewModel = ViewModel.SearchHitViewModel.GetOrCreateSearchHitViewModel(searchResult, parent);
                    yield return(viewModel);

                    if (viewModel.IsExpanded)
                    {
                        foreach (var occurrence in viewModel.Occurrences)
                        {
                            yield return(occurrence);
                        }
                    }
                }
            }
            yield break;
        }