From 306f3dcb9a60493cc5604e8deed9bd3c0e00608d Mon Sep 17 00:00:00 2001 From: Luis Cantero Date: Mon, 12 Aug 2024 08:58:16 +0200 Subject: [PATCH] Add boilerplate to reference local OPC UA SDK (#386) * Add support for UseLocalOpcUaSdk * Remove configs * Handle BadSessionClosed * Update comment * Comment out sdk prj from sln * Add comment --- Directory.Build.targets | 6 ++++++ opcplc.sln | 8 +++++++- src/PlcServer.cs | 11 +++++++++++ src/opc-plc.csproj | 23 ++++++++++++++++------- 4 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 Directory.Build.targets diff --git a/Directory.Build.targets b/Directory.Build.targets new file mode 100644 index 00000000..d9af2ea6 --- /dev/null +++ b/Directory.Build.targets @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/opcplc.sln b/opcplc.sln index 856d7cdf..40bb6688 100644 --- a/opcplc.sln +++ b/opcplc.sln @@ -1,4 +1,4 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.4.33205.214 @@ -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 diff --git a/src/PlcServer.cs b/src/PlcServer.cs index 088cd7b5..c985477c 100644 --- a/src/PlcServer.cs +++ b/src/PlcServer.cs @@ -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)); diff --git a/src/opc-plc.csproj b/src/opc-plc.csproj index 77bd405b..4a4c922d 100644 --- a/src/opc-plc.csproj +++ b/src/opc-plc.csproj @@ -39,19 +39,28 @@ + + + + + + + + + + + - + - - - - - + + + - +