public void AddOrUpdateNode(Node node) { // Node oldNode = db.Nodes.FirstOrDefault(x => x.nodeId == node.nodeId); if (db.Nodes.Any(x => x.nodeId == node.nodeId)) { db.Entry(node).State = EntityState.Modified; } else { db.Nodes.Add(node); } db.SaveChanges(); }
public void OnNodeUpdatedEvent(Node node) { Clients.Others.onNodeUpdatedEvent(node); }
public void OnNewNodeEvent(Node node) { Clients.Others.onNewNodeEvent(node); }
public Sensor(int sensorId, Node ownerNode) { this.sensorId = sensorId; this.ownerNodeId = ownerNode.nodeId; }
public void AddNode(Node node) { nodes.Add(node); }
private void UpdateNodeFromMessage(Message mes) { Node node = GetNode(mes.nodeId); if (node == null) { node = new Node(mes.nodeId); nodes.Add(node); if (OnNewNodeEvent != null) OnNewNodeEvent(node); DebugGatewayState(String.Format("New node (id: {0}) registered", node.nodeId)); } node.UpdateLastSeenNow(); if (OnNodeLastSeenUpdatedEvent != null) OnNodeLastSeenUpdatedEvent(node); if (mes.sensorId == 255) { if (mes.messageType == MessageType.C_PRESENTATION) { if (mes.subType == (int)SensorType.S_ARDUINO_NODE) { node.isRepeatingNode = false; } else if (mes.subType == (int)SensorType.S_ARDUINO_REPEATER_NODE) { node.isRepeatingNode = true; } if (OnNodeUpdatedEvent != null) OnNodeUpdatedEvent(node); DebugGatewayState(String.Format("Node {0} updated", node.nodeId)); } else if (mes.messageType == MessageType.C_INTERNAL) { if (mes.subType == (int)InternalDataType.I_SKETCH_NAME) { node.name = mes.payload; if (OnNodeUpdatedEvent != null) OnNodeUpdatedEvent(node); DebugGatewayState(String.Format("Node {0} updated", node.nodeId)); } else if (mes.subType == (int)InternalDataType.I_SKETCH_VERSION) { node.version = mes.payload; if (OnNodeUpdatedEvent != null) OnNodeUpdatedEvent(node); DebugGatewayState(String.Format("Node {0} updated", node.nodeId)); } else if (mes.subType == (int)InternalDataType.I_BATTERY_LEVEL) { node.batteryLevel = Int32.Parse(mes.payload); if (OnNodeBatteryUpdatedEvent != null) OnNodeBatteryUpdatedEvent(node); return; } } } }
private void OnNodeUpdated(Node node) { if (storeTimeInterval == 0) AddOrUpdateNode(node); else { if (!updatedNodesId.Contains(node.nodeId)) updatedNodesId.Add(node.nodeId); } }
private void OnNodeUpdatedEvent(Node node) { if (!IsConnected()) return; hubProxy.Invoke("OnNodeUpdatedEvent", node); }