diff --git a/.globalconfig b/.globalconfig index 0b395802754..96905c3fae4 100644 --- a/.globalconfig +++ b/.globalconfig @@ -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 diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs index 6bc54a4748b..7f40948a876 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs @@ -537,7 +537,7 @@ private List TestRestartStageUsingWsman(IEnumerable 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 mCollection = cimSession.QueryInstances( @@ -593,7 +593,7 @@ private List SetUpComputerInfoUsingWsman(IEnumerable 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 mCollection = cimSession.QueryInstances( @@ -663,7 +663,7 @@ private void WriteOutTimeoutError(IEnumerable computerNames) #region "Internal Methods" - internal static List TestWmiConnectionUsingWsman(List computerNames, List nextTestList, CancellationToken token, PSCredential credential, string wsmanAuthentication, PSCmdlet cmdlet) + internal static List TestWmiConnectionUsingWsman(List computerNames, List 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'"; @@ -679,7 +679,7 @@ internal static List TestWmiConnectionUsingWsman(List 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 mCollection = cimSession.QueryInstances( @@ -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); } } @@ -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 { @@ -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; diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs index 92e67f5681a..2eedaa93feb 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs @@ -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. diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/JsonObject.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/JsonObject.cs index 2b9bce8fd82..317189b79ef 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/JsonObject.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/JsonObject.cs @@ -68,7 +68,7 @@ public readonly struct ConvertToJsonContext /// Indicates whether to use enum names for the JSON conversion. /// Indicates whether to get the compressed output. 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) { } @@ -78,16 +78,16 @@ public ConvertToJsonContext(int maxDepth, bool enumsAsStrings, bool compressOutp /// The maximum depth to visit the object. /// Indicates whether to use enum names for the JSON conversion. /// Indicates whether to get the compressed output. - /// Specifies the cancellation token for cancelling the operation. /// Specifies how strings are escaped when writing JSON text. /// Specifies the cmdlet that is calling this method. + /// Specifies the cancellation token for cancelling the operation. public ConvertToJsonContext( int maxDepth, bool enumsAsStrings, bool compressOutput, - CancellationToken cancellationToken, StringEscapeHandling stringEscapeHandling, - PSCmdlet targetCmdlet) + PSCmdlet targetCmdlet, + CancellationToken cancellationToken) { this.MaxDepth = maxDepth; this.CancellationToken = cancellationToken; diff --git a/src/System.Management.Automation/engine/Modules/GetModuleCommand.cs b/src/System.Management.Automation/engine/Modules/GetModuleCommand.cs index bfecce83e4e..4651f0c79de 100644 --- a/src/System.Management.Automation/engine/Modules/GetModuleCommand.cs +++ b/src/System.Management.Automation/engine/Modules/GetModuleCommand.cs @@ -165,8 +165,8 @@ private IEnumerable 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; diff --git a/src/System.Management.Automation/engine/Modules/ImportModuleCommand.cs b/src/System.Management.Automation/engine/Modules/ImportModuleCommand.cs index f6641930bf7..6c360e3b8d5 100644 --- a/src/System.Management.Automation/engine/Modules/ImportModuleCommand.cs +++ b/src/System.Management.Automation/engine/Modules/ImportModuleCommand.cs @@ -957,9 +957,9 @@ private IList 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 result = new List(); @@ -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; diff --git a/src/System.Management.Automation/engine/Modules/RemoteDiscoveryHelper.cs b/src/System.Management.Automation/engine/Modules/RemoteDiscoveryHelper.cs index 015b2bb72d2..c925a842240 100644 --- a/src/System.Management.Automation/engine/Modules/RemoteDiscoveryHelper.cs +++ b/src/System.Management.Automation/engine/Modules/RemoteDiscoveryHelper.cs @@ -137,10 +137,10 @@ private static EventHandler GetStreamForwarder(Action private static IEnumerable InvokeTopLevelPowerShell( PowerShell powerShell, - CancellationToken cancellationToken, PSCmdlet cmdlet, PSInvocationSettings invocationSettings, - string errorMessageTemplate) + string errorMessageTemplate, + CancellationToken cancellationToken) { using (var mergedOutput = new BlockingCollection>>(s_blockingCollectionCapacity)) { @@ -256,10 +256,10 @@ private static IEnumerable InvokeTopLevelPowerShell( private static IEnumerable InvokeNestedPowerShell( PowerShell powerShell, - CancellationToken cancellationToken, PSCmdlet cmdlet, PSInvocationSettings invocationSettings, - string errorMessageTemplate) + string errorMessageTemplate, + CancellationToken cancellationToken) { EventHandler errorHandler = GetStreamForwarder( delegate (ErrorRecord errorRecord) @@ -467,9 +467,9 @@ private static void HandleErrorFromPipeline(Cmdlet cmdlet, ErrorRecord errorReco internal static IEnumerable InvokePowerShell( PowerShell powerShell, - CancellationToken cancellationToken, PSCmdlet cmdlet, - string errorMessageTemplate) + string errorMessageTemplate, + CancellationToken cancellationToken) { CopyParameterFromCmdletToPowerShell(cmdlet, powerShell, "ErrorAction"); CopyParameterFromCmdletToPowerShell(cmdlet, powerShell, "WarningAction"); @@ -481,8 +481,8 @@ internal static IEnumerable InvokePowerShell( // TODO/FIXME: ETW events for the output stream IEnumerable 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, @@ -980,8 +980,8 @@ internal static CimSession CreateCimSession( PSCredential credential, string authentication, bool isLocalHost, - CancellationToken cancellationToken, - PSCmdlet cmdlet) + PSCmdlet cmdlet, + CancellationToken cancellationToken) { if (isLocalHost) { diff --git a/test/xUnit/csharp/test_Utils.cs b/test/xUnit/csharp/test_Utils.cs index cda3d5741f4..b30c3ad18f8 100644 --- a/test/xUnit/csharp/test_Utils.cs +++ b/test/xUnit/csharp/test_Utils.cs @@ -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 {