Skip to content

Commit

Permalink
Enforce Roslynator checks in CI build (#1608)
Browse files Browse the repository at this point in the history
- The ci pass includes Roslynator checks, fails on warnings
- Fix all existing warnings
  • Loading branch information
mregen committed Nov 24, 2021
1 parent fdf31dc commit 2430a65
Show file tree
Hide file tree
Showing 23 changed files with 470 additions and 465 deletions.
16 changes: 2 additions & 14 deletions .azurepipelines/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,12 @@ jobs:
inputs:
targetType: filePath
filePath: ./.azurepipelines/set-version.ps1
- task: DotNetCoreCLI@2
displayName: Release Restore
inputs:
command: restore
projects: '**/@(Console|NetCore)*.csproj'
arguments: '--framework ${{ parameters.framework }} --configuration Release ${{ parameters.buildoption }}'
- task: DotNetCoreCLI@2
displayName: Release Build
inputs:
command: build
projects: '**/@(Console|NetCore)*.csproj'
arguments: '--framework ${{ parameters.framework }} --no-restore --configuration Release ${{ parameters.buildoption }}'
arguments: '--framework ${{ parameters.framework }} --configuration Release ${{ parameters.buildoption }} /p:RCS=true'
- task: DotNetCoreCLI@2
displayName: Release Pack
condition: eq(variables['poolImage'], 'windows-2022')
Expand All @@ -58,18 +52,12 @@ jobs:
packagesToPack: '**/Opc.Ua.*.csproj'
configuration: Release
configurationToPack: Release
- task: DotNetCoreCLI@2
displayName: Debug Restore
inputs:
command: restore
projects: '**/@(Console|NetCore)*.csproj'
arguments: '--framework ${{ parameters.framework }} --configuration Debug ${{ parameters.buildoption }}'
- task: DotNetCoreCLI@2
displayName: Debug Build
inputs:
command: build
projects: '**/@(Console|NetCore)*.csproj'
arguments: '--framework ${{ parameters.framework }} --no-restore --configuration Debug ${{ parameters.buildoption }}'
arguments: '--framework ${{ parameters.framework }} --configuration Debug ${{ parameters.buildoption }} /p:RCS=true'
- task: DotNetCoreCLI@2
displayName: Debug Pack
condition: eq(variables['poolImage'], 'windows-2022')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private void StorePathCB_DropDown(object sender, EventArgs e)

foreach (string item in StorePathCB.Items)
{
if (String.Compare(storePath, item, StringComparison.OrdinalIgnoreCase) == 0)
if (String.Equals(storePath, item, StringComparison.OrdinalIgnoreCase))
{
found = true;
break;
Expand Down Expand Up @@ -265,7 +265,7 @@ private void BrowseStoreBTN_Click(object sender, EventArgs e)

for (int ii = 0; ii < StorePathCB.Items.Count; ii++)
{
if (String.Compare(storePath, StorePathCB.Items[ii] as string, StringComparison.OrdinalIgnoreCase) == 0)
if (String.Equals(storePath, StorePathCB.Items[ii] as string, StringComparison.OrdinalIgnoreCase))
{
StorePathCB.SelectedIndex = ii;
found = true;
Expand Down
2 changes: 1 addition & 1 deletion Applications/ReferenceServer/SerilogTraceLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class SerilogTraceLogger
{
loggerConfiguration.WriteTo.File(
Utils.ReplaceSpecialFolderNames(config.TraceConfiguration.OutputFilePath),
rollingInterval: RollingInterval.Day,
rollingInterval: RollingInterval.Infinite,
rollOnFileSizeLimit: true,
restrictedToMinimumLevel: fileMinimumLevel,
retainedFileCountLimit: 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace Opc.Ua.PubSub.Configuration
/// <summary>
/// Helper class that calculates the ConfigurationVersion for MetaData
/// </summary>
public class ConfigurationVersionUtils
public static class ConfigurationVersionUtils
{
// The epoch date is midnight UTC (00:00) on January 1, 2000.
private static readonly DateTime kEpochDate = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc);
Expand Down
6 changes: 3 additions & 3 deletions Libraries/Opc.Ua.PubSub/Transport/MqttClientCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

namespace Opc.Ua.PubSub.Transport
{
internal class MqttClientCreator
internal static class MqttClientCreator
{
#region Private
private static readonly Lazy<MqttFactory> mqttClientFactory = new Lazy<MqttFactory>(() => new MqttFactory());
Expand Down Expand Up @@ -108,15 +108,15 @@ internal class MqttClientCreator
mqttClient?.Options?.ClientId,
e.Reason,
e.ClientWasConnected);
await Connect(reconnectInterval, mqttClientOptions, mqttClient);
await Connect(reconnectInterval, mqttClientOptions, mqttClient).ConfigureAwait(false);
}
catch (Exception excOnDisconnect)
{
Utils.Trace("{0} Failed to reconnect after disconnect occurred: {1}", mqttClient?.Options?.ClientId, excOnDisconnect.Message);
}
});

await Connect(reconnectInterval, mqttClientOptions, mqttClient);
await Connect(reconnectInterval, mqttClientOptions, mqttClient).ConfigureAwait(false);

return mqttClient;
}
Expand Down
12 changes: 4 additions & 8 deletions Libraries/Opc.Ua.PubSub/Transport/UdpClientCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace Opc.Ua.PubSub.Transport
/// <summary>
/// Specialized in creating the necessary <see cref="UdpClient"/> instances from an URL
/// </summary>
internal class UdpClientCreator
internal static class UdpClientCreator
{
public const int SIO_UDP_CONNRESET = -1744830452;

Expand All @@ -65,7 +65,7 @@ internal static IPEndPoint GetEndPoint(string url)
return null;
}
string hostName = connectionUri.Host;
if (hostName.ToLower() == "localhost")
if (string.Equals(hostName, "localhost", StringComparison.OrdinalIgnoreCase))
{
hostName = "127.0.0.1";
}
Expand Down Expand Up @@ -107,7 +107,7 @@ internal static IPEndPoint GetEndPoint(string url)
internal static List<UdpClient> GetUdpClients(UsedInContext pubSubContext, string networkInterface, IPEndPoint configuredEndpoint)
{
StringBuilder buffer = new StringBuilder();
buffer.AppendFormat("networkAddressUrl.NetworkInterface = {0} \n", networkInterface != null ? networkInterface : "null");
buffer.AppendFormat("networkAddressUrl.NetworkInterface = {0} \n", networkInterface ?? "null");
buffer.AppendFormat("configuredEndpoint = {0}", configuredEndpoint != null ? configuredEndpoint.ToString() : "null");

Utils.Trace(Utils.TraceMasks.Information, buffer.ToString());
Expand Down Expand Up @@ -249,11 +249,7 @@ private static bool IsIPv4MulticastAddress(IPAddress address)
{
if (address == null) return false;
byte[] bytes = address.GetAddressBytes();
if (bytes[0] >= 224 && bytes[0] <= 239)
{
return true;
}
return false;
return bytes[0] >= 224 && bytes[0] <= 239;
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Opc.Ua.PubSub/Transport/UdpDiscovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public virtual async Task StartAsync(IServiceMessageContext messageContext)
// initialize Discovery channels
m_discoveryUdpClients = UdpClientCreator.GetUdpClients(UsedInContext.Discovery, DiscoveryNetworkInterfaceName, DiscoveryNetworkAddressEndPoint);
}
});
}).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -116,7 +116,7 @@ public virtual async Task StopAsync()
}
}

await Task.CompletedTask;
await Task.CompletedTask.ConfigureAwait(false);
}
#endregion

Expand Down
4 changes: 2 additions & 2 deletions Libraries/Opc.Ua.PubSub/Transport/UdpDiscoveryPublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public UdpDiscoveryPublisher(UdpPubSubConnection udpConnection) : base(udpConnec
/// <returns></returns>
public override async Task StartAsync(IServiceMessageContext messageContext)
{
await base.StartAsync(messageContext);
await base.StartAsync(messageContext).ConfigureAwait(false);

if (m_discoveryUdpClients != null)
{
Expand Down Expand Up @@ -181,7 +181,7 @@ private void ProcessReceivedMessageDiscovery(byte[] messageBytes, IPEndPoint sou

private async Task SendResponseDataSetMetaData()
{
await Task.Delay(m_responseInterval);
await Task.Delay(m_responseInterval).ConfigureAwait(false);

lock (m_lock)
{
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Opc.Ua.PubSub/Transport/UdpDiscoverySubscriber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public UdpDiscoverySubscriber(UdpPubSubConnection udpConnection) : base(udpConne
/// <returns></returns>
public override async Task StartAsync(IServiceMessageContext messageContext)
{
await base.StartAsync(messageContext);
await base.StartAsync(messageContext).ConfigureAwait(false);

m_intervalRunner.Start();
}
Expand All @@ -82,7 +82,7 @@ public override async Task StartAsync(IServiceMessageContext messageContext)
/// <returns></returns>
public override async Task StopAsync()
{
await base.StopAsync();
await base.StopAsync().ConfigureAwait(false);

m_intervalRunner.Stop();
}
Expand Down
10 changes: 5 additions & 5 deletions Libraries/Opc.Ua.PubSub/Transport/UdpPubSubConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public UdpPubSubConnection(UaPubSubApplication uaPubSubApplication, PubSubConnec
protected override async Task InternalStart()
{
//cleanup all existing UdpClient previously open
await InternalStop();
await InternalStop().ConfigureAwait(false);

if (NetworkAddressEndPoint == null)
{
Expand All @@ -111,7 +111,7 @@ protected override async Task InternalStart()
}

m_udpDiscoveryPublisher = new UdpDiscoveryPublisher(this);
await m_udpDiscoveryPublisher.StartAsync(MessageContext);
await m_udpDiscoveryPublisher.StartAsync(MessageContext).ConfigureAwait(false);
}

//subscriber initialization
Expand All @@ -137,7 +137,7 @@ protected override async Task InternalStart()

// initialize the discovery channel
m_udpDiscoverySubscriber = new UdpDiscoverySubscriber(this);
await m_udpDiscoverySubscriber.StartAsync(MessageContext);
await m_udpDiscoverySubscriber.StartAsync(MessageContext).ConfigureAwait(false);

// add handler to metaDataReceived event
this.Application.MetaDataReceived += Application_MetaDataReceived;
Expand Down Expand Up @@ -167,12 +167,12 @@ protected override async Task InternalStop()

if (m_udpDiscoveryPublisher != null)
{
await m_udpDiscoveryPublisher.StopAsync();
await m_udpDiscoveryPublisher.StopAsync().ConfigureAwait(false);
}

if (m_udpDiscoverySubscriber != null)
{
await m_udpDiscoverySubscriber.StopAsync();
await m_udpDiscoverySubscriber.StopAsync().ConfigureAwait(false);

// remove handler to metaDataReceived event
this.Application.MetaDataReceived -= Application_MetaDataReceived;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,26 @@ private static X509KeyUsageFlags GetKeyUsage(X509Certificate2 cert)
using (RSA rsaPrivateKey = certWithPrivateKey.GetRSAPrivateKey())
using (RSA rsaPublicKey = certWithPublicKey.GetRSAPublicKey())
{
X509KeyUsageFlags keyUsage = GetKeyUsage(certWithPublicKey);
if ((keyUsage & X509KeyUsageFlags.DataEncipherment) != 0)
{
result = VerifyRSAKeyPairCrypt(rsaPublicKey, rsaPrivateKey);
}
else if ((keyUsage & X509KeyUsageFlags.DigitalSignature) != 0)
// For non RSA certificates, RSA keys are null
if (rsaPrivateKey != null && rsaPublicKey != null)
{
result = VerifyRSAKeyPairSign(rsaPublicKey, rsaPrivateKey);
X509KeyUsageFlags keyUsage = GetKeyUsage(certWithPublicKey);
if ((keyUsage & X509KeyUsageFlags.DataEncipherment) != 0)
{
result = VerifyRSAKeyPairCrypt(rsaPublicKey, rsaPrivateKey);
}
else if ((keyUsage & X509KeyUsageFlags.DigitalSignature) != 0)
{
result = VerifyRSAKeyPairSign(rsaPublicKey, rsaPrivateKey);
}
else
{
throw new CryptographicException("Don't know how to verify the public/private key pair.");
}
}
else
{
throw new CryptographicException("Don't know how to verify the public/private key pair.");
throw new CryptographicException("The certificate does not contain a RSA public/private key pair.");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public static Task<ApplicationConfiguration> Load(FileInfo file, ApplicationType
{
using (FileStream stream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read))
{
configuration = await Load(stream, applicationType, systemType, applyTraceSettings, certificatePasswordProvider);
configuration = await Load(stream, applicationType, systemType, applyTraceSettings, certificatePasswordProvider).ConfigureAwait(false);
}
}
catch (Exception e)
Expand Down
4 changes: 2 additions & 2 deletions Stack/Opc.Ua.Core/Stack/Nodes/ContentFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1191,12 +1191,12 @@ public override string ToString()
/// <returns>The result of the validation</returns>
public override ServiceResult Validate(FilterContext context, int index)
{
if (m_index < 0)
if (index < 0)
{
return ServiceResult.Create(
StatusCodes.BadFilterOperandInvalid,
"ElementOperand specifies an Index that is less than zero ({0}).",
m_index);
index);
}

if (m_index <= index)
Expand Down

0 comments on commit 2430a65

Please sign in to comment.