Skip to content
Closed
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 @@ -1151,7 +1151,7 @@ dotnet_diagnostic.SA1117.severity = none
dotnet_diagnostic.SA1118.severity = none

# SA1119: Statement should not use unnecessary parenthesis
dotnet_diagnostic.SA1119.severity = none
dotnet_diagnostic.SA1119.severity = warning

# SA1120: Comments should contain text
dotnet_diagnostic.SA1120.severity = none
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected void GetCimInstanceInternal(CimBaseCommand cmdlet)
GetComputerName(cmdlet));
string nameSpace;
List<CimSessionProxy> proxys = new List<CimSessionProxy>();
bool isGetCimInstanceCommand = (cmdlet is GetCimInstanceCommand);
bool isGetCimInstanceCommand = cmdlet is GetCimInstanceCommand;
CimInstance targetCimInstance = null;
switch (cmdlet.ParameterSetName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ internal IEnumerable<PSObject> QuerySession(IEnumerable<string> nameArray,
if (pattern.IsMatch(kvp.Key))
{
HashSet<CimSessionWrapper> wrappers = kvp.Value;
foundSession = (wrappers.Count > 0);
foundSession = wrappers.Count > 0;
foreach (CimSessionWrapper wrapper in wrappers)
{
if (!sessionIds.Contains(wrapper.SessionId))
Expand Down Expand Up @@ -686,7 +686,7 @@ internal IEnumerable<PSObject> QuerySessionByComputerName(
if (this.curCimSessionsByComputerName.ContainsKey(computername))
{
HashSet<CimSessionWrapper> wrappers = this.curCimSessionsByComputerName[computername];
foundSession = (wrappers.Count > 0);
foundSession = wrappers.Count > 0;
foreach (CimSessionWrapper wrapper in wrappers)
{
if (!sessionIds.Contains(wrapper.SessionId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public CimSessionProxy(CimSessionProxy proxy)
public CimSessionProxy(string computerName)
{
CreateSetSession(computerName, null, null, null, false);
this.isDefaultSession = (computerName == ConstValue.NullComputerName);
this.isDefaultSession = computerName == ConstValue.NullComputerName;
}

/// <summary>
Expand All @@ -351,7 +351,7 @@ public CimSessionProxy(string computerName)
public CimSessionProxy(string computerName, CimSessionOptions sessionOptions)
{
CreateSetSession(computerName, null, sessionOptions, null, false);
this.isDefaultSession = (computerName == ConstValue.NullComputerName);
this.isDefaultSession = computerName == ConstValue.NullComputerName;
}

/// <summary>
Expand Down Expand Up @@ -391,7 +391,7 @@ public CimSessionProxy(string computerName, CimInstance cimInstance)

string cimsessionComputerName = cimInstance.GetCimSessionComputerName();
CreateSetSession(cimsessionComputerName, null, null, null, false);
this.isDefaultSession = (cimsessionComputerName == ConstValue.NullComputerName);
this.isDefaultSession = cimsessionComputerName == ConstValue.NullComputerName;

DebugHelper.WriteLogEx("Create a temp session with computerName = {0}.", 0, cimsessionComputerName);
}
Expand All @@ -406,7 +406,7 @@ public CimSessionProxy(string computerName, CimInstance cimInstance)
public CimSessionProxy(string computerName, CimSessionOptions sessionOptions, CimOperationOptions operOptions)
{
CreateSetSession(computerName, null, sessionOptions, operOptions, false);
this.isDefaultSession = (computerName == ConstValue.NullComputerName);
this.isDefaultSession = computerName == ConstValue.NullComputerName;
}

/// <summary>
Expand All @@ -418,7 +418,7 @@ public CimSessionProxy(string computerName, CimSessionOptions sessionOptions, Ci
public CimSessionProxy(string computerName, CimOperationOptions operOptions)
{
CreateSetSession(computerName, null, null, operOptions, false);
this.isDefaultSession = (computerName == ConstValue.NullComputerName);
this.isDefaultSession = computerName == ConstValue.NullComputerName;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ protected override void EndProcessing()
/// </summary>
private CimGetCimClass GetOperationAgent()
{
return (this.AsyncOperation as CimGetCimClass);
return this.AsyncOperation as CimGetCimClass;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ protected override void EndProcessing()
/// </summary>
private CimGetInstance GetOperationAgent()
{
return (this.AsyncOperation as CimGetInstance);
return this.AsyncOperation as CimGetInstance;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ protected override void EndProcessing()
/// </summary>
private CimNewCimInstance GetOperationAgent()
{
return (this.AsyncOperation as CimNewCimInstance);
return this.AsyncOperation as CimNewCimInstance;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ internal void BuildSessionOptions(out CimSessionOptions outputOptions, out CimCr
outputCredential = null;
if (options != null)
{
DComSessionOptions dcomOptions = (options as DComSessionOptions);
DComSessionOptions dcomOptions = options as DComSessionOptions;
if (dcomOptions != null)
{
bool conflict = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ protected override void EndProcessing()
/// </summary>
private CimRemoveCimInstance GetOperationAgent()
{
return (this.AsyncOperation as CimRemoveCimInstance);
return this.AsyncOperation as CimRemoveCimInstance;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ protected override void EndProcessing()
/// </summary>
private CimSetCimInstance GetOperationAgent()
{
return (this.AsyncOperation as CimSetCimInstance);
return this.AsyncOperation as CimSetCimInstance;
}

/// <summary>
Expand Down
18 changes: 9 additions & 9 deletions src/Microsoft.PowerShell.Commands.Diagnostics/GetEventCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ private void ProcessListLog()
if (((!WildcardPattern.ContainsWildcardCharacters(logPattern))
&& string.Equals(logPattern, logName, StringComparison.OrdinalIgnoreCase))
||
(wildLogPattern.IsMatch(logName)))
wildLogPattern.IsMatch(logName))
{
try
{
Expand Down Expand Up @@ -684,7 +684,7 @@ private void ProcessListProvider()
if (((!WildcardPattern.ContainsWildcardCharacters(provPattern))
&& string.Equals(provPattern, provName, StringComparison.OrdinalIgnoreCase))
||
(wildProvPattern.IsMatch(provName)))
wildProvPattern.IsMatch(provName))
{
try
{
Expand Down Expand Up @@ -1631,9 +1631,9 @@ private string HandleNamedDataHashValue(string key, object value)
//
private void CheckHashTableForQueryPathPresence(Hashtable hash)
{
bool isLogHash = (hash.ContainsKey(hashkey_logname_lc));
bool isPathHash = (hash.ContainsKey(hashkey_path_lc));
bool isProviderHash = (hash.ContainsKey(hashkey_providername_lc));
bool isLogHash = hash.ContainsKey(hashkey_logname_lc);
bool isPathHash = hash.ContainsKey(hashkey_path_lc);
bool isProviderHash = hash.ContainsKey(hashkey_providername_lc);

if (!isLogHash && !isProviderHash && !isPathHash)
{
Expand Down Expand Up @@ -2068,9 +2068,9 @@ private void FindLogNamesMatchingWildcards(EventLogSession eventLogSession, IEnu
foreach (string actualLogName in eventLogSession.GetLogNames())
{
if (((!WildcardPattern.ContainsWildcardCharacters(logPattern))
&& (logPattern.Equals(actualLogName, StringComparison.OrdinalIgnoreCase)))
&& logPattern.Equals(actualLogName, StringComparison.OrdinalIgnoreCase))
||
(wildLogPattern.IsMatch(actualLogName)))
wildLogPattern.IsMatch(actualLogName))
{
//
// Skip direct ETW channels matching wildcards unless -force is present.
Expand Down Expand Up @@ -2137,9 +2137,9 @@ private void FindProvidersByLogForWildcardPatterns(EventLogSession eventLogSessi
foreach (string provName in eventLogSession.GetProviderNames())
{
if (((!WildcardPattern.ContainsWildcardCharacters(provPattern))
&& (provPattern.Equals(provName, StringComparison.OrdinalIgnoreCase)))
&& provPattern.Equals(provName, StringComparison.OrdinalIgnoreCase))
||
(wildProvPattern.IsMatch(provName)))
wildProvPattern.IsMatch(provName))
{
WriteVerbose(string.Format(CultureInfo.InvariantCulture, "Found matching provider: {0}", provName));
AddLogsForProviderToInternalMap(eventLogSession, provName);
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.PowerShell.Commands.Diagnostics/PdhHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ public uint EnumObjectItems(string machineName, string objectName, ref StringCol

Int32 cChars = pCounterBufferSize.ToInt32();
IntPtr strCountersList = (cChars > 0) ?
Marshal.AllocHGlobal((cChars) * sizeof(char)) : IntPtr.Zero;
Marshal.AllocHGlobal(cChars * sizeof(char)) : IntPtr.Zero;
// re-set count to 0 if it is lte 2
if (cChars < 0)
{
Expand All @@ -698,7 +698,7 @@ public uint EnumObjectItems(string machineName, string objectName, ref StringCol

cChars = pInstanceBufferSize.ToInt32();
IntPtr strInstancesList = (cChars > 0) ?
Marshal.AllocHGlobal((cChars) * sizeof(char)) : IntPtr.Zero;
Marshal.AllocHGlobal(cChars * sizeof(char)) : IntPtr.Zero;

// re-set count to 0 if it is lte 2
if (cChars < 0)
Expand Down Expand Up @@ -808,7 +808,7 @@ private bool IsPathValid(ref PDH_COUNTER_PATH_ELEMENTS pathElts, out string outP
{
outPath = Marshal.PtrToStringUni(strPath);

ret = (PdhValidatePathEx(_hDataSource, outPath) == PdhResults.PDH_CSTATUS_VALID_DATA);
ret = PdhValidatePathEx(_hDataSource, outPath) == PdhResults.PDH_CSTATUS_VALID_DATA;
}
}
finally
Expand All @@ -821,7 +821,7 @@ private bool IsPathValid(ref PDH_COUNTER_PATH_ELEMENTS pathElts, out string outP

public bool IsPathValid(string path)
{
return (PdhValidatePathEx(_hDataSource, path) == PdhResults.PDH_CSTATUS_VALID_DATA);
return PdhValidatePathEx(_hDataSource, path) == PdhResults.PDH_CSTATUS_VALID_DATA;
}

private uint MakePath(PDH_COUNTER_PATH_ELEMENTS pathElts, out string outPath, bool bWildcardInstances)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override bool IsInvalid

protected override bool ReleaseHandle()
{
return (PdhHelper.PdhCloseLog(handle, 0) == 0);
return PdhHelper.PdhCloseLog(handle, 0) == 0;
}
}

Expand All @@ -38,7 +38,7 @@ public override bool IsInvalid

protected override bool ReleaseHandle()
{
return (PdhHelper.PdhCloseQuery(handle) == 0);
return PdhHelper.PdhCloseQuery(handle) == 0;
}
}

Expand All @@ -56,7 +56,7 @@ public override bool IsInvalid

protected override bool ReleaseHandle()
{
return (PdhHelper.PdhCloseLog(handle, 0) == 0);
return PdhHelper.PdhCloseLog(handle, 0) == 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ internal IEnumerable<MethodParameter> GetMethodOutputParameters()
}

var outParameters = allParameters_plus_returnValue
.Where(p => ((p.Bindings & (MethodParameterBindings.Out | MethodParameterBindings.Error)) != 0));
.Where(p => (p.Bindings & (MethodParameterBindings.Out | MethodParameterBindings.Error)) != 0);

return outParameters;
}
Expand Down Expand Up @@ -156,7 +156,7 @@ internal bool ShouldProcess()

internal bool IsPassThruObjectNeeded()
{
return (_passThru) && (!this.DidUserSuppressTheOperation) && (!this.JobHadErrors);
return _passThru && (!this.DidUserSuppressTheOperation) && (!this.JobHadErrors);
}

public override void OnCompleted()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private static bool IsWsManQuotaReached(Exception exception)
return false;
}

WsManErrorCode wsManErrorCode = (WsManErrorCode)(UInt32)(errorCodeProperty.Value);
WsManErrorCode wsManErrorCode = (WsManErrorCode)(UInt32)errorCodeProperty.Value;
switch (wsManErrorCode) // error codes that should result in sleep-and-retry are based on an email from Ryan
{
case WsManErrorCode.ERROR_WSMAN_QUOTA_MAX_SHELLS:
Expand Down Expand Up @@ -266,7 +266,7 @@ public override bool HasMoreData
{
get
{
return (Results.IsOpen || Results.Count > 0);
return Results.IsOpen || Results.Count > 0;
}
}

Expand Down Expand Up @@ -630,7 +630,7 @@ internal void ReportJobFailure(IContainsErrorRecord exception)
else
{
CimJobException cje = exception as CimJobException;
if ((cje != null) && (cje.IsTerminatingError))
if ((cje != null) && cje.IsTerminatingError)
{
terminatingErrorTracker.MarkSessionAsTerminated(this.JobContext.Session, out sessionWasAlreadyTerminated);
isThisTerminatingError = true;
Expand Down Expand Up @@ -934,7 +934,7 @@ internal CimResponseType ShouldProcess(

Dbg.Assert(
(this.JobContext.ShouldProcessOptimization != MshCommandRuntime.ShouldProcessPossibleOptimization.AutoYes_CanSkipShouldProcessCall) ||
(this.JobContext.CmdletInvocationContext.CmdletDefinitionContext.ClientSideShouldProcess),
this.JobContext.CmdletInvocationContext.CmdletDefinitionContext.ClientSideShouldProcess,
"MI layer should not call us when AutoYes_CanSkipShouldProcessCall optimization is in effect");
Exception exceptionThrownOnCmdletThread;
ShouldProcessReason shouldProcessReason;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ internal object ConvertFromDotNetToCim(object dotNetObject)
Type dotNetType = psObject.BaseObject.GetType();
if (typeof(PSCredential).IsAssignableFrom(dotNetType))
{
var credential = (PSCredential)(psObject.BaseObject);
var credential = (PSCredential)psObject.BaseObject;

string escapedUsername = credential.UserName;
escapedUsername = escapedUsername.Replace("\\", "\\\\"); // Esc backslashes
Expand Down Expand Up @@ -304,14 +304,14 @@ internal static object ConvertFromDotNetToCim(object dotNetObject)

if (typeof(X509Certificate2).IsAssignableFrom(dotNetType))
{
var cert = (X509Certificate2)(psObject.BaseObject);
var cert = (X509Certificate2)psObject.BaseObject;
byte[] cimIntrinsicValue = cert.RawData;
return cimIntrinsicValue;
}

if (typeof(X500DistinguishedName).IsAssignableFrom(dotNetType))
{
var x500name = (X500DistinguishedName)(psObject.BaseObject);
var x500name = (X500DistinguishedName)psObject.BaseObject;
byte[] cimIntrinsicValue = x500name.RawData;
return cimIntrinsicValue;
}
Expand All @@ -330,13 +330,13 @@ internal static object ConvertFromDotNetToCim(object dotNetObject)

if (typeof(WildcardPattern).IsAssignableFrom(dotNetType))
{
var wildcardPattern = (WildcardPattern)(psObject.BaseObject);
var wildcardPattern = (WildcardPattern)psObject.BaseObject;
return wildcardPattern.ToWql();
}

if (typeof(XmlDocument).IsAssignableFrom(dotNetType))
{
var xmlDocument = (XmlDocument)(psObject.BaseObject);
var xmlDocument = (XmlDocument)psObject.BaseObject;
string cimIntrinsicValue = xmlDocument.OuterXml;
return cimIntrinsicValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ private bool IsSupportedSession(CimSession cimSession, TerminatingErrorTracker t
PSPropertyInfo protocolProperty = PSObject.AsPSObject(cimSession).Properties["Protocol"];
if ((protocolProperty != null) &&
(protocolProperty.Value != null) &&
(protocolProperty.Value.ToString().Equals("DCOM", StringComparison.OrdinalIgnoreCase)))
protocolProperty.Value.ToString().Equals("DCOM", StringComparison.OrdinalIgnoreCase))
{
bool sessionWasAlreadyTerminated;
terminatingErrorTracker.MarkSessionAsTerminated(cimSession, out sessionWasAlreadyTerminated);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public NotFoundError(string propertyName, object propertyValue, bool wildcardsEn
if (wildcardsEnabled)
{
var propertyValueAsString = propertyValue as string;
if ((propertyValueAsString != null) && (WildcardPattern.ContainsWildcardCharacters(propertyValueAsString)))
if ((propertyValueAsString != null) && WildcardPattern.ContainsWildcardCharacters(propertyValueAsString))
{
this.ErrorMessageGenerator =
(queryDescription, className) => GetErrorMessageForNotFound_ForWildcard(this.PropertyName, this.PropertyValue, className);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private void EmptyRecycleBin(string drivePath)
drivePath);
}

if (_force || (ShouldProcess(clearRecycleBinShouldProcessTarget, "Clear-RecycleBin")))
if (_force || ShouldProcess(clearRecycleBinShouldProcessTarget, "Clear-RecycleBin"))
{
// If driveName is null, then clear the recyclebin for all drives; otherwise, just for the specified driveName.

Expand Down
Loading