fix: preserve SDK 2.0 client value and lifetime contracts
This commit is contained in:
@@ -310,7 +310,7 @@ public sealed class OpcUaClientService : IOpcUaClientService
|
||||
}
|
||||
|
||||
var handle = await subscription.AddDataChangeMonitoredItemAsync(
|
||||
nodeId, intervalMs, OnDataChangeNotification, ct);
|
||||
nodeId, intervalMs, DataCallback(session, subscription), ct);
|
||||
|
||||
lock (_subscriptionLock)
|
||||
{
|
||||
@@ -394,7 +394,7 @@ public sealed class OpcUaClientService : IOpcUaClientService
|
||||
|
||||
var filter = CreateAlarmEventFilter();
|
||||
await subscription.AddEventMonitoredItemAsync(
|
||||
monitorNode, intervalMs, filter, OnAlarmEventNotification, ct);
|
||||
monitorNode, intervalMs, filter, AlarmCallback(session, subscription), ct);
|
||||
|
||||
lock (_subscriptionLock)
|
||||
{
|
||||
@@ -989,7 +989,7 @@ public sealed class OpcUaClientService : IOpcUaClientService
|
||||
}
|
||||
|
||||
var handle = await dataSubscription.AddDataChangeMonitoredItemAsync(
|
||||
nodeId, intervalMs, OnDataChangeNotification, CancellationToken.None);
|
||||
nodeId, intervalMs, DataCallback(session, dataSubscription), CancellationToken.None);
|
||||
|
||||
lock (_subscriptionLock)
|
||||
{
|
||||
@@ -1012,7 +1012,7 @@ public sealed class OpcUaClientService : IOpcUaClientService
|
||||
lock (_subscriptionLock) _alarmSubscription = replayedAlarms;
|
||||
var filter = CreateAlarmEventFilter();
|
||||
await replayedAlarms.AddEventMonitoredItemAsync(
|
||||
monitorNode, intervalMs, filter, OnAlarmEventNotification, CancellationToken.None);
|
||||
monitorNode, intervalMs, filter, AlarmCallback(session, replayedAlarms), CancellationToken.None);
|
||||
|
||||
lock (_subscriptionLock)
|
||||
{
|
||||
@@ -1026,6 +1026,25 @@ public sealed class OpcUaClientService : IOpcUaClientService
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsCurrentNotification(ISessionAdapter session, ISubscriptionAdapter subscription, bool alarm)
|
||||
{
|
||||
lock (_subscriptionLock)
|
||||
return !_disposed && _state == ConnectionState.Connected && ReferenceEquals(_session, session)
|
||||
&& ReferenceEquals(alarm ? _alarmSubscription : _dataSubscription, subscription);
|
||||
}
|
||||
|
||||
private Action<string, DataValue> DataCallback(ISessionAdapter session, ISubscriptionAdapter subscription) =>
|
||||
(nodeId, value) =>
|
||||
{
|
||||
if (IsCurrentNotification(session, subscription, false)) OnDataChangeNotification(nodeId, value);
|
||||
};
|
||||
|
||||
private Action<EventFieldList> AlarmCallback(ISessionAdapter session, ISubscriptionAdapter subscription) =>
|
||||
fields =>
|
||||
{
|
||||
if (IsCurrentNotification(session, subscription, true)) OnAlarmEventNotification(fields);
|
||||
};
|
||||
|
||||
private void OnDataChangeNotification(string nodeId, DataValue value)
|
||||
{
|
||||
DataChanged?.Invoke(this, new DataChangedEventArgs(nodeId, value));
|
||||
|
||||
Reference in New Issue
Block a user