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 @@ -1184,7 +1184,7 @@ dotnet_diagnostic.SA1129.severity = none
dotnet_diagnostic.SA1130.severity = none

# SA1131: Use readable conditions
dotnet_diagnostic.SA1131.severity = none
dotnet_diagnostic.SA1131.severity = warning

# SA1132: Do not combine fields
dotnet_diagnostic.SA1132.severity = none
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,37 +325,37 @@ private enum JobOutputs

private static void DiscardJobOutputs(Job job, JobOutputs jobOutputsToDiscard)
{
if (JobOutputs.Output == (jobOutputsToDiscard & JobOutputs.Output))
if ((jobOutputsToDiscard & JobOutputs.Output) == JobOutputs.Output)
{
DiscardJobOutputs(job.Output);
}

if (JobOutputs.Error == (jobOutputsToDiscard & JobOutputs.Error))
if ((jobOutputsToDiscard & JobOutputs.Error) == JobOutputs.Error)
{
DiscardJobOutputs(job.Error);
}

if (JobOutputs.Warning == (jobOutputsToDiscard & JobOutputs.Warning))
if ((jobOutputsToDiscard & JobOutputs.Warning) == JobOutputs.Warning)
{
DiscardJobOutputs(job.Warning);
}

if (JobOutputs.Verbose == (jobOutputsToDiscard & JobOutputs.Verbose))
if ((jobOutputsToDiscard & JobOutputs.Verbose) == JobOutputs.Verbose)
{
DiscardJobOutputs(job.Verbose);
}

if (JobOutputs.Debug == (jobOutputsToDiscard & JobOutputs.Debug))
if ((jobOutputsToDiscard & JobOutputs.Debug) == JobOutputs.Debug)
{
DiscardJobOutputs(job.Debug);
}

if (JobOutputs.Progress == (jobOutputsToDiscard & JobOutputs.Progress))
if ((jobOutputsToDiscard & JobOutputs.Progress) == JobOutputs.Progress)
{
DiscardJobOutputs(job.Progress);
}

if (JobOutputs.Results == (jobOutputsToDiscard & JobOutputs.Results))
if ((jobOutputsToDiscard & JobOutputs.Results) == JobOutputs.Results)
{
DiscardJobOutputs(job.Results);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private void ProcessOutParameter(CimMethodResult methodResult, MethodParameter m
object valueReturnedFromMethod = (outParameter == null) ? null : outParameter.Value;

object dotNetValue = CimValueConverter.ConvertFromCimToDotNet(valueReturnedFromMethod, methodParameter.ParameterType);
if (MethodParameterBindings.Out == (methodParameter.Bindings & MethodParameterBindings.Out))
if ((methodParameter.Bindings & MethodParameterBindings.Out) == MethodParameterBindings.Out)
{
methodParameter.Value = dotNetValue;
cmdletOutput.Add(methodParameter.Name, methodParameter);
Expand All @@ -81,7 +81,7 @@ private void ProcessOutParameter(CimMethodResult methodResult, MethodParameter m
CimCmdletAdapter.AssociateSessionOfOriginWithInstance(cimInstance, this.JobContext.Session);
}
}
else if (MethodParameterBindings.Error == (methodParameter.Bindings & MethodParameterBindings.Error))
else if ((methodParameter.Bindings & MethodParameterBindings.Error) == MethodParameterBindings.Error)
{
var gotError = (bool)LanguagePrimitives.ConvertTo(dotNetValue, typeof(bool), CultureInfo.InvariantCulture);
if (gotError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ private PSObject AddProperties(ServiceController service)
lpDatabaseName: null,
dwDesiredAccess: NativeMethods.SC_MANAGER_CONNECT
);
if (IntPtr.Zero == hScManager)
if (hScManager == IntPtr.Zero)
{
lastError = Marshal.GetLastWin32Error();
Win32Exception exception = new Win32Exception(lastError);
Expand All @@ -683,7 +683,7 @@ private PSObject AddProperties(ServiceController service)
service.ServiceName,
NativeMethods.SERVICE_QUERY_CONFIG
);
if (IntPtr.Zero == hService)
if (hService == IntPtr.Zero)
{
lastError = Marshal.GetLastWin32Error();
Win32Exception exception = new Win32Exception(lastError);
Expand Down Expand Up @@ -737,7 +737,7 @@ private PSObject AddProperties(ServiceController service)
}
finally
{
if (IntPtr.Zero != hService)
if (hService != IntPtr.Zero)
{
bool succeeded = NativeMethods.CloseServiceHandle(hService);
if (!succeeded)
Expand All @@ -746,7 +746,7 @@ private PSObject AddProperties(ServiceController service)
}
}

if (IntPtr.Zero != hScManager)
if (hScManager != IntPtr.Zero)
{
bool succeeded = NativeMethods.CloseServiceHandle(hScManager);
if (!succeeded)
Expand Down Expand Up @@ -907,14 +907,14 @@ internal bool DoStartService(ServiceController serviceController)
}
catch (Win32Exception e)
{
if (NativeMethods.ERROR_SERVICE_ALREADY_RUNNING != e.NativeErrorCode)
if (e.NativeErrorCode != NativeMethods.ERROR_SERVICE_ALREADY_RUNNING)
exception = e;
}
catch (InvalidOperationException e)
{
Win32Exception eInner = e.InnerException as Win32Exception;
if (eInner == null
|| NativeMethods.ERROR_SERVICE_ALREADY_RUNNING != eInner.NativeErrorCode)
|| eInner.NativeErrorCode != NativeMethods.ERROR_SERVICE_ALREADY_RUNNING)
{
exception = e;
}
Expand Down Expand Up @@ -1024,15 +1024,15 @@ internal List<ServiceController> DoStopService(ServiceController serviceControll
}
catch (Win32Exception e)
{
if (NativeMethods.ERROR_SERVICE_NOT_ACTIVE != e.NativeErrorCode)
if (e.NativeErrorCode != NativeMethods.ERROR_SERVICE_NOT_ACTIVE)
exception = e;
}
catch (InvalidOperationException e)
{
Win32Exception eInner =
e.InnerException as Win32Exception;
if (eInner == null
|| NativeMethods.ERROR_SERVICE_NOT_ACTIVE != eInner.NativeErrorCode)
|| eInner.NativeErrorCode != NativeMethods.ERROR_SERVICE_NOT_ACTIVE)
{
exception = e;
}
Expand Down Expand Up @@ -1117,7 +1117,7 @@ internal bool DoPauseService(ServiceController serviceController)
}
catch (Win32Exception e)
{
if (NativeMethods.ERROR_SERVICE_NOT_ACTIVE == e.NativeErrorCode)
if (e.NativeErrorCode == NativeMethods.ERROR_SERVICE_NOT_ACTIVE)
{
serviceNotRunning = true;
}
Expand All @@ -1128,7 +1128,7 @@ internal bool DoPauseService(ServiceController serviceController)
{
Win32Exception eInner = e.InnerException as Win32Exception;
if (eInner != null
&& NativeMethods.ERROR_SERVICE_NOT_ACTIVE == eInner.NativeErrorCode)
&& eInner.NativeErrorCode == NativeMethods.ERROR_SERVICE_NOT_ACTIVE)
{
serviceNotRunning = true;
}
Expand Down Expand Up @@ -1198,7 +1198,7 @@ internal bool DoResumeService(ServiceController serviceController)
}
catch (Win32Exception e)
{
if (NativeMethods.ERROR_SERVICE_NOT_ACTIVE == e.NativeErrorCode)
if (e.NativeErrorCode == NativeMethods.ERROR_SERVICE_NOT_ACTIVE)
{
serviceNotRunning = true;
}
Expand All @@ -1209,7 +1209,7 @@ internal bool DoResumeService(ServiceController serviceController)
{
Win32Exception eInner = e.InnerException as Win32Exception;
if (eInner != null
&& NativeMethods.ERROR_SERVICE_NOT_ACTIVE == eInner.NativeErrorCode)
&& eInner.NativeErrorCode == NativeMethods.ERROR_SERVICE_NOT_ACTIVE)
{
serviceNotRunning = true;
}
Expand Down Expand Up @@ -1737,7 +1737,7 @@ protected override void ProcessRecord()
NativeMethods.SC_MANAGER_CONNECT
);

if (IntPtr.Zero == hScManager)
if (hScManager == IntPtr.Zero)
{
int lastError = Marshal.GetLastWin32Error();
Win32Exception exception = new Win32Exception(lastError);
Expand All @@ -1756,7 +1756,7 @@ protected override void ProcessRecord()
NativeMethods.SERVICE_CHANGE_CONFIG | NativeMethods.WRITE_DAC | NativeMethods.WRITE_OWNER
);

if (IntPtr.Zero == hService)
if (hService == IntPtr.Zero)
{
int lastError = Marshal.GetLastWin32Error();
Win32Exception exception = new Win32Exception(lastError);
Expand All @@ -1770,7 +1770,7 @@ protected override void ProcessRecord()
}
// Modify startup type or display name or credential
if (!string.IsNullOrEmpty(DisplayName)
|| ServiceStartupType.InvalidValue != StartupType || Credential != null)
|| StartupType != ServiceStartupType.InvalidValue || Credential != null)
{
DWORD dwStartType = NativeMethods.SERVICE_NO_CHANGE;
if (!NativeMethods.TryGetNativeStartupType(StartupType, out dwStartType))
Expand Down Expand Up @@ -1920,12 +1920,12 @@ protected override void ProcessRecord()
}
finally
{
if (IntPtr.Zero != delayedAutoStartInfoBuffer)
if (delayedAutoStartInfoBuffer != IntPtr.Zero)
{
Marshal.FreeCoTaskMem(delayedAutoStartInfoBuffer);
}

if (IntPtr.Zero != hService)
if (hService != IntPtr.Zero)
{
bool succeeded = NativeMethods.CloseServiceHandle(hService);
if (!succeeded)
Expand All @@ -1941,7 +1941,7 @@ protected override void ProcessRecord()
}
}

if (IntPtr.Zero != hScManager)
if (hScManager != IntPtr.Zero)
{
bool succeeded = NativeMethods.CloseServiceHandle(hScManager);
if (!succeeded)
Expand All @@ -1960,7 +1960,7 @@ protected override void ProcessRecord()
}
finally
{
if (IntPtr.Zero != password)
if (password != IntPtr.Zero)
{
Marshal.ZeroFreeCoTaskMemUnicode(password);
}
Expand Down Expand Up @@ -2133,7 +2133,7 @@ protected override void BeginProcessing()
null,
NativeMethods.SC_MANAGER_CONNECT | NativeMethods.SC_MANAGER_CREATE_SERVICE
);
if (IntPtr.Zero == hScManager)
if (hScManager == IntPtr.Zero)
{
int lastError = Marshal.GetLastWin32Error();
Win32Exception exception = new Win32Exception(lastError);
Expand Down Expand Up @@ -2210,7 +2210,7 @@ protected override void BeginProcessing()
username,
password
);
if (IntPtr.Zero == hService)
if (hService == IntPtr.Zero)
{
int lastError = Marshal.GetLastWin32Error();
Win32Exception exception = new Win32Exception(lastError);
Expand Down Expand Up @@ -2292,17 +2292,17 @@ protected override void BeginProcessing()
}
finally
{
if (IntPtr.Zero != delayedAutoStartInfoBuffer)
if (delayedAutoStartInfoBuffer != IntPtr.Zero)
{
Marshal.FreeCoTaskMem(delayedAutoStartInfoBuffer);
}

if (IntPtr.Zero != password)
if (password != IntPtr.Zero)
{
Marshal.ZeroFreeCoTaskMemUnicode(password);
}

if (IntPtr.Zero != hService)
if (hService != IntPtr.Zero)
{
bool succeeded = NativeMethods.CloseServiceHandle(hService);
if (!succeeded)
Expand All @@ -2320,7 +2320,7 @@ protected override void BeginProcessing()
}
}

if (IntPtr.Zero != hScManager)
if (hScManager != IntPtr.Zero)
{
bool succeeded = NativeMethods.CloseServiceHandle(hScManager);
if (!succeeded)
Expand Down Expand Up @@ -2432,7 +2432,7 @@ protected override void ProcessRecord()
lpDatabaseName: null,
dwDesiredAccess: NativeMethods.SC_MANAGER_ALL_ACCESS
);
if (IntPtr.Zero == hScManager)
if (hScManager == IntPtr.Zero)
{
int lastError = Marshal.GetLastWin32Error();
Win32Exception exception = new Win32Exception(lastError);
Expand All @@ -2451,7 +2451,7 @@ protected override void ProcessRecord()
Name,
NativeMethods.SERVICE_DELETE
);
if (IntPtr.Zero == hService)
if (hService == IntPtr.Zero)
{
int lastError = Marshal.GetLastWin32Error();
Win32Exception exception = new Win32Exception(lastError);
Expand Down Expand Up @@ -2480,7 +2480,7 @@ protected override void ProcessRecord()
}
finally
{
if (IntPtr.Zero != hService)
if (hService != IntPtr.Zero)
{
bool succeeded = NativeMethods.CloseServiceHandle(hService);
if (!succeeded)
Expand All @@ -2490,7 +2490,7 @@ protected override void ProcessRecord()
}
}

if (IntPtr.Zero != hScManager)
if (hScManager != IntPtr.Zero)
{
bool succeeded = NativeMethods.CloseServiceHandle(hScManager);
if (!succeeded)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected override void ProcessRecord()
foreach (string tzname in Name)
{
TimeZoneInfo[] timeZones = TimeZoneHelper.LookupSystemTimeZoneInfoByName(tzname);
if (0 < timeZones.Length)
if (timeZones.Length > 0)
{
// manually process each object in the array, so if there is only a single
// entry then the returned type is TimeZoneInfo and not TimeZoneInfo[], and
Expand Down Expand Up @@ -198,7 +198,7 @@ protected override void ProcessRecord()
ErrorCategory.InvalidArgument,
"Name"));
}
else if (1 < timeZones.Length)
else if (timeZones.Length > 1)
{
string message = string.Format(CultureInfo.InvariantCulture,
TimeZoneResources.MultipleMatchingTimeZones, Name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private void Process(OrderByPropertyEntry differenceEntry)
// Add differenceEntry to differenceEntryBacklog
if (differenceEntry != null)
{
if (0 < SyncWindow)
if (SyncWindow > 0)
{
while (_differenceEntryBacklog.Count >= SyncWindow)
{
Expand All @@ -234,7 +234,7 @@ private void Process(OrderByPropertyEntry differenceEntry)
// Add referenceEntry to referenceEntryBacklog
if (referenceEntry != null)
{
if (0 < SyncWindow)
if (SyncWindow > 0)
{
while (_referenceEntryBacklog.Count >= SyncWindow)
{
Expand Down Expand Up @@ -406,7 +406,7 @@ protected override void ProcessRecord()
return;
}

if (_comparer == null && 0 < DifferenceObject.Length)
if (_comparer == null && DifferenceObject.Length > 0)
{
InitComparer();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ internal virtual void PrepareSession()
WebSession.Proxy = webProxy;
}

if (-1 < MaximumRedirection)
if (MaximumRedirection > -1)
{
WebSession.MaximumRedirection = MaximumRedirection;
}
Expand Down Expand Up @@ -777,7 +777,7 @@ private string FormatDictionary(IDictionary content)
StringBuilder bodyBuilder = new StringBuilder();
foreach (string key in content.Keys)
{
if (0 < bodyBuilder.Length)
if (bodyBuilder.Length > 0)
{
bodyBuilder.Append('&');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private void SetResponse(HttpResponseMessage response, Stream contentStream)
}

long contentLength = response.Content.Headers.ContentLength.Value;
if (0 >= contentLength)
if (contentLength <= 0)
{
contentLength = StreamHelper.DefaultReadBuffer;
}
Expand Down
Loading