-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#51 - Add checkbox on Browser tab to include prerelease packages in s…
…earch results. Refactor package content download into separate service.
- Loading branch information
Showing
13 changed files
with
150 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/PackageManager.NuGet/Services/NuGetPackageContentService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using Neptuo; | ||
using Neptuo.Logging; | ||
using NuGet.Common; | ||
using NuGet.Packaging; | ||
using NuGet.Protocol.Core.Types; | ||
using PackageManager.Logging; | ||
using PackageManager.Models; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace PackageManager.Services | ||
{ | ||
public class NuGetPackageContentService | ||
{ | ||
private readonly ILog log; | ||
private readonly ILogger nuGetLog; | ||
private readonly NuGetPackageContent.IFrameworkFilter frameworkFilter; | ||
|
||
public NuGetPackageContentService(ILog log, NuGetPackageContent.IFrameworkFilter frameworkFilter = null) | ||
{ | ||
Ensure.NotNull(log, "log"); | ||
this.log = log.Factory.Scope("Package"); | ||
this.nuGetLog = new NuGetLogger(this.log); | ||
this.frameworkFilter = frameworkFilter; | ||
} | ||
|
||
public async Task<IPackageContent> DownloadAsync(SourceRepository repository, IPackageSearchMetadata package, CancellationToken cancellationToken) | ||
{ | ||
Ensure.NotNull(repository, "repository"); | ||
Ensure.NotNull(package, "package"); | ||
|
||
DownloadResource download = await repository.GetResourceAsync<DownloadResource>(); | ||
if (download == null) | ||
throw Ensure.Exception.InvalidOperation($"Unnable to resolve '{nameof(DownloadResource)}'."); | ||
|
||
using (var sourceCacheContext = new SourceCacheContext()) | ||
{ | ||
var context = new PackageDownloadContext(sourceCacheContext, Path.GetTempPath(), true); | ||
var result = await download.GetDownloadResourceResultAsync(package.Identity, context, String.Empty, nuGetLog, cancellationToken); | ||
if (result.Status == DownloadResourceResultStatus.Cancelled) | ||
throw new OperationCanceledException(); | ||
else if (result.Status == DownloadResourceResultStatus.NotFound) | ||
throw Ensure.Exception.InvalidOperation($"Package '{package.Identity.Id}-v{package.Identity.Version}' not found"); | ||
|
||
return new NuGetPackageContent(new PackageArchiveReader(result.PackageStream), log, frameworkFilter); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.