src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Tree/Dependencies/GraphNodes/Actions/SearchGraphActionHandler.cs
/// <summary>
/// Generates search graph containing nodes matching search criteria in Solution Explorer 
/// and attaches it to correct top level node.
/// </summary>
Generates search graph containing nodes matching search criteria in Solution Explorer
and attaches it to correct top level node.
Generates search graph containing nodes matching search criteria in Solution Explorer and attaches it to correct top level node .
private void Search(IGraphContext graphContext)
        {
            var searchParametersTypeName = typeof(ISolutionSearchParameters).GUID.ToString();
            var searchParameters = graphContext.GetValue<ISolutionSearchParameters>(searchParametersTypeName);
            if (searchParameters == null)
            {
                return;
            }
            var searchTerm = searchParameters.SearchQuery.SearchString?.ToLowerInvariant();
            if (searchTerm == null)
            {
                return;
            }
            var cachedDependencyToMatchingResultsMap = new Dictionary<string, HashSet<IDependency>>(StringComparer.OrdinalIgnoreCase);
            var searchResultsPerContext = new Dictionary<string, HashSet<IDependency>>(StringComparer.OrdinalIgnoreCase);
            var snapshotProviders = AggregateSnapshotProvider.GetSnapshotProviders();
            foreach (var snapshotProvider in snapshotProviders)
            {
                var snapshot = snapshotProvider.CurrentSnapshot;
                if (snapshot == null)
                {
                    continue;
                }
                searchResultsPerContext[snapshotProvider.ProjectFilePath] = SearchFlat(snapshotProvider.ProjectFilePath,
                                                                                     searchTerm.ToLowerInvariant(),
                                                                                     graphContext,
                                                                                     snapshot);
            }
            foreach (var snapshotProvider in snapshotProviders)
            {
                var snapshot = snapshotProvider.CurrentSnapshot;
                if (snapshot == null)
                {
                    continue;
                }
                var allTopLevelDependencies = snapshot.GetFlatTopLevelDependencies();
                var matchedDependencies = searchResultsPerContext[snapshotProvider.ProjectFilePath];
                using (var scope = new GraphTransactionScope())
                {
                    foreach (var topLevelDependency in allTopLevelDependencies)
                    {
                        var targetedSnapshot = snapshot.Targets[topLevelDependency.TargetFramework];
                        if (!cachedDependencyToMatchingResultsMap
                                .TryGetValue(topLevelDependency.Id, out HashSet<IDependency> topLevelDependencyMatches))
                        {
                            var viewProvider = ViewProviders.FirstOrDefault(x => x.Value.SupportsDependency(topLevelDependency));
                            if (viewProvider == null)
                            {
                                continue;
                            }
                            var processed = viewProvider.Value.MatchSearchResults(
                                snapshotProvider.ProjectFilePath,
                                topLevelDependency,
                                searchResultsPerContext,
                                out topLevelDependencyMatches);
                            if (!processed)
                            {
                                if (matchedDependencies.Count == 0)
                                {
                                    continue;
                                }
                                topLevelDependencyMatches = GetMatchingResultsForDependency(
                                    topLevelDependency,
                                    targetedSnapshot,
                                    matchedDependencies,
                                    cachedDependencyToMatchingResultsMap);
                            }
                            cachedDependencyToMatchingResultsMap[topLevelDependency.Id] = topLevelDependencyMatches;
                        }
                        if (topLevelDependencyMatches.Count == 0)
                        {
                            continue;
                        }
                        var topLevelNode = Builder.AddTopLevelGraphNode(graphContext,
                                                                snapshotProvider.ProjectFilePath,
                                                                topLevelDependency.ToViewModel(targetedSnapshot));
                        foreach (var matchedDependency in topLevelDependencyMatches)
                        {
                            var matchedDependencyNode = Builder.AddGraphNode(graphContext,
                                                                    snapshotProvider.ProjectFilePath,
                                                                    topLevelNode,
                                                                    matchedDependency.ToViewModel(targetedSnapshot));
                            graphContext.Graph.Links.GetOrCreate(topLevelNode,
                                                                 matchedDependencyNode,
                                                                 null ,
                                                                 GraphCommonSchema.Contains);
                        }
                        if (topLevelNode != null)
                        {
                            topLevelNode.AddCategory(CodeNodeCategories.ProjectItem);
                        }
                    }
                    scope.Complete();
                }
            }
            graphContext.OnCompleted();
        }
private void Search ( IGraphContext graphContext ) { var searchParametersTypeName = typeof ( ISolutionSearchParameters ) . GUID . ToString ( ) ; var searchParameters = graphContext . GetValue < ISolutionSearchParameters > ( searchParametersTypeName ) ; if ( searchParameters == null ) { return ; } var searchTerm = searchParameters . SearchQuery . SearchString ? . ToLowerInvariant ( ) ; if ( searchTerm == null ) { return ; } var cachedDependencyToMatchingResultsMap = new Dictionary < string , HashSet < IDependency > > ( StringComparer . OrdinalIgnoreCase ) ; var searchResultsPerContext = new Dictionary < string , HashSet < IDependency > > ( StringComparer . OrdinalIgnoreCase ) ; var snapshotProviders = AggregateSnapshotProvider . GetSnapshotProviders ( ) ; foreach ( var snapshotProvider in snapshotProviders ) { var snapshot = snapshotProvider . CurrentSnapshot ; if ( snapshot == null ) { continue ; } searchResultsPerContext [ snapshotProvider . ProjectFilePath ] = SearchFlat ( snapshotProvider . ProjectFilePath , searchTerm . ToLowerInvariant ( ) , graphContext , snapshot ) ; } foreach ( var snapshotProvider in snapshotProviders ) { var snapshot = snapshotProvider . CurrentSnapshot ; if ( snapshot == null ) { continue ; } var allTopLevelDependencies = snapshot . GetFlatTopLevelDependencies ( ) ; var matchedDependencies = searchResultsPerContext [ snapshotProvider . ProjectFilePath ] ; using ( var scope = new GraphTransactionScope ( ) ) { foreach ( var topLevelDependency in allTopLevelDependencies ) { var targetedSnapshot = snapshot . Targets [ topLevelDependency . TargetFramework ] ; if ( ! cachedDependencyToMatchingResultsMap . TryGetValue ( topLevelDependency . Id , out HashSet < IDependency > topLevelDependencyMatches ) ) { var viewProvider = ViewProviders . FirstOrDefault ( x => x . Value . SupportsDependency ( topLevelDependency ) ) ; if ( viewProvider == null ) { continue ; } var processed = viewProvider . Value . MatchSearchResults ( snapshotProvider . ProjectFilePath , topLevelDependency , searchResultsPerContext , out topLevelDependencyMatches ) ; if ( ! processed ) { if ( matchedDependencies . Count == 0 ) { continue ; } topLevelDependencyMatches = GetMatchingResultsForDependency ( topLevelDependency , targetedSnapshot , matchedDependencies , cachedDependencyToMatchingResultsMap ) ; } cachedDependencyToMatchingResultsMap [ topLevelDependency . Id ] = topLevelDependencyMatches ; } if ( topLevelDependencyMatches . Count == 0 ) { continue ; } var topLevelNode = Builder . AddTopLevelGraphNode ( graphContext , snapshotProvider . ProjectFilePath , topLevelDependency . ToViewModel ( targetedSnapshot ) ) ; foreach ( var matchedDependency in topLevelDependencyMatches ) { var matchedDependencyNode = Builder . AddGraphNode ( graphContext , snapshotProvider . ProjectFilePath , topLevelNode , matchedDependency . ToViewModel ( targetedSnapshot ) ) ; graphContext . Graph . Links . GetOrCreate ( topLevelNode , matchedDependencyNode , null , GraphCommonSchema . Contains ) ; } if ( topLevelNode != null ) { topLevelNode . AddCategory ( CodeNodeCategories . ProjectItem ) ; } } scope . Complete ( ) ; } } graphContext . OnCompleted ( ) ; }
Generates search graph containing nodes matching search criteria in Solution Explorer
and attaches it to correct top level node.
Generates search graph containing nodes matching search criteria in Solution Explorer and attaches it to correct top level node .
/*label*/ // 'node' is a GraphNode for top level dependency (which is part of solution explorer tree) // Setting ProjectItem category (and correct GraphNodeId) ensures that search graph appears  // under right solution explorer hierarchy item
graphContext
IGraphContext