public static async Task <CrawlerResults> CrawlAsync(NuGetFeed feed, PackageIdentity packageId) { var crawler = new AssemblyCrawler(); var reader = await feed.GetPackageAsync(packageId); foreach (var packagePath in reader.GetFiles()) { await using var assemblyStream = reader.GetStream(packagePath); await using var memoryStream = new MemoryStream(); await assemblyStream.CopyToAsync(memoryStream); memoryStream.Position = 0; var env = new HostEnvironment(); var assembly = env.LoadAssemblyFrom(packagePath, memoryStream); if (assembly is null) { continue; } crawler.Crawl(assembly); } return(crawler.GetResults()); }
public static async Task <CrawlerResults> CrawlAsync(NuGetFeed feed, PackageIdentity packageId) { ArgumentNullException.ThrowIfNull(feed); ArgumentNullException.ThrowIfNull(packageId); var crawler = new AssemblyCrawler(); using var reader = await feed.GetPackageAsync(packageId).ConfigureAwait(false); foreach (var packagePath in reader.GetFiles()) { #pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task await using var assemblyStream = reader.GetStream(packagePath); await using var memoryStream = new MemoryStream(); #pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task await assemblyStream.CopyToAsync(memoryStream).ConfigureAwait(false); memoryStream.Position = 0; using var env = new HostEnvironment(); var assembly = env.LoadAssemblyFrom(packagePath, memoryStream); if (assembly is null) { continue; } crawler.Crawl(assembly); } return(crawler.CreateResults()); }
public async Task <PackageArchiveReader> GetPackageAsync(string id, string version) { var path = GetPackagePath(id, version); if (path != null && File.Exists(path)) { return(new PackageArchiveReader(File.OpenRead(path))); } var identity = new PackageIdentity(id, NuGetVersion.Parse(version)); if (path == null) { return(await _feed.GetPackageAsync(identity)); } var fileStream = File.Create(path); await _feed.CopyPackageStreamAsync(identity, fileStream); fileStream.Position = 0; return(new PackageArchiveReader(fileStream)); }