Repository navigation
Expand file tree
/
Copy pathFindPackageCommand.cs
More file actions
97 lines (85 loc) · 3.93 KB
/
Copy pathFindPackageCommand.cs
File metadata and controls
97 lines (85 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Linq;
using System.Management.Automation;
using NuGet.VisualStudio;
namespace NuGet.PowerShell.Commands
{
/// <summary>
/// FindPackage is identical to GetPackage except that FindPackage filters packages only by Id and does not consider description or tags.
/// </summary>
[Cmdlet(VerbsCommon.Find, "Package", DefaultParameterSetName = "Default")]
[OutputType(typeof(IPackage))]
public class FindPackageCommand : GetPackageCommand
{
private const int MaxReturnedPackages = 30;
public FindPackageCommand()
: this(ServiceLocator.GetInstance<IPackageRepositoryFactory>(),
ServiceLocator.GetInstance<IVsPackageSourceProvider>(),
ServiceLocator.GetInstance<ISolutionManager>(),
ServiceLocator.GetInstance<IVsPackageManagerFactory>(),
ServiceLocator.GetInstance<IHttpClientEvents>())
{
}
public FindPackageCommand(IPackageRepositoryFactory repositoryFactory,
IVsPackageSourceProvider packageSourceProvider,
ISolutionManager solutionManager,
IVsPackageManagerFactory packageManagerFactory,
IHttpClientEvents httpClientEvents)
: base(repositoryFactory, packageSourceProvider, solutionManager, packageManagerFactory, httpClientEvents, null)
{
}
/// <summary>
/// Determines if an exact Id match would be performed with the Filter parameter. By default, FindPackage returns all packages that starts with the
/// Filter value.
/// </summary>
[Parameter]
public SwitchParameter ExactMatch { get; set; }
protected override void ProcessRecordCore()
{
// Since this is used for intellisense, we need to limit the number of packages that we return. Otherwise,
// typing InstallPackage TAB would download the entire feed.
First = MaxReturnedPackages;
base.ProcessRecordCore();
}
protected override IQueryable<IPackage> GetPackages(IPackageRepository sourceRepository)
{
IQueryable<IPackage> packages;
if (!String.IsNullOrEmpty(Filter))
{
if (ExactMatch)
{
packages = sourceRepository.FindPackagesById(Filter).AsQueryable();
}
else
{
packages = sourceRepository.GetPackages()
.Where(p => p.Id.ToLower().StartsWith(Filter.ToLower()));
}
}
else
{
packages = sourceRepository.GetPackages();
}
return packages.OrderByDescending(p => p.DownloadCount)
.ThenBy(p => p.Id)
.AsQueryable();
}
protected override IQueryable<IPackage> GetPackagesForUpdate(IPackageRepository sourceRepository)
{
IPackageRepository localRepository = PackageManager.LocalRepository;
var packagesToUpdate = localRepository.GetPackages();
if (!String.IsNullOrEmpty(Filter))
{
packagesToUpdate = packagesToUpdate.Where(p => p.Id.StartsWith(Filter, StringComparison.OrdinalIgnoreCase));
}
return sourceRepository.GetUpdates(packagesToUpdate, IncludePrerelease, includeAllVersions: AllVersions)
.OrderByDescending(p => p.DownloadCount)
.ThenBy(p => p.Id)
.AsQueryable();
}
protected override void LogCore(MessageLevel level, string formattedMessage)
{
// We don't want this cmdlet to print anything
}
}
}