Skip to content

Commit 2683add

Browse files
committed
add error, warning, debug, and verbose queues to appropriate methods
1 parent 536aed5 commit 2683add

File tree

8 files changed

+132
-59
lines changed

8 files changed

+132
-59
lines changed

src/code/ContainerRegistryServerAPICalls.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ public ContainerRegistryServerAPICalls(PSRepositoryInfo repository, PSCmdlet cmd
8282

8383
#region Overridden Methods
8484

85-
public override Task<FindResults> FindVersionAsync(string packageName, string version, ResourceType type, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> debugMsgs)
85+
public override Task<FindResults> FindVersionAsync(string packageName, string version, ResourceType type, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> warningMsgs, ConcurrentQueue<string> debugMsgs, ConcurrentQueue<string> verboseMsgs)
8686
{
8787
throw new NotImplementedException("FindVersionAsync is not implemented for ContainerRegistryServerAPICalls.");
8888
}
8989

90-
public override Task<FindResults> FindVersionGlobbingAsync(string packageName, VersionRange versionRange, bool includePrerelease, ResourceType type, bool getOnlyLatest, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> debugMsgs)
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)
9191
{
9292
throw new NotImplementedException("FindVersionGlobbingAsync is not implemented for ContainerRegistryServerAPICalls.");
9393
}
@@ -158,7 +158,7 @@ public override FindResults FindName(string packageName, bool includePrerelease,
158158
}
159159

160160

161-
public override Task<FindResults> FindNameAsync(string packageName, bool includePrerelease, ResourceType type, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> debugMsgs)
161+
public override Task<FindResults> FindNameAsync(string packageName, bool includePrerelease, ResourceType type, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> warningMsgs, ConcurrentQueue<string> debugMsgs, ConcurrentQueue<string> verboseMsgs)
162162
{
163163
throw new NotImplementedException("FindNameAsync is not implemented for ContainerRegistryServerAPICalls.");
164164
}
@@ -319,6 +319,19 @@ public override Stream InstallPackage(string packageName, string packageVersion,
319319
return results;
320320
}
321321

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+
322335
/// <summary>
323336
/// Installs a package with version specified.
324337
/// Version can be prerelease or stable.

src/code/FindHelper.cs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,9 @@ private IEnumerable<PSResourceInfo> SearchByNames(ServerApiCall currentServer, R
709709
{
710710
ErrorRecord errRecord = null;
711711
ConcurrentQueue<ErrorRecord> errorMsgs = new ConcurrentQueue<ErrorRecord>();
712+
ConcurrentQueue<string> warningMsgs = new ConcurrentQueue<string>();
712713
ConcurrentQueue<string> debugMsgs = new ConcurrentQueue<string>();
714+
ConcurrentQueue<string> verboseMsgs = new ConcurrentQueue<string>();
713715
List<PSResourceInfo> parentPkgs = new List<PSResourceInfo>();
714716
string tagsAsString = String.Empty;
715717
bool isV2Resource = currentResponseUtil is V2ResponseUtil;
@@ -912,7 +914,7 @@ private IEnumerable<PSResourceInfo> SearchByNames(ServerApiCall currentServer, R
912914
Task<FindResults> response = null;
913915
if (currentServer.Repository.ApiVersion == PSRepositoryInfo.APIVersion.V2) {
914916
string key = $"{pkgName}|{_nugetVersion.ToNormalizedString()}|{_type}";
915-
response = cachedNetworkCalls.GetOrAdd(key, _ => currentServer.FindVersionAsync(pkgName, _nugetVersion.ToNormalizedString(), _type, errorMsgs, debugMsgs));
917+
response = cachedNetworkCalls.GetOrAdd(key, _ => currentServer.FindVersionAsync(pkgName, _nugetVersion.ToNormalizedString(), _type, errorMsgs, warningMsgs, debugMsgs, verboseMsgs));
916918

917919
responses = response.GetAwaiter().GetResult();
918920

@@ -997,7 +999,7 @@ private IEnumerable<PSResourceInfo> SearchByNames(ServerApiCall currentServer, R
997999
Task<FindResults> response = null;
9981000
if (currentServer.Repository.ApiVersion == PSRepositoryInfo.APIVersion.V2) {
9991001
string key = $"{pkgName}|{_versionRange.ToString()}|{_type}";
1000-
response = cachedNetworkCalls.GetOrAdd(key, _ => currentServer.FindVersionGlobbingAsync(pkgName, _versionRange, _prerelease, _type, getOnlyLatest: false, errorMsgs, debugMsgs));
1002+
response = cachedNetworkCalls.GetOrAdd(key, _ => currentServer.FindVersionGlobbingAsync(pkgName, _versionRange, _prerelease, _type, getOnlyLatest: false, errorMsgs, warningMsgs, debugMsgs, verboseMsgs));
10011003

10021004
responses = response.GetAwaiter().GetResult();
10031005
}
@@ -1192,7 +1194,7 @@ internal void FindDependencyPackagesHelper(ServerApiCall currentServer, Response
11921194
Parallel.ForEach(currentPkg.Dependencies, new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism }, dep =>
11931195
{
11941196
debugMsgs.Enqueue($"Finding dependency '{dep.Name}' version range '{dep.VersionRange}'");
1195-
FindDependencyPackageVersion(dep, currentServer, currentResponseUtil, currentPkg, repository, errorMsgs, verboseMsgs, warningMsgs);
1197+
FindDependencyPackageVersion(dep, currentServer, currentResponseUtil, currentPkg, repository, errorMsgs, warningMsgs, debugMsgs, verboseMsgs);
11961198
});
11971199
// TODO: what is perf if parallel.ForEach is always run?
11981200
}
@@ -1201,7 +1203,7 @@ internal void FindDependencyPackagesHelper(ServerApiCall currentServer, Response
12011203
foreach (var dep in currentPkg.Dependencies)
12021204
{
12031205
debugMsgs.Enqueue($"Finding dependency '{dep.Name}' version range '{dep.VersionRange}'");
1204-
FindDependencyPackageVersion(dep, currentServer, currentResponseUtil, currentPkg, repository, errorMsgs, verboseMsgs, warningMsgs);
1206+
FindDependencyPackageVersion(dep, currentServer, currentResponseUtil, currentPkg, repository, errorMsgs, warningMsgs, debugMsgs, verboseMsgs);
12051207
}
12061208
}
12071209

@@ -1237,8 +1239,9 @@ private void FindDependencyPackageVersion(
12371239
PSResourceInfo currentPkg,
12381240
PSRepositoryInfo repository,
12391241
ConcurrentQueue<ErrorRecord> errorMsgs,
1240-
ConcurrentQueue<string> verboseMsgs,
1241-
ConcurrentQueue<string> warningMsgs)
1242+
ConcurrentQueue<string> warningMsgs,
1243+
ConcurrentQueue<string> debugMsgs,
1244+
ConcurrentQueue<string> verboseMsgs)
12421245
{
12431246
PSResourceInfo depPkg = null;
12441247

@@ -1254,7 +1257,7 @@ private void FindDependencyPackageVersion(
12541257
else
12551258
{
12561259
// Find this version from the server
1257-
depPkg = FindDependencyWithLowerBound(dep, currentServer, currentResponseUtil, currentPkg, repository, errorMsgs, verboseMsgs);
1260+
depPkg = FindDependencyWithLowerBound(dep, currentServer, currentResponseUtil, currentPkg, repository, errorMsgs, warningMsgs, debugMsgs, verboseMsgs);
12581261
}
12591262
}
12601263
else if (dep.VersionRange.HasLowerBound && dep.VersionRange.MinVersion.Equals(dep.VersionRange.MaxVersion))
@@ -1271,7 +1274,7 @@ private void FindDependencyPackageVersion(
12711274
}
12721275
else
12731276
{
1274-
depPkg = FindDependencyWithSpecificVersion(dep, currentServer, currentResponseUtil, currentPkg, repository, errorMsgs, verboseMsgs, warningMsgs);
1277+
depPkg = FindDependencyWithSpecificVersion(dep, currentServer, currentResponseUtil, currentPkg, repository, errorMsgs, warningMsgs, debugMsgs, verboseMsgs);
12751278
}
12761279
}
12771280
else
@@ -1287,7 +1290,7 @@ private void FindDependencyPackageVersion(
12871290
}
12881291
else
12891292
{
1290-
depPkg = FindDependencyWithUpperBound(dep, currentServer, currentResponseUtil, currentPkg, repository, errorMsgs, verboseMsgs);
1293+
depPkg = FindDependencyWithUpperBound(dep, currentServer, currentResponseUtil, currentPkg, repository, errorMsgs, warningMsgs, debugMsgs, verboseMsgs);
12911294
}
12921295
}
12931296
}
@@ -1300,8 +1303,9 @@ private PSResourceInfo FindDependencyWithSpecificVersion(
13001303
PSResourceInfo currentPkg,
13011304
PSRepositoryInfo repository,
13021305
ConcurrentQueue<ErrorRecord> errorMsgs,
1303-
ConcurrentQueue<string> verboseMsgs,
1304-
ConcurrentQueue<string> warningMsgs)
1306+
ConcurrentQueue<string> warningMsgs,
1307+
ConcurrentQueue<string> debugMsgs,
1308+
ConcurrentQueue<string> verboseMsgs)
13051309
{
13061310
PSResourceInfo depPkg = null;
13071311
ErrorRecord errRecord = null;
@@ -1313,7 +1317,7 @@ private PSResourceInfo FindDependencyWithSpecificVersion(
13131317
// See if the network call we're making is already cached, if not, call FindNameAsync() and cache results
13141318
string key = $"{dep.Name}|{dep.VersionRange.MaxVersion.ToString()}|{_type}";
13151319
verboseMsgs.Enqueue("Checking if network call is cached.");
1316-
response = _cachedNetworkCalls.GetOrAdd(key, _ => currentServer.FindVersionAsync(dep.Name, dep.VersionRange.MaxVersion.ToString(), _type, errorMsgs, verboseMsgs));
1320+
response = _cachedNetworkCalls.GetOrAdd(key, _ => currentServer.FindVersionAsync(dep.Name, dep.VersionRange.MaxVersion.ToString(), _type, errorMsgs, warningMsgs, debugMsgs, verboseMsgs));
13171321

13181322
responses = response.GetAwaiter().GetResult();
13191323
}
@@ -1374,6 +1378,8 @@ private PSResourceInfo FindDependencyWithLowerBound(
13741378
PSResourceInfo currentPkg,
13751379
PSRepositoryInfo repository,
13761380
ConcurrentQueue<ErrorRecord> errorMsgs,
1381+
ConcurrentQueue<string> warningMsgs,
1382+
ConcurrentQueue<string> debugMsgs,
13771383
ConcurrentQueue<string> verboseMsgs)
13781384
{
13791385
PSResourceInfo depPkg = null;
@@ -1386,7 +1392,7 @@ private PSResourceInfo FindDependencyWithLowerBound(
13861392
// See if the network call we're making is already cached, if not, call FindNameAsync() and cache results
13871393
string key = $"{dep.Name}|*|{_type}";
13881394
verboseMsgs.Enqueue("Checking if network call is cached.");
1389-
response = _cachedNetworkCalls.GetOrAdd(key, _ => currentServer.FindNameAsync(dep.Name, includePrerelease: true, _type, errorMsgs, verboseMsgs));
1395+
response = _cachedNetworkCalls.GetOrAdd(key, _ => currentServer.FindNameAsync(dep.Name, includePrerelease: true, _type, errorMsgs, warningMsgs, debugMsgs, verboseMsgs));
13901396

13911397
responses = response.GetAwaiter().GetResult();
13921398
}
@@ -1446,6 +1452,8 @@ private PSResourceInfo FindDependencyWithUpperBound(
14461452
PSResourceInfo currentPkg,
14471453
PSRepositoryInfo repository,
14481454
ConcurrentQueue<ErrorRecord> errorMsgs,
1455+
ConcurrentQueue<string> warningMsgs,
1456+
ConcurrentQueue<string> debugMsgs,
14491457
ConcurrentQueue<string> verboseMsgs)
14501458
{
14511459
PSResourceInfo depPkg = null;
@@ -1460,7 +1468,7 @@ private PSResourceInfo FindDependencyWithUpperBound(
14601468
// See if the network call we're making is already caced, if not, call FindNameAsync() and cache results
14611469
string key = $"{dep.Name}|{dep.VersionRange.MaxVersion.ToString()}|{_type}";
14621470
verboseMsgs.Enqueue("Checking if network call is cached.");
1463-
response = cachedNetworkCalls.GetOrAdd(key, _ => currentServer.FindVersionGlobbingAsync(dep.Name, dep.VersionRange, includePrerelease: true, ResourceType.None, getOnlyLatest: true, errorMsgs, verboseMsgs));
1471+
response = cachedNetworkCalls.GetOrAdd(key, _ => currentServer.FindVersionGlobbingAsync(dep.Name, dep.VersionRange, includePrerelease: true, ResourceType.None, getOnlyLatest: true, errorMsgs, warningMsgs, debugMsgs, verboseMsgs));
14641472

14651473
responses = response.GetAwaiter().GetResult();
14661474

src/code/InstallHelper.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -878,26 +878,26 @@ private ConcurrentDictionary<string, Hashtable> InstallParentAndDependencyPackag
878878
verboseMsgs.Enqueue($"Installing package '{depPkgName}' version '{depPkgVersion}'");
879879
//Stream responseStream = currentServer.InstallPackage(depPkgName, depPkgVersion, true, out ErrorRecord installNameErrRecord);
880880
// add async
881-
Stream responseStream = currentServer.InstallPackageAsync(depPkgName, depPkgVersion, true, out ErrorRecord installNameErrRecord, errorMsgs, verboseMsgs);
881+
Stream responseStream = currentServer.InstallPackageAsync(depPkgName, depPkgVersion, true, errorMsgs, warningMsgs, debugMsgs, verboseMsgs).GetAwaiter().GetResult();
882882

883-
if (installNameErrRecord != null)
883+
if (errorMsgs.Count > 0)
884884
{
885-
verboseMsgs.Enqueue($"Error installing package '{depPkgName}': {installNameErrRecord.Exception?.Message}");
886-
errorMsgs.Enqueue(installNameErrRecord);
885+
verboseMsgs.Enqueue($"Error installing package '{depPkgName}'");
887886
}
887+
else {
888+
ErrorRecord tempSaveErrRecord = null, tempInstallErrRecord = null;
889+
bool installedToTempPathSuccessfully = _asNupkg ? TrySaveNupkgToTempPath(responseStream, tempInstallPath, depPkgName, depPkgVersion, depPkg, packagesHash, out updatedPackagesHash, out tempSaveErrRecord) :
890+
TryInstallToTempPath(responseStream, tempInstallPath, depPkgName, depPkgVersion, depPkg, packagesHash, out updatedPackagesHash, out warning, out tempInstallErrRecord);
888891

889-
ErrorRecord tempSaveErrRecord = null, tempInstallErrRecord = null;
890-
bool installedToTempPathSuccessfully = _asNupkg ? TrySaveNupkgToTempPath(responseStream, tempInstallPath, depPkgName, depPkgVersion, depPkg, packagesHash, out updatedPackagesHash, out tempSaveErrRecord) :
891-
TryInstallToTempPath(responseStream, tempInstallPath, depPkgName, depPkgVersion, depPkg, packagesHash, out updatedPackagesHash, out warning, out tempInstallErrRecord);
892-
893-
if (!installedToTempPathSuccessfully)
894-
{
895-
verboseMsgs.Enqueue($"Failed to install '{depPkgName}' to temp path");
896-
errorMsgs.Enqueue(tempSaveErrRecord ?? tempInstallErrRecord);
897-
}
898-
else
899-
{
900-
verboseMsgs.Enqueue($"Successfully installed '{depPkgName}' version '{depPkgVersion}' to temp path");
892+
if (!installedToTempPathSuccessfully)
893+
{
894+
verboseMsgs.Enqueue($"Failed to install '{depPkgName}' to temp path");
895+
errorMsgs.Enqueue(tempSaveErrRecord ?? tempInstallErrRecord);
896+
}
897+
else
898+
{
899+
verboseMsgs.Enqueue($"Successfully installed '{depPkgName}' version '{depPkgVersion}' to temp path");
900+
}
901901
}
902902
});
903903

src/code/LocalServerApiCalls.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ public LocalServerAPICalls (PSRepositoryInfo repository, PSCmdlet cmdletPassedIn
4141

4242
#region Overridden Methods
4343

44-
public override Task<FindResults> FindVersionAsync(string packageName, string version, ResourceType type, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> debugMsgs)
44+
public override Task<FindResults> FindVersionAsync(string packageName, string version, ResourceType type, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> warningMsgs, ConcurrentQueue<string> debugMsgs, ConcurrentQueue<string> verboseMsgs)
4545
{
4646
throw new NotImplementedException();
4747
}
4848

49-
public override Task<FindResults> FindVersionGlobbingAsync(string packageName, VersionRange versionRange, bool includePrerelease, ResourceType type, bool getOnlyLatest, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> debugMsgs)
49+
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)
5050
{
5151
throw new NotImplementedException();
5252
}
@@ -120,7 +120,7 @@ public override FindResults FindName(string packageName, bool includePrerelease,
120120
return FindNameHelper(packageName, Utils.EmptyStrArray, includePrerelease, type, out errRecord);
121121
}
122122

123-
public override Task<FindResults> FindNameAsync(string packageName, bool includePrerelease, ResourceType type, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> debugMsgs)
123+
public override Task<FindResults> FindNameAsync(string packageName, bool includePrerelease, ResourceType type, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> warningMsgs, ConcurrentQueue<string> debugMsgs, ConcurrentQueue<string> verboseMsgs)
124124
{
125125
throw new NotImplementedException();
126126
}
@@ -258,6 +258,19 @@ public override Stream InstallPackage(string packageName, string packageVersion,
258258
return results;
259259
}
260260

261+
/// <summary>
262+
/// Installs a specific package asynchronously.
263+
/// 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.
264+
/// Therefore, package version should not be null in this method.
265+
/// Name: no wildcard support.
266+
/// Examples: Install "PowerShellGet" -Version "3.5.0-alpha"
267+
/// Install "PowerShellGet" -Version "3.0.0"
268+
/// </summary>
269+
public override Task<Stream> InstallPackageAsync(string packageName, string packageVersion, bool includePrerelease, ConcurrentQueue<ErrorRecord> errorMsgs, ConcurrentQueue<string> warningMsgs, ConcurrentQueue<string> debugMsgs, ConcurrentQueue<string> verboseMsgs)
270+
{
271+
throw new NotImplementedException("InstallPackageAsync is not implemented for LocalServerAPICalls.");
272+
}
273+
261274
#endregion
262275

263276
#region Private Methods

0 commit comments

Comments
 (0)