re-implement hide of nuget api key in build logs, add more tests for it
[teamcity/dotNetPackagesSupport.git] / nuget-extensions / nuget-commands / src / ListCommandBase.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.ComponentModel.Composition;\r
4 using System.Linq;\r
5 using System.Linq.Expressions;\r
6 using JetBrains.TeamCity.NuGet.ExtendedCommands.Util;\r
7 using NuGet;\r
8 \r
9 namespace JetBrains.TeamCity.NuGet.ExtendedCommands\r
10 {\r
11   public abstract class ListCommandBase : CommandBase\r
12   {\r
13     [Import]\r
14     public IPackageRepositoryFactory RepositoryFactory { get; set; }\r
15 \r
16     [Import]\r
17     public IPackageSourceProvider SourceProvider { get; set; }\r
18 \r
19     protected IEnumerable<IPackage> GetAllPackages(string source, IEnumerable<string> ids)\r
20     {\r
21       IPackageRepository packageRepository = RepositoryFactory.CreateRepository(source);\r
22 \r
23       var param = Expression.Parameter(typeof (IPackageMetadata));\r
24 \r
25       Expression result = Expression.Constant(true);\r
26       foreach (var id in ids)\r
27       {\r
28         result = Expression.Equal(Expression.Property(param, "Id"), Expression.Constant(id));\r
29       }\r
30 \r
31       return packageRepository.GetPackages().Where(Expression.Lambda<Func<IPackage, bool>>(result, param));\r
32     }\r
33 \r
34     protected static void PrintPackageInfo(IPackage p)\r
35     {\r
36       var msg = ServiceMessageFormatter.FormatMessage(\r
37         "nuget-package",\r
38         new ServiceMessageProperty("Id", p.Id),\r
39         new ServiceMessageProperty("Version", p.Version.ToString())\r
40         );\r
41 \r
42       System.Console.Out.WriteLine(msg);\r
43     }\r
44 \r
45   }\r
46 }