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);
+ }
}
}