Пример #1
0
 public DependenciesTreeSearchContext(IRelationshipSearchParameters parameters, Action <ISearchResult> resultAccumulator)
 {
     _searchString      = parameters.SearchQuery.SearchString;
     _maximumResults    = checked ((int)parameters.MaximumResults);
     _resultAccumulator = resultAccumulator;
     _cts = CancellationTokenSource.CreateLinkedTokenSource(parameters.CancellationToken);
 }
        public void Search(IRelationshipSearchParameters parameters, Action <ISearchResult> resultAccumulator)
        {
            Requires.NotNull(parameters, nameof(parameters));
            Requires.NotNull(resultAccumulator, nameof(resultAccumulator));

            if (_providers.Length == 0)
            {
                // No providers registered
                return;
            }

            if (!parameters.Options.SearchExternalItems)
            {
                // Consider the dependencies tree as containing 'external items', allowing the
                // tree to be excluded from search results via this option.
                return;
            }

            using var context = new DependenciesTreeSearchContext(parameters, resultAccumulator);

            _joinableTaskContext.Factory.Run(SearchSolutionAsync);

            Task SearchSolutionAsync()
            {
                // Search projects concurrently
                return(Task.WhenAll(_projectServiceAccessor.GetProjectService().LoadedUnconfiguredProjects.Select(SearchProjectAsync)));
            }

            async Task SearchProjectAsync(UnconfiguredProject unconfiguredProject)
            {
                IUnconfiguredProjectVsServices?  projectVsServices         = unconfiguredProject.Services.ExportProvider.GetExportedValue <IUnconfiguredProjectVsServices>();
                IActiveConfigurationGroupService?configurationGroupService = unconfiguredProject.Services.ExportProvider.GetExportedValue <IActiveConfigurationGroupService>();
                IProjectTree?dependenciesNode = projectVsServices?.ProjectTree.CurrentTree?.FindChildWithFlags(DependencyTreeFlags.DependenciesRootNode);

                if (projectVsServices != null &&
                    dependenciesNode != null &&
                    configurationGroupService is IActiveConfigurationGroupService2 activeConfigurationGroupService)
                {
                    IConfigurationGroup <ConfiguredProject> configuredProjects = await activeConfigurationGroupService.GetActiveLoadedConfiguredProjectGroupAsync();

                    var projectContext = new DependenciesTreeProjectSearchContext(context, unconfiguredProject, dependenciesNode, _hierarchyItemManager, projectVsServices, _relationProvider);

                    // Search providers concurrently
                    await Task.WhenAll(_providers.Select(provider => provider.SearchAsync(projectContext)));
                }
            }
        }