Skip to content

Commit

Permalink
Use editorconfig and implement feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelschlatter committed Mar 26, 2024
1 parent ee08496 commit 4b8b525
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 35 deletions.
40 changes: 40 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
charset = utf-8

[*.cs]
trim_trailing_whitespace = true
max_line_length = 175

dotnet_style_namespace_match_folder = true:error
dotnet_diagnostic.IDE0130.severity = error

csharp_style_namespace_declarations = file_scoped:error
dotnet_diagnostic.IDE0161.severity = error

dotnet_diagnostic.IDE0005.severity = error

dotnet_diagnostic.CA2007.severity = error
dotnet_diagnostic.CA2016.severity = error

dotnet_naming_rule.private_members_with_underscore.symbols = private_fields
dotnet_naming_rule.private_members_with_underscore.style = prefix_underscore
dotnet_naming_rule.private_members_with_underscore.severity = warning
dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private
dotnet_naming_style.prefix_underscore.capitalization = camel_case
dotnet_naming_style.prefix_underscore.required_prefix = _

dotnet_naming_rule.const_members_all_caps.symbols = const_fields
dotnet_naming_rule.const_members_all_caps.style = all_caps
dotnet_naming_rule.const_members_all_caps.severity = warning
dotnet_naming_symbols.const_fields.applicable_kinds = field
dotnet_naming_symbols.const_fields.applicable_accessibilities = *
dotnet_naming_symbols.const_fields.required_modifiers = const
dotnet_naming_style.all_caps.capitalization = all_upper
dotnet_naming_style.all_caps.word_separator = _
8 changes: 8 additions & 0 deletions Source/OPCUA.CodeStyle.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<NoWarn>$(NoWarn);SYSLIB1006;CS1591;IL2104;IL2026;CS1570;CS1573</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
</Project>
3 changes: 2 additions & 1 deletion Source/OPCUA.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="./OPCUA.CodeStyle.props" />
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
Expand All @@ -23,4 +24,4 @@
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Core" Version="1.5.374.27" />
<PackageReference Include="Polly" Version="7.2.4" />
</ItemGroup>
</Project>
</Project>
6 changes: 3 additions & 3 deletions Source/OpcuaClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async Task<bool> ConnectAsync()
30 * 60 * 1000,
new UserIdentity(),
null
);
).ConfigureAwait(false);

if (opcuaSession != null && opcuaSession.Connected)
{
Expand Down Expand Up @@ -188,7 +188,7 @@ private void CertificateValidation(CertificateValidator sender, CertificateValid
{
_logger.Information("Untrusted Certificate accepted. Subject={0}, Issuer={1}", e.Certificate.Subject, e.Certificate.Issuer);
}

else
{
_logger.Information("Untrusted Certificate rejected. Subject={0}, Issuer={1}", e.Certificate.Subject, e.Certificate.Issuer);
Expand Down Expand Up @@ -219,7 +219,7 @@ private void CertificateValidation(CertificateValidator sender, CertificateValid

datapoints.Add(opcuaDatapointOutput);
}

return datapoints;
}
}
Expand Down
14 changes: 7 additions & 7 deletions Source/OpcuaConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace RaaLabs.Edge.Connectors.OPCUA;
public class OpcuaConnector : IRunAsync, IProduceEvent<Events.OpcuaDatapointOutput>
{
/// <summary>
///
///
/// </summary>
public event EventEmitter<Events.OpcuaDatapointOutput> SendDatapoint;
private OpcuaClient _opcuaClient;
Expand Down Expand Up @@ -74,7 +74,7 @@ private ReadValueIdCollection InitializeReadValueIdCollection()
ReadValueIdCollection nodesToRead = new ReadValueIdCollection(){};
foreach (var nodeId in _opcuaConfiguration.NodeIds)
{
// Because nodeId and value cannot be read using the same ReadValueId, but nodeId and value are required
// Because nodeId and value cannot be read using the same ReadValueId, but nodeId and value are required
nodesToRead.Add(new ReadValueId() { NodeId = nodeId, AttributeId = Attributes.NodeId });
nodesToRead.Add(new ReadValueId() { NodeId = nodeId, AttributeId = Attributes.Value });
}
Expand All @@ -86,7 +86,7 @@ public async Task Run()
{
_logger.Information("Raa Labs OPC UA connector");
_opcuaClient = new OpcuaClient(_opcuaAppInstance.ApplicationConfiguration, _opcuaConfiguration, _logger, ClientBase.ValidateResponse);
await _opcuaClient.ConnectAsync();
await _opcuaClient.ConnectAsync().ConfigureAwait(false);

while (true)
{
Expand All @@ -100,10 +100,10 @@ public async Task Run()

await policy.ExecuteAsync(async () =>
{
await ConnectOpcua();
});
await ConnectOpcua().ConfigureAwait(false);
}).ConfigureAwait(false);

await Task.Delay(1000);
await Task.Delay(1000).ConfigureAwait(false);
}
}

Expand All @@ -113,7 +113,7 @@ private async Task ConnectOpcua()
{
if (!_opcuaClient.Session.Connected)
{
await _opcuaClient.ConnectAsync();
await _opcuaClient.ConnectAsync().ConfigureAwait(false);
}

List<Events.OpcuaDatapointOutput> opcuaDatapoints = _opcuaClient.ReadNodes(_nodesToRead);
Expand Down
46 changes: 22 additions & 24 deletions Source/events/OpcuaDatapointOutput.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
// Copyright (c) RaaLabs. All rights reserved.
// Licensed under the GPLv2 License. See LICENSE file in the project root for full license information.

using System;
using RaaLabs.Edge.Modules.EdgeHub;


namespace RaaLabs.Edge.Connectors.OPCUA.Events
namespace RaaLabs.Edge.Connectors.OPCUA.Events;

/// <summary>
/// The data point on the format it should be sent to EdgeHub.
/// </summary>
[OutputName("output")]
public class OpcuaDatapointOutput : IEdgeHubOutgoingEvent
{
/// <summary>
/// The data point on the format it should be sent to EdgeHub.
/// Represents the Source system.
/// </summary>
[OutputName("output")]
public class OpcuaDatapointOutput : IEdgeHubOutgoingEvent
{
/// <summary>
/// Represents the Source system.
/// </summary>
public string Source { get; set; }
public string Source { get; set; }

/// <summary>
/// Gets or sets the tag. Represents the sensor name from the source system, OPC UA node id, consisting of namespace index and identifier, e.g. "ns=3;i=1002".
/// </summary>
public string Tag { get; set; }
/// <summary>
/// Gets or sets the tag. Represents the sensor name from the source system, OPC UA node id, consisting of namespace index and identifier, e.g. "ns=3;i=1002".
/// </summary>
public string Tag { get; set; }

/// <summary>
/// The value of the sensor reading.
/// </summary>
public dynamic Value { get; set; }
/// <summary>
/// The value of the sensor reading.
/// </summary>
public dynamic Value { get; set; }

/// <summary>
/// Gets or sets the timestamp in the form of EPOCH milliseconds granularity.
/// </summary>
public long Timestamp { get; set; }
}
}
/// <summary>
/// Gets or sets the timestamp in the form of EPOCH milliseconds granularity.
/// </summary>
public long Timestamp { get; set; }
}

0 comments on commit 4b8b525

Please sign in to comment.