Enable CA1068: CancellationToken parameters must come last (#13867)

* Enable CA1068: CancellationToken parameters must come last
This commit is contained in:
xtqqczze 2020-11-05 04:08:28 +00:00 committed by GitHub
parent 91e49d42d4
commit 47c92090db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 31 additions and 31 deletions

View file

@ -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

View file

@ -537,7 +537,7 @@ $result
{
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(
@ -593,7 +593,7 @@ $result
{
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(
@ -663,7 +663,7 @@ $result
#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'";
@ -679,7 +679,7 @@ $result
{
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(
@ -964,7 +964,7 @@ $result
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 @@ $result
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 @@ $result
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;

View file

@ -116,9 +116,9 @@ namespace Microsoft.PowerShell.Commands
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.

View file

@ -68,7 +68,7 @@ namespace Microsoft.PowerShell.Commands
/// <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)
{
}
@ -78,16 +78,16 @@ namespace Microsoft.PowerShell.Commands
/// <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;

View file

@ -165,8 +165,8 @@ namespace Microsoft.PowerShell.Commands
"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;

View file

@ -957,9 +957,9 @@ namespace Microsoft.PowerShell.Commands
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>();
@ -1076,7 +1076,7 @@ namespace Microsoft.PowerShell.Commands
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;

View file

@ -137,10 +137,10 @@ namespace System.Management.Automation
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))
{
@ -256,10 +256,10 @@ namespace System.Management.Automation
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)
@ -467,9 +467,9 @@ namespace System.Management.Automation
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");
@ -481,8 +481,8 @@ namespace System.Management.Automation
// 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,
@ -980,8 +980,8 @@ namespace System.Management.Automation
PSCredential credential,
string authentication,
bool isLocalHost,
CancellationToken cancellationToken,
PSCmdlet cmdlet)
PSCmdlet cmdlet,
CancellationToken cancellationToken)
{
if (isLocalHost)
{

View file

@ -134,9 +134,9 @@ namespace PSTests.Parallel
maxDepth: 1,
enumsAsStrings: true,
compressOutput: false,
source.Token,
Newtonsoft.Json.StringEscapeHandling.Default,
targetCmdlet: null);
targetCmdlet: null,
source.Token);
source.Cancel();
Hashtable hash = new Hashtable {