Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/code/ContainerRegistryServerAPICalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ public ContainerRegistryServerAPICalls(PSRepositoryInfo repository, PSCmdlet cmd

#region Overridden Methods

public override Task<FindResults> FindVersionAsync(string packageName, string version, ResourceType type)
{
return null;
}

public override Task<FindResults> FindVersionGlobbingAsync(string packageName, VersionRange versionRange, bool includePrerelease, ResourceType type, bool getOnlyLatest)
{
return null;
}

/// <summary>
/// Find method which allows for searching for all packages from a repository and returns latest version for each.
/// </summary>
Expand Down Expand Up @@ -146,6 +156,12 @@ public override FindResults FindName(string packageName, bool includePrerelease,
return new FindResults(stringResponse: new string[] { }, hashtableResponse: pkgResult.ToArray(), responseType: containerRegistryFindResponseType);
}


public override Task<FindResults> FindNameAsync(string packageName, bool includePrerelease, ResourceType type)
{
return null;
}

/// <summary>
/// Find method which allows for searching for single name and tag and returns latest version.
/// Name: no wildcard support
Expand Down
537 changes: 380 additions & 157 deletions src/code/FindHelper.cs

Large diffs are not rendered by default.

255 changes: 148 additions & 107 deletions src/code/InstallHelper.cs

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions src/code/LocalServerApiCalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Net;
using System.Management.Automation;
using System.Runtime.ExceptionServices;
using System.Threading.Tasks;

namespace Microsoft.PowerShell.PSResourceGet.Cmdlets
{
Expand All @@ -39,6 +40,15 @@ public LocalServerAPICalls (PSRepositoryInfo repository, PSCmdlet cmdletPassedIn

#region Overridden Methods

public override Task<FindResults> FindVersionAsync(string packageName, string version, ResourceType type)
{
return null;
}

public override Task<FindResults> FindVersionGlobbingAsync(string packageName, VersionRange versionRange, bool includePrerelease, ResourceType type, bool getOnlyLatest)
{
return null;
}
/// <summary>
/// Find method which allows for searching for all packages from a repository and returns latest version for each.
/// Examples: Search -Repository PSGallery
Expand Down Expand Up @@ -109,6 +119,11 @@ public override FindResults FindName(string packageName, bool includePrerelease,
return FindNameHelper(packageName, Utils.EmptyStrArray, includePrerelease, type, out errRecord);
}

public override Task<FindResults> FindNameAsync(string packageName, bool includePrerelease, ResourceType type)
{
return null;
}

/// <summary>
/// Find method which allows for searching for single name and tag and returns latest version.
/// Name: no wildcard support
Expand Down
14 changes: 14 additions & 0 deletions src/code/NuGetServerAPICalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ public NuGetServerAPICalls (PSRepositoryInfo repository, PSCmdlet cmdletPassedIn

#region Overridden Methods

public override Task<FindResults> FindVersionAsync(string packageName, string version, ResourceType type)
{
return null;
}

public override Task<FindResults> FindVersionGlobbingAsync(string packageName, VersionRange versionRange, bool includePrerelease, ResourceType type, bool getOnlyLatest)
{
return null;
}
/// <summary>
/// Find method which allows for searching for all packages from a repository and returns latest version for each.
/// Examples: Search -Repository MyNuGetServer
Expand Down Expand Up @@ -183,6 +192,11 @@ public override FindResults FindName(string packageName, bool includePrerelease,
return new FindResults(stringResponse: new string[]{ response }, hashtableResponse: emptyHashResponses, responseType: FindResponseType);
}

public override Task<FindResults> FindNameAsync(string packageName, bool includePrerelease, ResourceType type)
{
return null;
}

/// <summary>
/// Find method which allows for searching for single name and tag and returns latest version.
/// Name: no wildcard support
Expand Down
26 changes: 26 additions & 0 deletions src/code/ServerApiCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Text;
using System.Runtime.ExceptionServices;
using System.Management.Automation;
using System.Threading.Tasks;

namespace Microsoft.PowerShell.PSResourceGet.Cmdlets
{
Expand Down Expand Up @@ -81,6 +82,13 @@ public ServerApiCall(PSRepositoryInfo repository, NetworkCredential networkCrede
/// </summary>
public abstract FindResults FindName(string packageName, bool includePrerelease, ResourceType type, out ErrorRecord errRecord);

/// <summary>
/// Find method which allows for searching for package by single name and returns latest version.
/// Name: no wildcard support
/// Examples: Search "PowerShellGet"
/// </summary>
public abstract Task<FindResults> FindNameAsync(string packageName, bool includePrerelease, ResourceType type);

/// <summary>
/// Find method which allows for searching for package by single name and tag and returns latest version.
/// Name: no wildcard support
Expand Down Expand Up @@ -118,6 +126,24 @@ public ServerApiCall(PSRepositoryInfo repository, NetworkCredential networkCrede
/// </summary>
public abstract FindResults FindVersion(string packageName, string version, ResourceType type, out ErrorRecord errRecord);

/// <summary>
/// Find method which allows for searching for single name with specific version.
/// Name: no wildcard support
/// Version: no wildcard support
/// Examples: Search "PowerShellGet" "2.2.5"
/// </summary>
public abstract Task<FindResults> FindVersionAsync(string packageName, string version, ResourceType type);


/// <summary>
/// Find method which allows for searching for single name with specific version.
/// Name: no wildcard support
/// Version: no wildcard support
/// Examples: Search "PowerShellGet" "2.2.5"
/// </summary>

public abstract Task<FindResults> FindVersionGlobbingAsync(string packageName, VersionRange versionRange, bool includePrerelease, ResourceType type, bool getOnlyLatest);

/// <summary>
/// Find method which allows for searching for single name with specific version.
/// Name: no wildcard support
Expand Down
86 changes: 67 additions & 19 deletions src/code/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1342,37 +1342,85 @@ private static bool TryReadPSDataFile(
out Hashtable dataFileInfo,
out Exception error)
{
dataFileInfo = null;
error = null;
try
{
if (filePath is null)
{
throw new PSArgumentNullException(nameof(filePath));
}

string contents = System.IO.File.ReadAllText(filePath);
var scriptBlock = System.Management.Automation.ScriptBlock.Create(contents);

// Ensure that the content script block is safe to convert into a PSDataFile Hashtable.
// This will throw for unsafe content.
scriptBlock.CheckRestrictedLanguage(
allowedCommands: allowedCommands,
allowedVariables: allowedVariables,
allowEnvironmentVariables: allowEnvironmentVariables);

// Convert contents into PSDataFile Hashtable by executing content as script.
object result = scriptBlock.InvokeReturnAsIs();
if (result is PSObject psObject)

// Parallel.ForEach calls into this method.
// Each thread needs its own runspace created to provide a separate environment for operations to run independently.
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
runspace.SessionStateProxy.LanguageMode = PSLanguageMode.ConstrainedLanguage;

// Set the created runspace as the default for the current thread
Runspace.DefaultRunspace = runspace;

using (System.Management.Automation.PowerShell pwsh = System.Management.Automation.PowerShell.Create())
{
result = psObject.BaseObject;
}
pwsh.Runspace = runspace;

dataFileInfo = (Hashtable)result;
error = null;
return true;
var cmd = new Command(
command: contents,
isScript: true,
useLocalScope: true);
cmd.MergeMyResults(
myResult: PipelineResultTypes.Error | PipelineResultTypes.Warning | PipelineResultTypes.Verbose | PipelineResultTypes.Debug | PipelineResultTypes.Information,
toResult: PipelineResultTypes.Output);
pwsh.Commands.AddCommand(cmd);


try
{
// Invoke the pipeline and retrieve the results
var results = pwsh.Invoke();

if (results[0] is PSObject pwshObj)
{
switch (pwshObj.BaseObject)
{
case ErrorRecord err:
//_cmdletPassedIn.WriteError(error);
break;

case WarningRecord warning:
//cmdlet.WriteWarning(warning.Message);
break;

case VerboseRecord verbose:
//cmdlet.WriteVerbose(verbose.Message);
break;

case DebugRecord debug:
//cmdlet.WriteDebug(debug.Message);
break;

case InformationRecord info:
//cmdlet.WriteInformation(info);
break;

case Hashtable result:
dataFileInfo = result;
return true;
}
}
}
catch (Exception ex)
{
error = ex;
}
}
runspace.Close();

return false;
}
catch (Exception ex)
{
dataFileInfo = null;
error = ex;
return false;
}
Expand Down
Loading