Skip to content

Commit

Permalink
Add boilerplate to reference local OPC UA SDK (#386)
Browse files Browse the repository at this point in the history
* Add support for UseLocalOpcUaSdk

* Remove configs

* Handle BadSessionClosed

* Update comment

* Comment out sdk prj from sln

* Add comment
  • Loading branch information
luiscantero authored Aug 12, 2024
1 parent ea70038 commit 306f3dc
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
6 changes: 6 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project>
<PropertyGroup>
<!-- Uncomment the following to test against a local OPC UA SDK and avoid error CS0433 -->
<!-- <DefineConstants>UseLocalOpcUaSdk</DefineConstants> -->
</PropertyGroup>
</Project>
8 changes: 7 additions & 1 deletion opcplc.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33205.214
Expand Down Expand Up @@ -40,6 +40,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "templates", "templates", "{
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "opc-plc-tests", "tests\opc-plc-tests.csproj", "{978DA9FC-4211-46CE-8548-D16E3DC3550F}"
EndProject
# Uncomment the following to include local OPC UA SDK files, e.g. for debugging.
# You will also need to define the constant UseLocalOpcUaSdk in the file Directory.Build.targets.
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Opc.Ua.Configuration", "..\UA-.NETStandard\Libraries\Opc.Ua.Configuration\Opc.Ua.Configuration.csproj", "{19796333-27CA-461A-A3B3-96F7DB378F23}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Opc.Ua.Server", "..\UA-.NETStandard\Libraries\Opc.Ua.Server\Opc.Ua.Server.csproj", "{6D71B6B9-2A80-44A7-A5BE-E1012C2419E0}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
11 changes: 11 additions & 0 deletions src/PlcServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,17 @@ public override ResponseHeader Publish(

return new ResponseHeader { ServiceResult = StatusCodes.BadSecureChannelIdInvalid };
}
catch (ServiceResultException ex) when (ex.StatusCode == StatusCodes.BadSessionClosed)
{
MetricsHelper.RecordTotalErrors(nameof(Publish));

LogErrorWithStatusCode(
nameof(Publish),
nameof(StatusCodes.BadSessionClosed),
ex);

return new ResponseHeader { ServiceResult = StatusCodes.BadSessionClosed };
}
catch (Exception ex)
{
MetricsHelper.RecordTotalErrors(nameof(Publish));
Expand Down
23 changes: 16 additions & 7 deletions src/opc-plc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,28 @@
<PackageReference Update="Nerdbank.GitVersioning" Version="3.6.139" />
</ItemGroup>

<!-- When referencing a local build of the OPC UA stack for testing, define the constant UseLocalOpcUaSdk in the file Directory.Build.targets -->
<Choose>
<When Condition="'$(Configuration)'=='Debug'">
<ItemGroup Condition="!$(DefineConstants.Contains(UseLocalOpcUaSdk))">
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Configuration.Debug" Version="1.5.374.78" NoWarn="NU5104" />
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Server.Debug" Version="1.5.374.78" NoWarn="NU5104" />
</ItemGroup>
<ItemGroup Condition="$(DefineConstants.Contains(UseLocalOpcUaSdk))">
<ProjectReference Include="..\..\UA-.NETStandard\Libraries\Opc.Ua.Configuration\Opc.Ua.Configuration.csproj" />
<ProjectReference Include="..\..\UA-.NETStandard\Libraries\Opc.Ua.Server\Opc.Ua.Server.csproj" />
</ItemGroup>
</When>
<When Condition="'$(Configuration)'=='Release'">
<ItemGroup>
<ItemGroup Condition="!$(DefineConstants.Contains(UseLocalOpcUaSdk))">
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Configuration" Version="1.5.374.78" NoWarn="NU5104" />
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Server" Version="1.5.374.78" NoWarn="NU5104" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Configuration.Debug" Version="1.5.374.78" NoWarn="NU5104" />
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Server.Debug" Version="1.5.374.78" NoWarn="NU5104" />
<ItemGroup Condition="$(DefineConstants.Contains(UseLocalOpcUaSdk))">
<ProjectReference Include="..\..\UA-.NETStandard\Libraries\Opc.Ua.Configuration\Opc.Ua.Configuration.csproj" />
<ProjectReference Include="..\..\UA-.NETStandard\Libraries\Opc.Ua.Server\Opc.Ua.Server.csproj" />
</ItemGroup>
</Otherwise>
</When>
</Choose>

<ItemGroup>
Expand Down

0 comments on commit 306f3dc

Please sign in to comment.