Skip to content

Commit 992743e

Browse files
authored
Concurrent installation (#1950)
1 parent d389d79 commit 992743e

25 files changed

Lines changed: 1656 additions & 555 deletions

src/code/ContainerRegistryServerAPICalls.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections;
6+
using System.Collections.Concurrent;
67
using System.Collections.Generic;
78
using System.Collections.ObjectModel;
89
using System.IO;
@@ -81,6 +82,16 @@ public ContainerRegistryServerAPICalls(PSRepositoryInfo repository, PSCmdlet cmd
8182

8283
#region Overridden Methods
8384

85+
public override Task<FindResults> FindVersionAsync(string packageName, string version, ResourceType type, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> warningMsgs, ConcurrentQueue<string> debugMsgs, ConcurrentQueue<string> verboseMsgs)
86+
{
87+
throw new NotImplementedException("FindVersionAsync is not implemented for ContainerRegistryServerAPICalls.");
88+
}
89+
90+
public override Task<FindResults> FindVersionGlobbingAsync(string packageName, VersionRange versionRange, bool includePrerelease, ResourceType type, bool getOnlyLatest, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> warningMsgs, ConcurrentQueue<string> debugMsgs, ConcurrentQueue<string> verboseMsgs)
91+
{
92+
throw new NotImplementedException("FindVersionGlobbingAsync is not implemented for ContainerRegistryServerAPICalls.");
93+
}
94+
8495
/// <summary>
8596
/// Find method which allows for searching for all packages from a repository and returns latest version for each.
8697
/// </summary>
@@ -146,6 +157,12 @@ public override FindResults FindName(string packageName, bool includePrerelease,
146157
return new FindResults(stringResponse: new string[] { }, hashtableResponse: pkgResult.ToArray(), responseType: containerRegistryFindResponseType);
147158
}
148159

160+
161+
public override Task<FindResults> FindNameAsync(string packageName, bool includePrerelease, ResourceType type, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> warningMsgs, ConcurrentQueue<string> debugMsgs, ConcurrentQueue<string> verboseMsgs)
162+
{
163+
throw new NotImplementedException("FindNameAsync is not implemented for ContainerRegistryServerAPICalls.");
164+
}
165+
149166
/// <summary>
150167
/// Find method which allows for searching for single name and tag and returns latest version.
151168
/// Name: no wildcard support
@@ -302,6 +319,19 @@ public override Stream InstallPackage(string packageName, string packageVersion,
302319
return results;
303320
}
304321

322+
/// <summary>
323+
/// Installs a specific package asynchronously.
324+
/// User may request to install package with or without providing version (as seen in examples below), but prior to calling this method the package is located and package version determined.
325+
/// Therefore, package version should not be null in this method.
326+
/// Name: no wildcard support.
327+
/// Examples: Install "PowerShellGet" -Version "3.5.0-alpha"
328+
/// Install "PowerShellGet" -Version "3.0.0"
329+
/// </summary>
330+
public override Task<Stream> InstallPackageAsync(string packageName, string packageVersion, bool includePrerelease, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> warningMsgs, ConcurrentQueue<string> debugMsgs, ConcurrentQueue<string> verboseMsgs)
331+
{
332+
throw new NotImplementedException("FindNameAsync is not implemented for ContainerRegistryServerAPICalls.");
333+
}
334+
305335
/// <summary>
306336
/// Installs a package with version specified.
307337
/// Version can be prerelease or stable.

src/code/FindHelper.cs

Lines changed: 392 additions & 227 deletions
Large diffs are not rendered by default.

src/code/GetHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

44
using Microsoft.PowerShell.PSResourceGet.UtilClasses;

src/code/InstallHelper.cs

Lines changed: 224 additions & 148 deletions
Large diffs are not rendered by default.

src/code/InstallPSResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ protected override void ProcessRecord()
292292
case InputObjectParameterSet:
293293
foreach (var inputObj in InputObject)
294294
{
295-
string normalizedVersionString = Utils.GetNormalizedVersionString(inputObj.Version.ToString(), inputObj.Prerelease);
295+
string normalizedVersionString = Utils.GetFullVersionString(inputObj.Version.ToString(), inputObj.Prerelease);
296296
ProcessInstallHelper(
297297
pkgNames: new string[] { inputObj.Name },
298298
pkgVersion: normalizedVersionString,

src/code/LocalServerApiCalls.cs

Lines changed: 106 additions & 38 deletions
Large diffs are not rendered by default.

src/code/NuGetServerAPICalls.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using System.Net;
1414
using System.Runtime.ExceptionServices;
1515
using System.Management.Automation;
16+
using System.Collections.Concurrent;
1617

1718
namespace Microsoft.PowerShell.PSResourceGet.Cmdlets
1819
{
@@ -48,6 +49,15 @@ public NuGetServerAPICalls (PSRepositoryInfo repository, PSCmdlet cmdletPassedIn
4849

4950
#region Overridden Methods
5051

52+
public override Task<FindResults> FindVersionAsync(string packageName, string version, ResourceType type, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> warningMsgs, ConcurrentQueue<string> debugMsgs, ConcurrentQueue<string> verboseMsgs)
53+
{
54+
throw new NotImplementedException("FindVersionAsync is not implemented for NuGetServerAPICalls.");
55+
}
56+
57+
public override Task<FindResults> FindVersionGlobbingAsync(string packageName, VersionRange versionRange, bool includePrerelease, ResourceType type, bool getOnlyLatest, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> warningMsgs, ConcurrentQueue<string> debugMsgs, ConcurrentQueue<string> verboseMsgs)
58+
{
59+
throw new NotImplementedException("FindVersionGlobbingAsync is not implemented for NuGetServerAPICalls.");
60+
}
5161
/// <summary>
5262
/// Find method which allows for searching for all packages from a repository and returns latest version for each.
5363
/// Examples: Search -Repository MyNuGetServer
@@ -183,6 +193,11 @@ public override FindResults FindName(string packageName, bool includePrerelease,
183193
return new FindResults(stringResponse: new string[]{ response }, hashtableResponse: emptyHashResponses, responseType: FindResponseType);
184194
}
185195

196+
public override Task<FindResults> FindNameAsync(string packageName, bool includePrerelease, ResourceType type, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> warningMsgs, ConcurrentQueue<string> debugMsgs, ConcurrentQueue<string> verboseMsgs)
197+
{
198+
throw new NotImplementedException("FindNameAsync is not implemented for NuGetServerAPICalls.");
199+
}
200+
186201
/// <summary>
187202
/// Find method which allows for searching for single name and tag and returns latest version.
188203
/// Name: no wildcard support
@@ -446,6 +461,19 @@ public override Stream InstallPackage(string packageName, string packageVersion,
446461
return results;
447462
}
448463

464+
/// <summary>
465+
/// Installs a specific package asynchronously.
466+
/// User may request to install package with or without providing version (as seen in examples below), but prior to calling this method the package is located and package version determined.
467+
/// Therefore, package version should not be null in this method.
468+
/// Name: no wildcard support.
469+
/// Examples: Install "PowerShellGet" -Version "3.5.0-alpha"
470+
/// Install "PowerShellGet" -Version "3.0.0"
471+
/// </summary>
472+
public override Task<Stream> InstallPackageAsync(string packageName, string packageVersion, bool includePrerelease, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> warningMsgs, ConcurrentQueue<string> debugMsgs, ConcurrentQueue<string> verboseMsgs)
473+
{
474+
throw new NotImplementedException("InstallPackageAsync is not implemented for NuGetServerAPICalls.");
475+
}
476+
449477
/// <summary>
450478
/// Helper method that makes the HTTP request for the NuGet server protocol url passed in for find APIs.
451479
/// </summary>

src/code/PSResourceInfo.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,7 @@ private static Dependency[] GetDependencies(ArrayList dependencyInfos)
15351535

15361536
private static string ConcatenateVersionWithPrerelease(string version, string prerelease)
15371537
{
1538-
return Utils.GetNormalizedVersionString(version, prerelease);
1538+
return Utils.GetThreeDigitNormalizedVersionString(version, prerelease);
15391539
}
15401540

15411541
#endregion
@@ -1820,9 +1820,8 @@ private static ResourceType ParseHttpMetadataTypeForLocalRepo(
18201820

18211821
private PSObject ConvertToCustomObject()
18221822
{
1823-
// 1.0.0-alpha1
1824-
// 1.0.0.0
1825-
string NormalizedVersion = IsPrerelease ? ConcatenateVersionWithPrerelease(Version.ToString(), Prerelease) : Version.ToString();
1823+
string version = Utils.GetFullVersionString(Version.ToString(), Prerelease);
1824+
string NormalizedVersion = Utils.GetThreeDigitNormalizedVersionString(Version.ToString(), Prerelease);
18261825

18271826
var additionalMetadata = new PSObject();
18281827

@@ -1852,7 +1851,7 @@ private PSObject ConvertToCustomObject()
18521851

18531852
var psObject = new PSObject();
18541853
psObject.Properties.Add(new PSNoteProperty(nameof(Name), Name));
1855-
psObject.Properties.Add(new PSNoteProperty(nameof(Version), NormalizedVersion));
1854+
psObject.Properties.Add(new PSNoteProperty(nameof(Version), version));
18561855
psObject.Properties.Add(new PSNoteProperty(nameof(Type), Type));
18571856
psObject.Properties.Add(new PSNoteProperty(nameof(Description), Description));
18581857
psObject.Properties.Add(new PSNoteProperty(nameof(Author), Author));

src/code/SavePSResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ protected override void ProcessRecord()
216216
case InputObjectParameterSet:
217217
foreach (var inputObj in InputObject)
218218
{
219-
string normalizedVersionString = Utils.GetNormalizedVersionString(inputObj.Version.ToString(), inputObj.Prerelease);
219+
string normalizedVersionString = Utils.GetFullVersionString(inputObj.Version.ToString(), inputObj.Prerelease);
220220
ProcessSaveHelper(
221221
pkgNames: new string[] { inputObj.Name },
222222
pkgVersion: normalizedVersionString,

src/code/ServerApiCall.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
using System.Text;
1111
using System.Runtime.ExceptionServices;
1212
using System.Management.Automation;
13+
using System.Threading.Tasks;
14+
using System.Collections.Concurrent;
1315

1416
namespace Microsoft.PowerShell.PSResourceGet.Cmdlets
1517
{
@@ -81,6 +83,13 @@ public ServerApiCall(PSRepositoryInfo repository, NetworkCredential networkCrede
8183
/// </summary>
8284
public abstract FindResults FindName(string packageName, bool includePrerelease, ResourceType type, out ErrorRecord errRecord);
8385

86+
/// <summary>
87+
/// Find method which allows for async searching for package by single name and returns latest version.
88+
/// Name: no wildcard support
89+
/// Examples: Search "PowerShellGet"
90+
/// </summary>
91+
public abstract Task<FindResults> FindNameAsync(string packageName, bool includePrerelease, ResourceType type, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> warningMsgs, ConcurrentQueue<string> debugMsgs, ConcurrentQueue<string> verboseMsgs);
92+
8493
/// <summary>
8594
/// Find method which allows for searching for package by single name and tag and returns latest version.
8695
/// Name: no wildcard support
@@ -95,6 +104,15 @@ public ServerApiCall(PSRepositoryInfo repository, NetworkCredential networkCrede
95104
/// </summary>
96105
public abstract FindResults FindNameGlobbing(string packageName, bool includePrerelease, ResourceType type, out ErrorRecord errRecord);
97106

107+
/// <summary>
108+
/// Find method which allows for async searching for single name with version range.
109+
/// Name: no wildcard support
110+
/// Version: supports wildcards
111+
/// Examples: Search "PowerShellGet" "[3.0.0.0, 5.0.0.0]"
112+
/// Search "PowerShellGet" "3.*"
113+
/// </summary>
114+
public abstract Task<FindResults> FindVersionGlobbingAsync(string packageName, VersionRange versionRange, bool includePrerelease, ResourceType type, bool getOnlyLatest, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> warningMsgs, ConcurrentQueue<string> debugMsgs, ConcurrentQueue<string> verboseMsgs);
115+
98116
/// <summary>
99117
/// Find method which allows for searching for single name with wildcards and tag and returns latest version.
100118
/// Name: supports wildcards
@@ -118,6 +136,14 @@ public ServerApiCall(PSRepositoryInfo repository, NetworkCredential networkCrede
118136
/// </summary>
119137
public abstract FindResults FindVersion(string packageName, string version, ResourceType type, out ErrorRecord errRecord);
120138

139+
/// <summary>
140+
/// Find method which allows for async searching for single name with specific version.
141+
/// Name: no wildcard support
142+
/// Version: no wildcard support
143+
/// Examples: Search "PowerShellGet" "2.2.5"
144+
/// </summary>
145+
public abstract Task<FindResults> FindVersionAsync(string packageName, string version, ResourceType type, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> warningMsgs, ConcurrentQueue<string> debugMsgs, ConcurrentQueue<string> verboseMsgs);
146+
121147
/// <summary>
122148
/// Find method which allows for searching for single name with specific version.
123149
/// Name: no wildcard support
@@ -140,6 +166,19 @@ public ServerApiCall(PSRepositoryInfo repository, NetworkCredential networkCrede
140166
/// </summary>
141167
public abstract Stream InstallPackage(string packageName, string packageVersion, bool includePrerelease, out ErrorRecord errRecord);
142168

169+
/// <summary>
170+
/// Installs specific package asynchronously.
171+
/// Name: no wildcard support.
172+
/// Examples: Install "PowerShellGet"
173+
/// Install "PowerShellGet" -Version "3.0.0"
174+
/// Install "PowerShellGet" -Version "3.0.0-beta24"
175+
/// Implementation Note: if not prerelease: https://www.powershellgallery.com/api/v2/package/powershellget (Returns latest stable)
176+
/// if prerelease, the calling method should first call IFindPSResource.FindName(),
177+
/// then find the exact version to install, then call into install version
178+
/// </summary>
179+
public abstract Task<Stream> InstallPackageAsync(string packageName, string packageVersion, bool includePrerelease, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> warningMsgs, ConcurrentQueue<string> debugMsgs, ConcurrentQueue<string> verboseMsgs);
180+
181+
143182
#endregion
144183

145184
}

0 commit comments

Comments
 (0)