Skip to content
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
2 changes: 1 addition & 1 deletion .globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ dotnet_diagnostic.CA1066.severity = none
dotnet_diagnostic.CA1067.severity = suggestion

# CA1068: CancellationToken parameters must come last
dotnet_diagnostic.CA1068.severity = suggestion
dotnet_diagnostic.CA1068.severity = warning

# CA1069: Enums values should not be duplicated
dotnet_diagnostic.CA1069.severity = suggestion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ private List<string> TestRestartStageUsingWsman(IEnumerable<string> computerName
{
if (token.IsCancellationRequested) { break; }

using (CimSession cimSession = RemoteDiscoveryHelper.CreateCimSession(computer, Credential, WsmanAuthentication, isLocalHost: false, token, this))
using (CimSession cimSession = RemoteDiscoveryHelper.CreateCimSession(computer, Credential, WsmanAuthentication, isLocalHost: false, this, token))
{
bool itemRetrieved = false;
IEnumerable<CimInstance> mCollection = cimSession.QueryInstances(
Expand Down Expand Up @@ -593,7 +593,7 @@ private List<string> SetUpComputerInfoUsingWsman(IEnumerable<string> computerNam
{
try
{
using (CimSession cimSession = RemoteDiscoveryHelper.CreateCimSession(computer, Credential, WsmanAuthentication, isLocalHost: false, token, this))
using (CimSession cimSession = RemoteDiscoveryHelper.CreateCimSession(computer, Credential, WsmanAuthentication, isLocalHost: false, this, token))
{
bool itemRetrieved = false;
IEnumerable<CimInstance> mCollection = cimSession.QueryInstances(
Expand Down Expand Up @@ -663,7 +663,7 @@ private void WriteOutTimeoutError(IEnumerable<string> computerNames)

#region "Internal Methods"

internal static List<string> TestWmiConnectionUsingWsman(List<string> computerNames, List<string> nextTestList, CancellationToken token, PSCredential credential, string wsmanAuthentication, PSCmdlet cmdlet)
internal static List<string> TestWmiConnectionUsingWsman(List<string> computerNames, List<string> nextTestList, PSCredential credential, string wsmanAuthentication, PSCmdlet cmdlet, CancellationToken token)
{
// Check if the WMI service "Winmgmt" is started
const string wmiServiceQuery = "Select * from " + ComputerWMIHelper.WMI_Class_Service + " Where name = 'Winmgmt'";
Expand All @@ -679,7 +679,7 @@ internal static List<string> TestWmiConnectionUsingWsman(List<string> computerNa
{
if (token.IsCancellationRequested) { break; }

using (CimSession cimSession = RemoteDiscoveryHelper.CreateCimSession(computer, credential, wsmanAuthentication, isLocalHost: false, token, cmdlet))
using (CimSession cimSession = RemoteDiscoveryHelper.CreateCimSession(computer, credential, wsmanAuthentication, isLocalHost: false, cmdlet, token))
{
bool itemRetrieved = false;
IEnumerable<CimInstance> mCollection = cimSession.QueryInstances(
Expand Down Expand Up @@ -964,7 +964,7 @@ protected override void ProcessRecord()
WriteProgress(_indicator[(indicatorIndex++) % 4] + _activity, _status, _percent, ProgressRecordType.Processing);
}

wmiTestList = TestWmiConnectionUsingWsman(wmiTestList, winrmTestList, _cancel.Token, Credential, WsmanAuthentication, this);
wmiTestList = TestWmiConnectionUsingWsman(wmiTestList, winrmTestList, Credential, WsmanAuthentication, this, _cancel.Token);
}
}

Expand Down Expand Up @@ -1435,7 +1435,7 @@ private void DoRenameComputerWsman(string computer, string computerName, string
try
{
using (CancellationTokenSource cancelTokenSource = new CancellationTokenSource())
using (CimSession cimSession = RemoteDiscoveryHelper.CreateCimSession(computer, credToUse, WsmanAuthentication, isLocalhost, cancelTokenSource.Token, this))
using (CimSession cimSession = RemoteDiscoveryHelper.CreateCimSession(computer, credToUse, WsmanAuthentication, isLocalhost, this, cancelTokenSource.Token))
{
var operationOptions = new CimOperationOptions
{
Expand Down Expand Up @@ -2110,7 +2110,7 @@ internal static bool InvokeWin32ShutdownUsingWsman(
return false;
}

using (CimSession cimSession = RemoteDiscoveryHelper.CreateCimSession(targetMachine, credInUse, authInUse, isLocalhost, cancelToken, cmdlet))
using (CimSession cimSession = RemoteDiscoveryHelper.CreateCimSession(targetMachine, credInUse, authInUse, isLocalhost, cmdlet, cancelToken))
{
var methodParameters = new CimMethodParametersCollection();
int retVal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ protected override void EndProcessing()
Depth,
EnumsAsStrings.IsPresent,
Compress.IsPresent,
_cancellationSource.Token,
EscapeHandling,
targetCmdlet: this);
targetCmdlet: this,
_cancellationSource.Token);

// null is returned only if the pipeline is stopping (e.g. ctrl+c is signaled).
// in that case, we shouldn't write the null to the output pipe.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public readonly struct ConvertToJsonContext
/// <param name="enumsAsStrings">Indicates whether to use enum names for the JSON conversion.</param>
/// <param name="compressOutput">Indicates whether to get the compressed output.</param>
public ConvertToJsonContext(int maxDepth, bool enumsAsStrings, bool compressOutput)
: this(maxDepth, enumsAsStrings, compressOutput, CancellationToken.None, StringEscapeHandling.Default, targetCmdlet: null)
: this(maxDepth, enumsAsStrings, compressOutput, StringEscapeHandling.Default, targetCmdlet: null, CancellationToken.None)
{
}

Expand All @@ -78,16 +78,16 @@ public ConvertToJsonContext(int maxDepth, bool enumsAsStrings, bool compressOutp
/// <param name="maxDepth">The maximum depth to visit the object.</param>
/// <param name="enumsAsStrings">Indicates whether to use enum names for the JSON conversion.</param>
/// <param name="compressOutput">Indicates whether to get the compressed output.</param>
/// <param name="cancellationToken">Specifies the cancellation token for cancelling the operation.</param>
/// <param name="stringEscapeHandling">Specifies how strings are escaped when writing JSON text.</param>
/// <param name="targetCmdlet">Specifies the cmdlet that is calling this method.</param>
/// <param name="cancellationToken">Specifies the cancellation token for cancelling the operation.</param>
public ConvertToJsonContext(
int maxDepth,
bool enumsAsStrings,
bool compressOutput,
CancellationToken cancellationToken,
StringEscapeHandling stringEscapeHandling,
PSCmdlet targetCmdlet)
PSCmdlet targetCmdlet,
CancellationToken cancellationToken)
{
this.MaxDepth = maxDepth;
this.CancellationToken = cancellationToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ private IEnumerable<PSModuleInfo> GetAvailableViaPsrpSessionCore(string[] module
"Get-Module");
foreach (
PSObject outputObject in
RemoteDiscoveryHelper.InvokePowerShell(powerShell, this.CancellationToken, this,
errorMessageTemplate))
RemoteDiscoveryHelper.InvokePowerShell(powerShell, this, errorMessageTemplate,
this.CancellationToken))
{
PSModuleInfo moduleInfo = RemoteDiscoveryHelper.RehydratePSModuleInfo(outputObject);
yield return moduleInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -957,9 +957,9 @@ private IList<PSModuleInfo> ImportModule_RemotelyViaPsrpSession(
string.Format(CultureInfo.InvariantCulture, "Import-Module -Name '{0}'", moduleName));
remotelyImportedModules = RemoteDiscoveryHelper.InvokePowerShell(
powerShell,
this.CancellationToken,
this,
errorMessageTemplate).ToList();
errorMessageTemplate,
this.CancellationToken).ToList();
}

List<PSModuleInfo> result = new List<PSModuleInfo>();
Expand Down Expand Up @@ -1076,7 +1076,7 @@ private PSModuleInfo ImportModule_RemotelyViaPsrpSession_SinglePreimportedModule
CultureInfo.InvariantCulture,
Modules.RemoteDiscoveryFailedToGenerateProxyForRemoteModule,
remoteModuleName);
int numberOfLocallyCreatedFiles = RemoteDiscoveryHelper.InvokePowerShell(powerShell, this.CancellationToken, this, errorMessageTemplate).Count();
int numberOfLocallyCreatedFiles = RemoteDiscoveryHelper.InvokePowerShell(powerShell, this, errorMessageTemplate, this.CancellationToken).Count();
if (numberOfLocallyCreatedFiles == 0)
{
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ private static EventHandler<DataAddedEventArgs> GetStreamForwarder<T>(Action<T>

private static IEnumerable<PSObject> InvokeTopLevelPowerShell(
PowerShell powerShell,
CancellationToken cancellationToken,
PSCmdlet cmdlet,
PSInvocationSettings invocationSettings,
string errorMessageTemplate)
string errorMessageTemplate,
CancellationToken cancellationToken)
{
using (var mergedOutput = new BlockingCollection<Func<PSCmdlet, IEnumerable<PSObject>>>(s_blockingCollectionCapacity))
{
Expand Down Expand Up @@ -256,10 +256,10 @@ private static IEnumerable<PSObject> InvokeTopLevelPowerShell(

private static IEnumerable<PSObject> InvokeNestedPowerShell(
PowerShell powerShell,
CancellationToken cancellationToken,
PSCmdlet cmdlet,
PSInvocationSettings invocationSettings,
string errorMessageTemplate)
string errorMessageTemplate,
CancellationToken cancellationToken)
{
EventHandler<DataAddedEventArgs> errorHandler = GetStreamForwarder<ErrorRecord>(
delegate (ErrorRecord errorRecord)
Expand Down Expand Up @@ -467,9 +467,9 @@ private static void HandleErrorFromPipeline(Cmdlet cmdlet, ErrorRecord errorReco

internal static IEnumerable<PSObject> InvokePowerShell(
PowerShell powerShell,
CancellationToken cancellationToken,
PSCmdlet cmdlet,
string errorMessageTemplate)
string errorMessageTemplate,
CancellationToken cancellationToken)
{
CopyParameterFromCmdletToPowerShell(cmdlet, powerShell, "ErrorAction");
CopyParameterFromCmdletToPowerShell(cmdlet, powerShell, "WarningAction");
Expand All @@ -481,8 +481,8 @@ internal static IEnumerable<PSObject> InvokePowerShell(

// TODO/FIXME: ETW events for the output stream
IEnumerable<PSObject> outputStream = powerShell.IsNested
? InvokeNestedPowerShell(powerShell, cancellationToken, cmdlet, invocationSettings, errorMessageTemplate)
: InvokeTopLevelPowerShell(powerShell, cancellationToken, cmdlet, invocationSettings, errorMessageTemplate);
? InvokeNestedPowerShell(powerShell, cmdlet, invocationSettings, errorMessageTemplate, cancellationToken)
: InvokeTopLevelPowerShell(powerShell, cmdlet, invocationSettings, errorMessageTemplate, cancellationToken);

return EnumerateWithCatch(
outputStream,
Expand Down Expand Up @@ -980,8 +980,8 @@ internal static CimSession CreateCimSession(
PSCredential credential,
string authentication,
bool isLocalHost,
CancellationToken cancellationToken,
PSCmdlet cmdlet)
PSCmdlet cmdlet,
CancellationToken cancellationToken)
{
if (isLocalHost)
{
Expand Down
4 changes: 2 additions & 2 deletions test/xUnit/csharp/test_Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ public static void TestConvertToJsonCancellation()
maxDepth: 1,
enumsAsStrings: true,
compressOutput: false,
source.Token,
Newtonsoft.Json.StringEscapeHandling.Default,
targetCmdlet: null);
targetCmdlet: null,
source.Token);

source.Cancel();
Hashtable hash = new Hashtable {
Expand Down