/// <summary> /// Reads to identifier to show for notification in payload of IoT Hub method /// Prio 1: DataSetFieldId (need to be read from message) /// Prio 2: DisplayName - nothing to do, because notification.Id already contains DisplayName /// Prio 3: ExpandedNodeId /// </summary> /// <param name="notification">Notification, were ID need to be looked up for</param> /// <param name="message">subscription notification message, containing notifications</param> /// <param name="context">service context</param> /// <returns>identifier of payload element</returns> private string GetPayloadIdentifier(MonitoredItemNotificationModel notification, DataSetMessageModel message, ServiceMessageContext context) { if (notification is null) { throw new ArgumentNullException(nameof(notification)); } if (message is null) { throw new ArgumentNullException(nameof(message)); } if (context is null) { throw new ArgumentNullException(nameof(context)); } var notificationNodeId = notification.NodeId.ToString(); var notificationExpandedNodeId = notification.NodeId.ToExpandedNodeId(context.NamespaceUris).AsString(context); if (_knownPayloadIdentifiers.TryGetValue(notificationNodeId, out var knownPayloadIdentifier) && !string.IsNullOrEmpty(knownPayloadIdentifier)) { return(knownPayloadIdentifier); } else { //do the long running lookup as less as possible var dataSetWriter = message.Writer; foreach (var publishedVariableData in dataSetWriter.DataSet.DataSetSource.PublishedVariables.PublishedData) { if (publishedVariableData.PublishedVariableNodeId == notification.NodeId || publishedVariableData.PublishedVariableNodeId.ToExpandedNodeId(context).AsString(context) == notificationExpandedNodeId) { if (publishedVariableData.Id != notification.NodeId) { _knownPayloadIdentifiers[notificationNodeId] = publishedVariableData.Id; return(publishedVariableData.Id); } else { var notificationIdentifier = !string.IsNullOrEmpty(notification.Id) ? notification.Id : notificationExpandedNodeId; _knownPayloadIdentifiers[notificationNodeId] = notificationIdentifier; return(notificationIdentifier); } } } } // Fall back to id of the notification or expanded node id. var knownIdentifier = !string.IsNullOrEmpty(notification.Id) ? notification.Id : notificationExpandedNodeId; _knownPayloadIdentifiers[notification.NodeId.ToString()] = knownIdentifier; return(knownIdentifier); }
/// <summary> /// Reads to identifier to show for notification in payload of IoT Hub method /// Prio 1: DataSetFieldId (need to be read from message) /// Prio 2: DisplayName - nothing to do, because notification.Id already contains DisplayName /// Prio 3: ExpandedNodeId /// </summary> /// <param name="notification">Notification, were ID need to be looked up for</param> /// <param name="message">subscription notification message, containing notifications</param> /// <param name="context">service context</param> /// <returns>identifier of payload element</returns> private string GetPayloadIdentifier(MonitoredItemNotificationModel notification, DataSetMessageModel message, ServiceMessageContext context) { if (notification is null) { throw new ArgumentNullException(nameof(notification)); } if (message is null) { throw new ArgumentNullException(nameof(message)); } if (context is null) { throw new ArgumentNullException(nameof(context)); } if (_knownPayloadIdentifiers.TryGetValue(notification.NodeId.ToString(), out var knownPayloadIdentifier)) { if (!string.IsNullOrEmpty(knownPayloadIdentifier)) { return(knownPayloadIdentifier); } } else //do the long running lookup as less as possible { foreach (var dataSetWriter in message.WriterGroup.DataSetWriters) { foreach (var publishedVariableData in dataSetWriter.DataSet.DataSetSource.PublishedVariables.PublishedData) { if ((publishedVariableData.PublishedVariableNodeId == notification.NodeId || publishedVariableData.PublishedVariableNodeId.ToExpandedNodeId(context).AsString(context) == notification.NodeId.ToExpandedNodeId(context.NamespaceUris).AsString(context)) && publishedVariableData.Id != notification.NodeId) { _knownPayloadIdentifiers[notification.NodeId.ToString()] = publishedVariableData.Id; return(publishedVariableData.Id); } else { _knownPayloadIdentifiers[notification.NodeId.ToString()] = string.Empty; } } } } return(!string.IsNullOrEmpty(notification.Id) ? notification.Id : notification.NodeId.ToExpandedNodeId(context.NamespaceUris) .AsString(message.ServiceMessageContext)); }