From 40db29f3a2fa031427433ea2f73692a115d21a35 Mon Sep 17 00:00:00 2001 From: Alin Moldovean Date: Wed, 17 Apr 2019 10:03:19 +0300 Subject: [PATCH] Fixes #703. Fix regression caused by #656. Add a MonitoredItem constructor to allow keeping the ClientHandle of the template. (#704) --- .../SDK/Opc.Ua.Client/MonitoredItem.cs | 22 +++++++++++++++---- .../SDK/Opc.Ua.Client/Subscription.cs | 11 +++++----- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/SampleApplications/SDK/Opc.Ua.Client/MonitoredItem.cs b/SampleApplications/SDK/Opc.Ua.Client/MonitoredItem.cs index 7bd710ab82..07ec8a3b6d 100644 --- a/SampleApplications/SDK/Opc.Ua.Client/MonitoredItem.cs +++ b/SampleApplications/SDK/Opc.Ua.Client/MonitoredItem.cs @@ -77,12 +77,22 @@ namespace Opc.Ua.Client /// /// The template used to specify the monitoring parameters. /// if set to true the event handlers are copied. - public MonitoredItem(MonitoredItem template, bool copyEventHandlers) + public MonitoredItem(MonitoredItem template, bool copyEventHandlers) : this(template, copyEventHandlers, false) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The template used to specify the monitoring parameters. + /// if set to true the event handlers are copied. + /// if set to true the clientHandle is of the template copied. + public MonitoredItem(MonitoredItem template, bool copyEventHandlers, bool copyClientHandle) { Initialize(); - + if (template != null) - { + { string displayName = template.DisplayName; if (displayName != null) @@ -103,7 +113,6 @@ namespace Opc.Ua.Client } } - m_clientHandle = template.m_clientHandle; // keep the same clientHandle since it uniquely identifies the monitored item for the subscriber m_handle = template.m_handle; m_displayName = Utils.Format("{0} {1}", displayName, m_clientHandle); m_startNodeId = template.m_startNodeId; @@ -123,6 +132,11 @@ namespace Opc.Ua.Client m_Notification = template.m_Notification; } + if (copyClientHandle) + { + m_clientHandle = template.m_clientHandle; + } + // this ensures the state is consistent with the node class. NodeClass = template.m_nodeClass; } diff --git a/SampleApplications/SDK/Opc.Ua.Client/Subscription.cs b/SampleApplications/SDK/Opc.Ua.Client/Subscription.cs index 4a1db06462..cad4f3b036 100644 --- a/SampleApplications/SDK/Opc.Ua.Client/Subscription.cs +++ b/SampleApplications/SDK/Opc.Ua.Client/Subscription.cs @@ -68,7 +68,7 @@ namespace Opc.Ua.Client Initialize(); if (template != null) - { + { string displayName = template.DisplayName; if (String.IsNullOrEmpty(displayName)) @@ -110,7 +110,7 @@ namespace Opc.Ua.Client if (copyEventHandlers) { m_StateChanged = template.m_StateChanged; - m_PublishStatusChanged = template.m_PublishStatusChanged; + m_PublishStatusChanged = template.m_PublishStatusChanged; m_fastDataChangeCallback = template.m_fastDataChangeCallback; m_fastEventCallback = template.m_fastEventCallback; } @@ -118,11 +118,10 @@ namespace Opc.Ua.Client // copy the list of monitored items. foreach (MonitoredItem monitoredItem in template.MonitoredItems) { - MonitoredItem clone = new MonitoredItem(monitoredItem, copyEventHandlers); - clone.Subscription = this; + MonitoredItem clone = new MonitoredItem(monitoredItem, copyEventHandlers, true); clone.DisplayName = monitoredItem.DisplayName; - m_monitoredItems.Add(clone.ClientHandle, clone); - } + AddItem(clone); + } } }