Exemplo n.º 1
0
        private void _DatabaseSearcher_SearchComplete(object sender, SearchResult e)
        {
            lock ( m_resultLock )
            {
                if (LatestSearchResult == null || e.ID != LatestSearchResult.ID)
                {
                    return;
                }

                EnableShowMoreButton = false;

                int numResultsToDisplay = Math.Min(Settings.MaxResultsDisplayed, e.ValidResults.Count);

                //need to be on the UI thread since we will be creating controls
                Application.Current.Dispatcher.Invoke((Action) delegate
                {
                    m_limitedResultCollection.Clear();

                    for (int i = 0; i < numResultsToDisplay; i++)
                    {
                        Controls.SearchResultControl newResult = new Controls.SearchResultControl();
                        newResult.SearchResultContent          = e.ValidResults[i];

                        newResult.PreviewMouseLeftButtonUp += SearchResult_MouseLeftButtonUp;

                        //if a file is modified we want to know about it so we can re-sort the list if necessary and write the changes to the DB
                        e.ValidResults[i].OnChangedEvent -= _OnFileChanged;
                        e.ValidResults[i].OnChangedEvent += _OnFileChanged;

                        //load the file's icon
                        e.ValidResults[i].LoadFileIcon();

                        m_limitedResultCollection.Add(newResult);
                    }

                    if (m_limitedResultCollection.Count < e.ValidResults.Count)
                    {
                        EnableShowMoreButton = true;
                    }

                    if (m_limitedResultCollection.Count > 0)
                    {
                        if (e.ValidResults.Count > m_limitedResultCollection.Count)
                        {
                            LatestSearchResultDetails = $"Showing top {String.Format("{0:n0}", Settings.MaxResultsDisplayed)} of {String.Format("{0:n0}", e.ValidResults.Count)} results";
                        }
                        else
                        {
                            LatestSearchResultDetails = $"Showing {String.Format("{0:n0}", e.ValidResults.Count)} of {String.Format("{0:n0}", e.ValidResults.Count)} results";
                        }
                    }
                    else
                    {
                        LatestSearchResultDetails = (e.SearchTerm.Length == 0) ? "" : "Showing 0 of 0 results";
                    }
                });
            }

            //remove any invalid results from the database so they don't appear in more searches
            List <List <DBPredicate> > removalPredicates = new List <List <DBPredicate> >();

            for (int i = 0; i < e.InvalidResults.Count; i++)
            {
                List <DBPredicate> filePredicates = new List <DBPredicate>();
                filePredicates.Add(new DBPredicate("path", DBOperator.EQUALS, e.InvalidResults[i].Path));
                removalPredicates.Add(filePredicates);
            }

            try
            {
                m_database.DeleteTransacted("FileCache", removalPredicates);
            }
            catch (Exception crap)
            {
                Settings.SessionLog += crap.Message + "\n";
                Debug.WriteLine(crap.Message);
            }
        }