Example #1
0
        /// <summary>
        /// Updates the list of area filters.
        /// </summary>
        private void UpdateAreaFilter(List <NodeId> areas)
        {
            // check if monitoring all events.
            if (areas == null || areas.Count == 0)
            {
                MonitoredItem monitoredItem = null;

                if (!m_notifiers.TryGetValue(Opc.Ua.ObjectIds.Server, out monitoredItem))
                {
                    monitoredItem = CreateMonitoredItem(Opc.Ua.ObjectIds.Server);
                }

                m_notifiers.Clear();
                m_notifiers[Opc.Ua.ObjectIds.Server] = monitoredItem;
                return;
            }

            // build table of areas to monitor.
            NodeIdDictionary <MonitoredItem> notifiers = new NodeIdDictionary <MonitoredItem>();

            // map all of the area search strings onto NodeIds for notifiers.
            for (int ii = 0; ii < areas.Count; ii++)
            {
                NodeId areaId = areas[ii];

                // check for existing item.
                MonitoredItem monitoredItem = null;

                if (m_notifiers.TryGetValue(areaId, out monitoredItem))
                {
                    notifiers[areaId] = monitoredItem;
                    continue;
                }

                // check for new item.
                if (!notifiers.ContainsKey(areaId))
                {
                    notifiers[areaId] = CreateMonitoredItem(areaId);
                }
            }

            // mark unused items for deletion.
            foreach (MonitoredItem monitoredItem in m_notifiers.Values)
            {
                if (!notifiers.ContainsKey(monitoredItem.StartNodeId))
                {
                    m_subscription.RemoveItem(monitoredItem);
                }
            }

            m_notifiers = notifiers;
        }
Example #2
0
        /// <summary>
        /// Checks the isInverse flag are returns true if a specified target exists.
        /// </summary>
        /// <param name="entry">The entry.</param>
        /// <param name="reference">The reference.</param>
        /// <returns>
        ///     <c>true</c> if the specified entry contains key; otherwise, <c>false</c>.
        /// </returns>
        private static bool ContainsKey(ReferenceTypeEntry entry, IReference reference)
        {
            // handle reference to external targets.
            if (reference.TargetId.IsAbsolute)
            {
                Dictionary <ExpandedNodeId, LinkedListNode <KeyValuePair <IReference, T> > > targets = null;

                if (reference.IsInverse)
                {
                    targets = entry.InverseExternalTargets;
                }
                else
                {
                    targets = entry.ForwardExternalTargets;
                }

                if (targets == null)
                {
                    return(false);
                }

                return(targets.ContainsKey(reference.TargetId));
            }

            // handle reference to internal target.
            else
            {
                NodeIdDictionary <LinkedListNode <KeyValuePair <IReference, T> > > targets = null;

                if (reference.IsInverse)
                {
                    targets = entry.InverseTargets;
                }
                else
                {
                    targets = entry.ForwardTargets;
                }

                if (targets == null)
                {
                    return(false);
                }

                return(targets.ContainsKey((NodeId)reference.TargetId));
            }
        }
        /// <summary>
        /// Updates the list of area filters.
        /// </summary>
        private void UpdateAreaFilter(List<NodeId> areas)
        {
            // check if monitoring all events.
            if (areas == null || areas.Count == 0)
            {
                MonitoredItem monitoredItem = null;

                if (!m_notifiers.TryGetValue(Opc.Ua.ObjectIds.Server, out monitoredItem))
                {
                    monitoredItem = CreateMonitoredItem(Opc.Ua.ObjectIds.Server);
                }

                m_notifiers.Clear();
                m_notifiers[Opc.Ua.ObjectIds.Server] = monitoredItem;
                return;
            }

            // build table of areas to monitor.
            NodeIdDictionary<MonitoredItem> notifiers = new NodeIdDictionary<MonitoredItem>();

            // map all of the area search strings onto NodeIds for notifiers.
            for (int ii = 0; ii < areas.Count; ii++)
            {
                NodeId areaId = areas[ii];

                // check for existing item.
                MonitoredItem monitoredItem = null;

                if (m_notifiers.TryGetValue(areaId, out monitoredItem))
                {
                    notifiers[areaId] = monitoredItem;
                    continue;
                }

                // check for new item.
                if (!notifiers.ContainsKey(areaId))
                {
                    notifiers[areaId] = CreateMonitoredItem(areaId);
                }
            }

            // mark unused items for deletion.
            foreach (MonitoredItem monitoredItem in m_notifiers.Values)
            {
                if (!notifiers.ContainsKey(monitoredItem.StartNodeId))
                {
                    m_subscription.RemoveItem(monitoredItem);
                }
            }

            m_notifiers = notifiers;
        }