public virtual async Task <ActionResult> Search(SearchRequest request) { Trace.TraceInformation("[NuGet.Search] Package: " + request.SearchTerm + " Source: " + request.Source); if (string.IsNullOrEmpty(request.SearchTerm)) { throw new UserActionException("Package Name is required during search", "CON.NUGET.SP1", new ArgumentNullException("PackageID")); } NuGetPackageSearchResponse model = await _cache.SearchPackages(request.SearchTerm, request.Source); return(View(model)); }
public async Task <NuGetPackageSearchResponse> SearchPackages(string searchTerm, string source) { if (string.IsNullOrEmpty(searchTerm)) { throw new ArgumentNullException("searchTerm"); } if (string.IsNullOrEmpty(source)) { throw new ArgumentNullException("source"); } NuGetFactory factory = new NuGetFactory(source); var model = new NuGetPackageSearchResponse { Request = new NuGetPackageSearchRequest { SearchKeyword = searchTerm, Source = source, SourceUrl = factory.SourceUrl } }; var searchResource = await factory.GetSearch(); var packageMeta = await searchResource.Search(searchTerm, new SearchFilter { IncludePrerelease = true }, 0, 100, CancellationToken.None); var packagesFound = packageMeta.ToList(); foreach (var searchInfo in packagesFound) { var result = new NuGetPackageSearchResult(); result.Title = searchInfo.Title; result.Summary = searchInfo.Summary; result.DownloadCount = searchInfo.LatestPackageMetadata.DownloadCount; result.IconUri = searchInfo.LatestPackageMetadata.IconUrl; result.PackageID = searchInfo.Identity.Id; result.LatestVersion = searchInfo.LatestPackageMetadata.Identity.Version.ToNormalizedString(); result.Authors = searchInfo.LatestPackageMetadata.Authors; result.Tags = searchInfo.LatestPackageMetadata.Tags; model.Results.Add(result); } return(model); }