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