public async Task <SearchResult <IPackageSearchMetadata> > SearchAsync(string searchText, SearchFilter filter, CancellationToken cancellationToken) { var searchOperationId = Guid.NewGuid(); if (_telemetryService != null) { _telemetryService.EmitTelemetryEvent(new SearchTelemetryEvent( searchOperationId, searchText, filter.IncludePrerelease)); } SearchResult <IPackageSearchMetadata> result; using (var packageSourceTelemetry = new PackageSourceTelemetry(_sourceRepositories.Select(r => r.PackageSource), searchOperationId)) { var searchTasks = TaskCombinators.ObserveErrorsAsync( _sourceRepositories, r => r.PackageSource.Name, (r, t) => r.SearchAsync(searchText, filter, PageSize, t), LogError, cancellationToken); result = await WaitForCompletionOrBailOutAsync( searchText, searchTasks, new TelemetryState(searchOperationId, pageIndex : 0), cancellationToken); if (_telemetryService != null) { packageSourceTelemetry.SendTelemetry(); var protocolDiagnosticTotals = packageSourceTelemetry.GetTotals(); _telemetryService.EmitTelemetryEvent(SourceTelemetry.GetSearchSourceSummaryEvent( searchOperationId, _sourceRepositories.Select(x => x.PackageSource), protocolDiagnosticTotals)); } } return(result); }
private async Task RestoreAsync(bool forceRestore, RestoreOperationSource restoreSource, CancellationToken token) { var startTime = DateTimeOffset.Now; _status = NuGetOperationStatus.NoOp; // start timer for telemetry event var stopWatch = Stopwatch.StartNew(); var projects = Enumerable.Empty <NuGetProject>(); _packageRestoreManager.PackageRestoredEvent += PackageRestoreManager_PackageRestored; _packageRestoreManager.PackageRestoreFailedEvent += PackageRestoreManager_PackageRestoreFailedEvent; var sources = _sourceRepositoryProvider.GetRepositories().Select(s => s.PackageSource); using (var packageSourceTelemetry = new PackageSourceTelemetry(sources, _nuGetProjectContext.OperationId)) { try { var solutionDirectory = _solutionManager.SolutionDirectory; var isSolutionAvailable = await _solutionManager.IsSolutionAvailableAsync(); // Get the projects from the SolutionManager // Note that projects that are not supported by NuGet, will not show up in this list projects = (await _solutionManager.GetNuGetProjectsAsync()).ToList(); if (projects.Any() && solutionDirectory == null) { await _logger.DoAsync((l, _) => { _status = NuGetOperationStatus.Failed; l.ShowError(Resources.SolutionIsNotSaved); l.WriteLine(VerbosityLevel.Minimal, Resources.SolutionIsNotSaved); }); return; } // Check if there are any projects that are not INuGetIntegratedProject, that is, // projects with packages.config. OR // any of the deferred project is type of packages.config, If so, perform package restore on them if (projects.Any(project => !(project is INuGetIntegratedProject))) { await RestorePackagesOrCheckForMissingPackagesAsync( projects, solutionDirectory, isSolutionAvailable, restoreSource, token); } var dependencyGraphProjects = projects .OfType <IDependencyGraphProject>() .ToList(); await RestorePackageSpecProjectsAsync( dependencyGraphProjects, forceRestore, isSolutionAvailable, restoreSource, token); // TODO: To limit risk, we only publish the event when there is a cross-platform PackageReference // project in the solution. Extending this behavior to all solutions is tracked here: // NuGet/Home#4478 if (projects.OfType <NetCorePackageReferenceProject>().Any()) { _restoreEventsPublisher.OnSolutionRestoreCompleted( new SolutionRestoredEventArgs(_status, solutionDirectory)); } } finally { _packageRestoreManager.PackageRestoredEvent -= PackageRestoreManager_PackageRestored; _packageRestoreManager.PackageRestoreFailedEvent -= PackageRestoreManager_PackageRestoreFailedEvent; packageSourceTelemetry.SendTelemetry(); stopWatch.Stop(); var duration = stopWatch.Elapsed; // Do not log any restore message if user disabled restore. if (_packageRestoreConsent.IsGranted) { await _logger.WriteSummaryAsync(_status, duration); } else { _logger.LogDebug(Resources.PackageRefNotRestoredBecauseOfNoConsent); } var protocolDiagnosticsTotals = packageSourceTelemetry.GetTotals(); // Emit telemetry event for restore operation EmitRestoreTelemetryEvent( projects, restoreSource, startTime, duration.TotalSeconds, protocolDiagnosticsTotals); } } }