Skip to content

Create private cancellation token in InstallHelper #422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 27, 2021
Merged
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
7 changes: 5 additions & 2 deletions src/code/InstallHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ internal class InstallHelper : PSCmdlet
bool _asNupkg;
bool _includeXML;

public InstallHelper(bool updatePkg, bool savePkg, CancellationToken cancellationToken, PSCmdlet cmdletPassedIn)
public InstallHelper(bool updatePkg, bool savePkg, PSCmdlet cmdletPassedIn)
{
// Define the cancellation token.
CancellationTokenSource source = new CancellationTokenSource();
_cancellationToken = source.Token;

this._updatePkg = updatePkg;
this._savePkg = savePkg;
this._cancellationToken = cancellationToken;
this._cmdletPassedIn = cmdletPassedIn;
}

Expand Down
7 changes: 1 addition & 6 deletions src/code/InstallPSResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class InstallPSResource : PSCmdlet
/// <summary>
/// Specifies the scope of installation.
/// </summary>
[ValidateSet("CurrentUser", "AllUsers")]
[Parameter(ParameterSetName = NameParameterSet)]
public ScopeType Scope { get; set; }

Expand Down Expand Up @@ -125,11 +124,7 @@ protected override void BeginProcessing()

protected override void ProcessRecord()
{
// Define the cancellation token.
CancellationTokenSource source = new CancellationTokenSource();
CancellationToken cancellationToken = source.Token;

var installHelper = new InstallHelper(updatePkg: false, savePkg: false, cancellationToken: cancellationToken, cmdletPassedIn: this);
var installHelper = new InstallHelper(updatePkg: false, savePkg: false, cmdletPassedIn: this);

switch (ParameterSetName)
{
Expand Down
6 changes: 1 addition & 5 deletions src/code/SavePSResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,7 @@ protected override void BeginProcessing()

protected override void ProcessRecord()
{
// Define the cancellation token.
CancellationTokenSource source = new CancellationTokenSource();
CancellationToken cancellationToken = source.Token;

var installHelper = new InstallHelper(updatePkg: false, savePkg: true, cancellationToken: cancellationToken, cmdletPassedIn: this);
var installHelper = new InstallHelper(updatePkg: false, savePkg: true, cmdletPassedIn: this);

switch (ParameterSetName)
{
Expand Down