Пример #1
0
        /// <summary>
        /// Updates the node. This will copy data from another node into this node. Updated elements are checked for equality
        /// and the method will only return true if the node data has been changed.
        ///
        /// <param name="node">the <see cref="ZigBeeNode"> that contains the newer node data.</param>
        /// <returns>true if there were changes made as a result of the update</returns>
        /// </summary>
        public bool UpdateNode(ZigBeeNode node)
        {
            if (!node.IeeeAddress.Equals(IeeeAddress))
            {
                return(false);
            }

            bool updated = false;

            if (!NetworkAddress.Equals(node.NetworkAddress))
            {
                updated        = true;
                NetworkAddress = node.NetworkAddress;
            }

            if (!NodeDescriptor.Equals(node.NodeDescriptor))
            {
                updated        = true;
                NodeDescriptor = node.NodeDescriptor;
            }

            if (!PowerDescriptor.Equals(node.PowerDescriptor))
            {
                updated         = true;
                PowerDescriptor = node.PowerDescriptor;
            }

            lock (AssociatedDevices)
            {
                if (!AssociatedDevices.Equals(node.AssociatedDevices))
                {
                    updated = true;
                    AssociatedDevices.Clear();
                    AssociatedDevices.AddRange(node.AssociatedDevices);
                }
            }

            lock (BindingTable)
            {
                if (!BindingTable.Equals(node.BindingTable))
                {
                    updated = true;
                    BindingTable.Clear();
                    BindingTable.AddRange(node.BindingTable);
                }
            }

            lock (Neighbors)
            {
                if (!Neighbors.Equals(node.Neighbors))
                {
                    updated = true;
                    Neighbors.Clear();
                    Neighbors.AddRange(node.Neighbors);
                }
            }

            lock (Routes)
            {
                if (!Routes.Equals(node.Routes))
                {
                    updated = true;
                    Routes.Clear();
                    Routes.AddRange(node.Routes);
                }
            }

            // Endpoints are only copied over if they don't exist in the node
            // The assumption here is that endpoints are only set once, and not changed.
            // This should be valid as they are set through the SimpleDescriptor.
            foreach (var endpoint in node.Endpoints)
            {
                if (Endpoints.ContainsKey(endpoint.Key))
                {
                    continue;
                }
                updated = true;
                Endpoints[endpoint.Key] = endpoint.Value;
            }

            return(updated);
        }
Пример #2
0
        /// <summary>
        /// Updates the node. This will copy data from another node into this node. Updated elements are checked for equality
        /// and the method will only return true if the node data has been changed.
        ///
        /// @param node the {@link ZigBeeNode} that contains the newer node data.
        /// @return true if there were changes made as a result of the update
        /// </summary>
        public bool UpdateNode(ZigBeeNode node)
        {
            if (!node.IeeeAddress.Equals(IeeeAddress))
            {
                return(false);
            }

            bool updated = false;

            if (!NetworkAddress.Equals(node.NetworkAddress))
            {
                updated        = true;
                NetworkAddress = node.NetworkAddress;
            }

            if (!NodeDescriptor.Equals(node.NodeDescriptor))
            {
                updated        = true;
                NodeDescriptor = node.NodeDescriptor;
            }

            if (!PowerDescriptor.Equals(node.PowerDescriptor))
            {
                updated         = true;
                PowerDescriptor = node.PowerDescriptor;
            }

            lock (AssociatedDevices)
            {
                if (!AssociatedDevices.Equals(node.AssociatedDevices))
                {
                    updated = true;
                    AssociatedDevices.Clear();
                    AssociatedDevices.AddRange(node.AssociatedDevices);
                }
            }

            lock (BindingTable)
            {
                if (!BindingTable.Equals(node.BindingTable))
                {
                    updated = true;
                    BindingTable.Clear();
                    BindingTable.AddRange(node.BindingTable);
                }
            }

            lock (Neighbors)
            {
                if (!Neighbors.Equals(node.Neighbors))
                {
                    updated = true;
                    Neighbors.Clear();
                    Neighbors.AddRange(node.Neighbors);
                }
            }

            lock (Routes)
            {
                if (!Routes.Equals(node.Routes))
                {
                    updated = true;
                    Routes.Clear();
                    Routes.AddRange(node.Routes);
                }
            }

            // TODO: How to deal with endpoints

            return(updated);
        }
Пример #3
0
        /// <summary>
        /// Updates the node. This will copy data from another node into this node. Updated elements are checked for equality
        /// and the method will only return true if the node data has been changed.
        ///
        /// <param name="node">the <see cref="ZigBeeNode"> that contains the newer node data.</param>
        /// <returns>true if there were changes made as a result of the update</returns>
        /// </summary>
        public bool UpdateNode(ZigBeeNode node)
        {
            if (!node.IeeeAddress.Equals(IeeeAddress))
            {
                Log.Debug("{IeeeAddress}: Ieee address inconsistent during update <>{NodeIeeeAddress}", IeeeAddress, node.IeeeAddress);
                return(false);
            }

            bool updated = false;

            if (NetworkAddress != 0 && !NetworkAddress.Equals(node.NetworkAddress))
            {
                Log.Debug("{IeeeAddress}: Network address updated from {NetworkAddress} to {NodeNetworkAddress}", IeeeAddress, NetworkAddress, node.NetworkAddress);
                updated        = true;
                NetworkAddress = node.NetworkAddress;
            }

            if (node.NodeDescriptor != null && (NodeDescriptor == null || !NodeDescriptor.Equals(node.NodeDescriptor)))
            {
                Log.Debug("{IeeeAddress}: Node descriptor updated", IeeeAddress);
                updated        = true;
                NodeDescriptor = node.NodeDescriptor;
            }

            if (node.PowerDescriptor != null && (PowerDescriptor == null || !PowerDescriptor.Equals(node.PowerDescriptor)))
            {
                Log.Debug("{IeeeAddress}: Power descriptor updated", IeeeAddress);
                updated         = true;
                PowerDescriptor = node.PowerDescriptor;
            }

            lock (_associatedDevices)
            {
                if (!_associatedDevices.SetEquals(node._associatedDevices))
                {
                    Log.Debug("{IeeeAddress}: Associated devices updated", IeeeAddress);
                    updated = true;
                    _associatedDevices.Clear();
                    _associatedDevices.UnionWith(node._associatedDevices);
                }
            }

            lock (_bindingTable)
            {
                if (!_bindingTable.SetEquals(node._bindingTable))
                {
                    Log.Debug("{IeeeAddress}: Binding table updated", IeeeAddress);
                    updated = true;
                    _bindingTable.Clear();
                    _bindingTable.UnionWith(node._bindingTable);
                }
            }

            lock (_neighbors)
            {
                if (!_neighbors.SetEquals(node._neighbors))
                {
                    Log.Debug("{IeeeAddress}: Neighbors updated", IeeeAddress);
                    updated = true;
                    _neighbors.Clear();
                    _neighbors.UnionWith(node._neighbors);
                }
            }

            lock (_routes)
            {
                if (!_routes.SetEquals(node._routes))
                {
                    Log.Debug("{IeeeAddress}: Routes updated", IeeeAddress);
                    updated = true;
                    _routes.Clear();
                    _routes.UnionWith(node._routes);
                }
            }

            // Endpoints are only copied over if they don't exist in the node
            // The assumption here is that endpoints are only set once, and not changed.
            // This should be valid as they are set through the SimpleDescriptor.
            foreach (var endpoint in node._endpoints)
            {
                if (_endpoints.ContainsKey(endpoint.Key))
                {
                    continue;
                }
                Log.Debug("{IeeeAddress}: Endpoint {EndpointId} added", IeeeAddress, endpoint.Key);
                updated = true;
                _endpoints[endpoint.Key] = endpoint.Value;
            }

            return(updated);
        }