Skip to content

Commit cacb6f9

Browse files
alericksonanamnavi
authored andcommitted
Clean up interface files (PowerShell#865)
1 parent ee60002 commit cacb6f9

File tree

5 files changed

+10
-351
lines changed

5 files changed

+10
-351
lines changed

src/code/HttpFindPSResource.cs

Lines changed: 7 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
using System;
22
using System.Collections;
3-
using System.Linq;
43
using System.Xml;
54
using Microsoft.PowerShell.PowerShellGet.UtilClasses;
65
using NuGet.Versioning;
76
using System.Collections.Generic;
8-
using System.Xml.Schema;
97

108
namespace Microsoft.PowerShell.PowerShellGet.Cmdlets
119
{
1210
internal class HttpFindPSResource : IFindPSResource
1311
{
14-
V2ServerAPICalls v2ServerAPICall = new V2ServerAPICalls();
12+
#region Members
13+
14+
readonly V2ServerAPICalls v2ServerAPICall = new V2ServerAPICalls();
15+
16+
#endregion
1517

1618
#region Constructor
1719

@@ -28,26 +30,16 @@ public HttpFindPSResource() {}
2830
/// - No prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion
2931
/// - Include prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsAbsoluteLatestVersion&includePrerelease=true
3032
/// </summary>
31-
public PSResourceInfo FindAll(PSRepositoryInfo repository, bool includePrerelease, out string errRecord)
33+
public PSResourceInfo FindAll(PSRepositoryInfo repository, bool includePrerelease, ResourceType type, out string errRecord)
3234
{
33-
var response = string.Empty;
34-
if (includePrerelease)
35-
{
36-
response = v2ServerAPICall.FindAllWithPrerelease(repository, out errRecord);
37-
}
38-
else {
39-
response = v2ServerAPICall.FindAllWithNoPrerelease(repository, out errRecord);
40-
}
35+
var response = v2ServerAPICall.FindAll(repository, includePrerelease, type, out errRecord);
4136

4237
PSResourceInfo currentPkg = null;
4338
if (!string.IsNullOrEmpty(errRecord))
4439
{
4540
return currentPkg;
4641
}
4742

48-
/*
49-
// Convert to PSResourceInfo object
50-
*/
5143
return currentPkg;
5244
}
5345

@@ -177,68 +169,6 @@ public PSCommandResourceInfo[] FindCommandOrDscResource(string[] tags, PSReposit
177169
return cmdInfoObjs.ToArray();
178170
}
179171

180-
181-
/// <summary>
182-
/// Find method which allows for searching for packages with resource type specified from a repository and returns latest version for each.
183-
/// Name: supports wildcards
184-
/// Type: Module, Script, Command, DSCResource (can take multiple)
185-
/// Examples: Search -Type Module -Repository PSGallery
186-
/// Search -Type Module -Name "Az*" -Repository PSGallery
187-
/// TODO: discuss consolidating Modules and Scripts endpoints (move scripts to modules endpoint)
188-
/// TODO Note: searchTerm is tokenized by whitespace.
189-
/// - No prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion&searchTerm='Az* tag:PSModule'
190-
/// - Include prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion&searchTerm='az* tag:PSScript'&includePrerelease=true
191-
/// </summary>
192-
public PSResourceInfo FindTypes(ResourceType packageResourceType, string packageName, PSRepositoryInfo repository, bool includePrerelease, out string errRecord)
193-
{
194-
var response = string.Empty;
195-
if (includePrerelease)
196-
{
197-
response = v2ServerAPICall.FindTypesWithPrerelease(packageResourceType, packageName, repository, out errRecord);
198-
}
199-
else {
200-
response = v2ServerAPICall.FindTypesWithPrerelease(packageResourceType, packageName, repository, out errRecord);
201-
}
202-
203-
PSResourceInfo currentPkg = null;
204-
if (!string.IsNullOrEmpty(errRecord))
205-
{
206-
return currentPkg;
207-
}
208-
209-
// Convert to PSResourceInfo object
210-
return currentPkg;
211-
212-
}
213-
214-
/// <summary>
215-
/// Find method which allows for searching for command names AND/OR DSC resource names and returns latest version of matching packages.
216-
/// Name: supports wildcards.
217-
/// Examples: Search -Name "Command1", "Command2" -Repository PSGallery
218-
/// - No prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion&searchTerm='Az* tag:PSCommand_Command1 tag:PSCommand_Command2'
219-
/// - Include prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion&searchTerm='Az* tag:PSCommand_Command1 tag:PSCommand_Command2'&includePrerelease=true
220-
/// </summary>
221-
public PSResourceInfo FindCommandName(string[] commandNames, PSRepositoryInfo repository, bool includePrerelease, out string errRecord)
222-
{
223-
var response = string.Empty;
224-
if (includePrerelease)
225-
{
226-
response = v2ServerAPICall.FindCommandNameWithPrerelease(commandNames, repository, out errRecord);
227-
}
228-
else {
229-
response = v2ServerAPICall.FindCommandNameWithNoPrerelease(commandNames, repository, out errRecord);
230-
}
231-
232-
PSResourceInfo currentPkg = null;
233-
if (!string.IsNullOrEmpty(errRecord))
234-
{
235-
return currentPkg;
236-
}
237-
238-
// Convert to PSResourceInfo object
239-
return currentPkg;
240-
}
241-
242172
/// <summary>
243173
/// Find method which allows for searching for single name and returns latest version.
244174
/// Name: no wildcard support
@@ -421,40 +351,10 @@ public PSResourceInfo FindVersion(string packageName, string version, PSReposito
421351
return null;
422352
}
423353

424-
/// <summary>
425-
/// *** we will not support this scenario ***
426-
/// Find method which allows for searching for single name with wildcards with version range.
427-
/// Name: supports wildcards
428-
/// Version: support wildcards
429-
/// Examples: Search "PowerShell*" "[3.0.0.0, 5.0.0.0]"
430-
/// Search "PowerShell*" "3.*"
431-
/// </summary>
432-
//PSResourceInfo FindNameGlobbingAndVersionGlobbing(string packageName, VersionRange versionRange, PSRepositoryInfo repository, bool includePrerelease, out string errRecord);
433-
434-
/// <summary>
435-
/// *** we will not support this scenario ***
436-
/// Find method which allows for searching for single name with wildcards with specific version.
437-
/// Name: supports wildcards
438-
/// Version: no wildcard support
439-
/// Examples: Search "PowerShell*" "3.0.0.0"
440-
/// </summary>
441-
//PSResourceInfo FindNameGlobbingAndVersion(string packageName, NuGetVersion version, PSRepositoryInfo repository, out string errRecord);
442-
443-
444-
/// <summary>
445-
/// *** we will not support this scenario ***
446-
/// Find method which allows for searching for multiple names with specific version.
447-
/// Name: supports wildcards
448-
/// Version: no wildcard support
449-
/// Examples: Search "PowerShellGet", "Package*", "PSReadLine" "3.0.0.0"
450-
/// </summary>
451-
//PSResourceInfo FindNamesGlobbingAndVersion(string[] packageNames, NuGetVersion version, PSRepositoryInfo repository)
452-
453354
#endregion
454355

455356
#region HelperMethods
456357

457-
// TODO: in progress
458358
public XmlNode[] ConvertResponseToXML(string httpResponse) {
459359

460360
//Create the XmlDocument.

src/code/IFindPSResource.cs

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public interface IFindPSResource
1313
/// - No prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion
1414
/// - Include prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsAbsoluteLatestVersion&includePrerelease=true
1515
/// </summary>
16-
PSResourceInfo FindAll(PSRepositoryInfo repository, bool includePrerelease, out string errRecord);
16+
PSResourceInfo FindAll(PSRepositoryInfo repository, bool includePrerelease, ResourceType type, out string errRecord);
1717

1818
/// <summary>
1919
/// Find method which allows for searching for packages with tag(s) from a repository and returns latest version for each.
@@ -24,28 +24,6 @@ public interface IFindPSResource
2424
/// </summary>
2525
PSResourceInfo[] FindTags(string[] tags, PSRepositoryInfo repository, bool includePrerelease, ResourceType type, out HashSet<string> tagsFound, out string errRecord);
2626

27-
/// <summary>
28-
/// Find method which allows for searching for packages with resource type specified from a repository and returns latest version for each.
29-
/// Name: supports wildcards
30-
/// Type: Module, Script, Command, DSCResource (can take multiple)
31-
/// Examples: Search -Type Module -Repository PSGallery
32-
/// Search -Type Module -Name "Az*" -Repository PSGallery
33-
/// TODO: discuss consolidating Modules and Scripts endpoints (move scripts to modules endpoint)
34-
/// TODO Note: searchTerm is tokenized by whitespace.
35-
/// - No prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion&searchTerm='Az* tag:PSModule'
36-
/// - Include prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion&searchTerm='az* tag:PSScript'&includePrerelease=true
37-
/// </summary>
38-
PSResourceInfo FindTypes(ResourceType packageResourceType, string packageName, PSRepositoryInfo repository, bool includePrerelease, out string errRecord);
39-
40-
/// <summary>
41-
/// Find method which allows for searching for command names and returns latest version of matching packages.
42-
/// Name: supports wildcards.
43-
/// Examples: Search -Name "Command1", "Command2" -Repository PSGallery
44-
/// - No prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion&searchTerm='Az* tag:PSCommand_Command1 tag:PSCommand_Command2'
45-
/// - Include prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion&searchTerm='Az* tag:PSCommand_Command1 tag:PSCommand_Command2'&includePrerelease=true
46-
/// </summary>
47-
PSResourceInfo FindCommandName(string[] commandNames, PSRepositoryInfo repository, bool includePrerelease, out string errRecord);
48-
4927
/// <summary>
5028
/// Find method which allows for searching for single name and returns latest version.
5129
/// Name: no wildcard support
@@ -88,52 +66,5 @@ public interface IFindPSResource
8866
/// </summary>
8967
PSResourceInfo FindVersion(string packageName, string version, PSRepositoryInfo repository, ResourceType type, out string errRecord);
9068

91-
/// <summary>
92-
/// *** we will not support this scenario ***
93-
/// Find method which allows for searching for single name with wildcards with version range.
94-
/// Name: supports wildcards
95-
/// Version: support wildcards
96-
/// Examples: Search "PowerShell*" "[3.0.0.0, 5.0.0.0]"
97-
/// Search "PowerShell*" "3.*"
98-
/// </summary>
99-
//PSResourceInfo FindNameGlobbingAndVersionGlobbing(string packageName, VersionRange versionRange, PSRepositoryInfo repository, bool includePrerelease, out string errRecord);
100-
101-
/// <summary>
102-
/// *** we will not support this scenario ***
103-
/// Find method which allows for searching for single name with wildcards with specific version.
104-
/// Name: supports wildcards
105-
/// Version: no wildcard support
106-
/// Examples: Search "PowerShell*" "3.0.0.0"
107-
/// </summary>
108-
//PSResourceInfo FindNameGlobbingAndVersion(string packageName, NuGetVersion version, PSRepositoryInfo repository, out string errRecord);
109-
110-
/// <summary>
111-
/// *** Note: we would just iterate through the names client side and call FindName() or FindNameGlobbing() ***
112-
/// Find method which allows for searching for multiple names and returns latest version for each.
113-
/// Name: supports wildcards
114-
/// Examples: Search "PowerShellGet", "Package*", "PSReadLine"
115-
/// </summary>
116-
// PSResourceInfo FindNamesGlobbing(string[] packageNames, PSRepositoryInfo repository, bool includePrerelease, out string[] errRecords);
117-
118-
/// <summary>
119-
/// *** we will not support this scenario ***
120-
/// Find method which allows for searching for multiple names with specific version.
121-
/// Name: supports wildcards
122-
/// Version: no wildcard support
123-
/// Examples: Search "PowerShellGet", "Package*", "PSReadLine" "3.0.0.0"
124-
/// </summary>
125-
//PSResourceInfo FindNamesGlobbingAndVersion(string[] packageNames, NuGetVersion version, PSRepositoryInfo repository, out string errRecord);
126-
127-
/// <summary>
128-
/// *** Note: would just iterate through names client side, and call FindVersionGlobbing() for each and discard (error) for name with globbing) ***
129-
/// Find method which allows for searching for multiple names with version range.
130-
/// Name: supports wildcards
131-
/// Version: support wildcards
132-
/// Examples: Search "PowerShellGet", "Package*", "PSReadLine" "[3.0.0.0, 5.0.0.0]" --> do it for first, write error for second, do it for third
133-
/// Search "PowerShellGet", "Package*", "PSReadLine" "3.*" --> do it for first, write error for second, do it for third
134-
/// Search "Package*", "PSReadLin*" "3.*" --> not supported
135-
/// </summary>
136-
// PSResourceInfo FindNamesAndVersionGlobbing(string[] packageNames, VersionRange versionRange, PSRepositoryInfo repository, bool includePrerelease, ResourceType type, out string[] errRecord);
137-
13869
#endregion
13970
}

src/code/IServerAPICalls.cs

Lines changed: 1 addition & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,13 @@
77
public interface IServerAPICalls
88
{
99
#region Methods
10-
// Find-PSResource >>> IFindPSResource (loops, version) >>> IServerAPICalls (http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion)
11-
12-
/// <summary>
13-
/// Find method which allows for searching for all packages from a repository and returns latest version for each.
14-
/// Examples: Search -Repository PSGallery
15-
/// API call:
16-
/// - Include prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsAbsoluteLatestVersion&includePrerelease=true
17-
/// </summary>
18-
string FindAllWithNoPrerelease(PSRepositoryInfo repository, out string errRecord);
19-
2010
/// <summary>
2111
/// Find method which allows for searching for all packages from a repository and returns latest version for each.
2212
/// Examples: Search -Repository PSGallery
2313
/// API call:
2414
/// - Include prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsAbsoluteLatestVersion&includePrerelease=true
2515
/// </summary>
26-
string FindAllWithPrerelease(PSRepositoryInfo repository, out string errRecord);
27-
16+
string FindAll(PSRepositoryInfo repository, bool includePrerelease, ResourceType type, out string errRecord);
2817

2918
/// <summary>
3019
/// Find method which allows for searching for packages with tag from a repository and returns latest version for each.
@@ -33,37 +22,7 @@ public interface IServerAPICalls
3322
/// - Include prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsAbsoluteLatestVersion&searchTerm='tag:JSON'&includePrerelease=true
3423
/// </summary>
3524
string[] FindTag(string tag, PSRepositoryInfo repository, bool includePrerelease, ResourceType _type, out string errRecord);
36-
37-
38-
/// <summary>
39-
/// Find method which allows for searching for packages with resource type specified from a repository and returns latest version for each.
40-
/// Name: supports wildcards
41-
/// Type: Module, Script, Command, DSCResource (can take multiple)
42-
/// Examples: Search -Type Module -Repository PSGallery
43-
/// Search -Type Module -Name "Az*" -Repository PSGallery
44-
/// TODO: discuss consolidating Modules and Scripts endpoints (move scripts to modules endpoint)
45-
/// TODO Note: searchTerm is tokenized by whitespace.
46-
/// - Include prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion&searchTerm='az* tag:PSScript'&includePrerelease=true
47-
/// </summary>
48-
string FindTypesWithPrerelease(ResourceType packageResourceType, string packageName, PSRepositoryInfo repository, out string errRecord);
49-
50-
51-
/// <summary>
52-
/// Find method which allows for searching for command names and returns latest version of matching packages.
53-
/// Name: supports wildcards.
54-
/// Examples: Search -Name "Command1", "Command2" -Repository PSGallery
55-
/// - No prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion&searchTerm='Az* tag:PSCommand_Command1 tag:PSCommand_Command2'
56-
/// </summary>
57-
string FindCommandNameWithNoPrerelease(string[] commandNames, PSRepositoryInfo repository, out string errRecord);
5825

59-
/// <summary>
60-
/// Find method which allows for searching for command names and returns latest version of matching packages.
61-
/// Name: supports wildcards.
62-
/// Examples: Search -Name "Command1", "Command2" -Repository PSGallery
63-
/// - Include prerelease: http://www.powershellgallery.com/api/v2/Search()?$filter=IsLatestVersion&searchTerm='Az* tag:PSCommand_Command1 tag:PSCommand_Command2'&includePrerelease=true
64-
/// </summary>
65-
string FindCommandNameWithPrerelease(string[] commandNames, PSRepositoryInfo repository, out string errRecord);
66-
6726
/// <summary>
6827
/// Find method which allows for searching for single name and returns latest version.
6928
/// Name: no wildcard support
@@ -96,53 +55,6 @@ public interface IServerAPICalls
9655
/// </summary>
9756
string FindVersionGlobbing(string packageName, VersionRange versionRange, PSRepositoryInfo repository, bool includePrerelease, ResourceType type, out string errRecord);
9857

99-
/// <summary>
100-
/// *** we will not support this scenario ***
101-
/// Find method which allows for searching for single name with wildcards with version range.
102-
/// Name: supports wildcards
103-
/// Version: support wildcards
104-
/// Examples: Search "PowerShell*" "[3.0.0.0, 5.0.0.0]"
105-
/// Search "PowerShell*" "3.*"
106-
/// </summary>
107-
/// PSResourceInfo FindNameGlobbingAndVersionGlobbing(string packageName, VersionRange versionRange, PSRepositoryInfo repository, bool includePrerelease);
108-
109-
/// <summary>
110-
/// *** we will not support this scenario ***
111-
/// Find method which allows for searching for single name with wildcards with specific version.
112-
/// Name: supports wildcards
113-
/// Version: no wildcard support
114-
/// Examples: Search "PowerShell*" "3.0.0.0"
115-
/// </summary>
116-
/// PSResourceInfo FindNameGlobbingAndVersion(string packageName, NuGetVersion version, PSRepositoryInfo repository);
117-
118-
/// <summary>
119-
/// *** Note: we would just iterate through the names client side and call FindName() or FindNameGlobbing() ***
120-
/// Find method which allows for searching for multiple names and returns latest version for each.
121-
/// Name: supports wildcards
122-
/// Examples: Search "PowerShellGet", "Package*", "PSReadLine"
123-
/// </summary>
124-
/// PSResourceInfo FindNamesGlobbing(string[] packageNames, PSRepositoryInfo repository, bool includePrerelease);
125-
126-
/// <summary>
127-
/// *** we will not support this scenario ***
128-
/// Find method which allows for searching for multiple names with specific version.
129-
/// Name: supports wildcards
130-
/// Version: no wildcard support
131-
/// Examples: Search "PowerShellGet", "Package*", "PSReadLine" "3.0.0.0"
132-
/// </summary>
133-
/// PSResourceInfo FindNamesGlobbingAndVersion(string[] packageNames, NuGetVersion version, PSRepositoryInfo repository);
134-
135-
/// <summary>
136-
/// *** Note: would just iterate through names client side, and call FindVersionGlobbing() for each and discard (error) for name with globbing) ***
137-
/// Find method which allows for searching for multiple names with version range.
138-
/// Name: supports wildcards
139-
/// Version: support wildcards
140-
/// Examples: Search "PowerShellGet", "Package*", "PSReadLine" "[3.0.0.0, 5.0.0.0]" --> do it for first, write error for second, do it for third
141-
/// Search "PowerShellGet", "Package*", "PSReadLine" "3.*" --> do it for first, write error for second, do it for third
142-
/// Search "Package*", "PSReadLin*" "3.*" --> not supported
143-
/// </summary>
144-
/// PSResourceInfo FindNamesAndVersionGlobbing(string[] packageNames, VersionRange versionRange, PSRepositoryInfo repository, bool includePrerelease);
145-
14658
// <summary>
14759
/// Find method which allows for searching for single name with specific version.
14860
/// Name: no wildcard support

0 commit comments

Comments
 (0)