public void AddOrUpdateNode(Node node)
        {
            Node oldNode = conn.Query<Node>("select * from Node where nodeId = ?", node.nodeId).FirstOrDefault();

            if (oldNode != null)
                conn.UpdateWithChildren(node);
            else
                conn.InsertWithChildren(node);
        }
 private void UpdateNode(Node node)
 {
     ShowNodes();
 }
 private void AddNode(Node node)
 {
     listView1.Items.Add(node.ToString());
 }
 public void AddNode(Node node)
 {
     nodes.Add(node);
 }
 private void OnNodeUpdated(Node node)
 {
     if (!updatedNodesId.Contains(node.nodeId))
         updatedNodesId.Add(node.nodeId);
 }
 private void UpdateNode(Node node)
 {
     StackPanel panel = GetNodePanel(node.nodeId);
     UpdateNodePanel(node, panel);
 }
        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);
            }

            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);
                }
                else if (mes.messageType == MessageType.C_INTERNAL)
                {
                    if (mes.subType == (int)InternalDataType.I_SKETCH_NAME)
                    {
                        node.name = mes.payload;

                        if (OnNodeUpdatedEvent != null)
                            OnNodeUpdatedEvent(node);
                    }
                    else if (mes.subType == (int)InternalDataType.I_SKETCH_VERSION)
                    {
                        node.version = mes.payload;

                        if (OnNodeUpdatedEvent != null)
                            OnNodeUpdatedEvent(node);
                    }
                    else if (mes.subType == (int)InternalDataType.I_BATTERY_LEVEL)
                    {
                        node.batteryLevel = Int32.Parse(mes.payload);
                        if (OnNodeBatteryUpdatedEvent != null)
                            OnNodeBatteryUpdatedEvent(node);
                        return;
                    }
                }
            }

        }
        private Grid CreateNodeTitle(Node node)
        {
            Grid grid = new Grid
            {
                VerticalAlignment = VerticalAlignment.Stretch,
                HorizontalAlignment = HorizontalAlignment.Stretch
            };

            SymbolIcon activityIcon = new SymbolIcon
            {
                Symbol = Symbol.Remove,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Center,
                Margin = new Thickness(5),
                Foreground = new SolidColorBrush(Color.FromArgb(255, 220, 220, 220)),
                Tag = node.nodeId
            };
            activityIcons.Add(activityIcon);
            grid.Children.Add(activityIcon);

     /*       Button button = new Button
            {
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment = VerticalAlignment.Center,
                Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)),
                Content = new SymbolIcon { Symbol = Symbol.More },
                Height = 30
                // Margin = new Thickness(5)
            };

            button.Tag = node.nodeId;
            button.Click += buttonNodeMenu_Click;
*/



            /*
             MenuFlyout menu = new MenuFlyout();
             MenuFlyoutItem item1 = new MenuFlyoutItem {Text = "Reboot Node"};
             item1.Click += buttonNodeMenu_Click;
             menu.Items.Add(item1);
             menu.Items[0].Tag = node.nodeId;

             menu.Items.Add(new MenuFlyoutItem { Text = "Delete Node" });
             MenuFlyoutItem n=new MenuFlyoutItem();
             button.Flyout = menu;
             */



            grid.Children.Add(new TextBlock
            {
                Text = "Node " + node.nodeId,
                Margin = new Thickness(5, 5, 5, 5),
                FontWeight = FontWeights.SemiBold,
                HorizontalAlignment = HorizontalAlignment.Center,

            });


          //  grid.Children.Add(button);


            return grid;
        }
        private void AddNode(Node node)
        {
            StackPanel oldPanel = GetNodePanel(node.nodeId);
            if (oldPanel != null)
                nodePanels.Remove(oldPanel);

            StackPanel nodePanel = CreateNodePanel(node);
            itemsControl1.Items.Add(nodePanel);
            nodePanels.Add(nodePanel);
        }
        private void UpdateNodePanel(Node node, StackPanel nodePanel)
        {
            nodePanel.Children.Clear();

            StackPanel titlePanel = new StackPanel()
            {
                Background = new SolidColorBrush(Colors.Gainsboro),
                Height = 30
            };

            Grid titleGrid = CreateNodeTitle(node);
            titlePanel.Children.Add(titleGrid);

            nodePanel.Children.Add(titlePanel);

            if (node.name != null)
                nodePanel.Children.Add(new TextBlock { Text = node.name, Margin = new Thickness(5) });

            foreach (Sensor sensor in node.sensors)
            {
                StackPanel oldPanel = GetSensorPanel(node.nodeId, sensor.sensorId);
                if (oldPanel != null)
                    sensorPanels.Remove(oldPanel);

                StackPanel sensorPanel = CreateSensorPanel(sensor);
                nodePanel.Children.Add(sensorPanel);
                sensorPanels.Add(sensorPanel);
            }

            if (node.batteryLevel != null)
            {
                TextBlock oldPanel = GetBatteryPanel(node.nodeId);
                if (oldPanel != null)
                    batteryPanels.Remove(oldPanel);

                TextBlock text = CreateBatteryPanel(node);
                nodePanel.Children.Add(text);
                batteryPanels.Add(text);
            }
        }
 private TextBlock CreateBatteryPanel(Node node)
 {
     TextBlock text = new TextBlock
     {
         Text = "Battery " + node.batteryLevel.Value,
         Margin = new Thickness(5),
         Foreground = new SolidColorBrush(Colors.Gray),
         Tag = node.nodeId
     };
     return text;
 }
        private StackPanel CreateNodePanel(Node node)
        {
            StackPanel nodePanel = new StackPanel
            {
                MinWidth = 200,
                Orientation = Orientation.Vertical,
                Margin = new Thickness(10),
                BorderThickness = new Thickness(1),
                BorderBrush = new SolidColorBrush(Colors.Black),
                Tag = node.nodeId
            };

            UpdateNodePanel(node, nodePanel);

            return nodePanel;

        }
        private void UpdateBattery(Node node)
        {
            TextBlock text = GetBatteryPanel(node.nodeId);
            if (text == null)
            {
                TextBlock oldPanel = GetBatteryPanel(node.nodeId);
                if (oldPanel != null)
                    batteryPanels.Remove(oldPanel);

                text = CreateBatteryPanel(node);
                StackPanel nodePanel = GetNodePanel(node.nodeId);
                nodePanel.Children.Add(text);
                batteryPanels.Add(text);
            }

            text.Text = "Battery " + node.batteryLevel.Value;
        }
 public Sensor(int sensorId, Node ownerNode)
 {
     this.sensorId = sensorId;
     this.ownerNodeId = ownerNode.nodeId;
     sensorData = new List<SensorData>();
 }
        private StackPanel CreateNode(Node node)
        {
            StackPanel nodePanel = new StackPanel();
            nodePanel.Orientation = Orientation.Vertical;
            nodePanel.Margin = new Thickness(5);
            nodePanel.BorderThickness = new Thickness(1);
            nodePanel.BorderBrush = new SolidColorBrush(Colors.Black);
            nodePanel.Background = new SolidColorBrush(Colors.Gray);

            StackPanel titlePanel = new StackPanel();
            titlePanel.Background = new SolidColorBrush(Colors.Gainsboro);
            titlePanel.Height = 30;

            titlePanel.Children.Add(new TextBlock { Text = "Node id: " + node.nodeId, Margin = new Thickness(5), FontWeight = FontWeights.SemiBold });

            nodePanel.Children.Add(titlePanel);

            if (node.name != null)
                nodePanel.Children.Add(new TextBlock { Text = node.name, Margin = new Thickness(5), Foreground = new SolidColorBrush(Colors.Gainsboro) });

            if (node.version != null)
                nodePanel.Children.Add(new TextBlock { Text = "Version: " + node.version, Margin = new Thickness(5), Foreground = new SolidColorBrush(Colors.Gainsboro) });

            nodePanel.Children.Add(new TextBlock { Text = "Registered: " + node.registered, Margin = new Thickness(5), Foreground = new SolidColorBrush(Colors.Gainsboro) });

            string lastSeenAgo = string.Format("{0:hh\\:mm\\:ss}",  DateTime.Now.Subtract(node.lastSeen));
            nodePanel.Children.Add(new TextBlock { Text = "Last seen: " + lastSeenAgo+" ago", Margin = new Thickness(5), Foreground = new SolidColorBrush(Colors.Gainsboro) });

            if (node.isRepeatingNode == null)
                nodePanel.Children.Add(new TextBlock
                {
                    Text = "Repeating: Unknown",
                    Margin = new Thickness(5),
                    Foreground = new SolidColorBrush(Colors.Gainsboro)
                });
            else if (node.isRepeatingNode.Value)
                nodePanel.Children.Add(new TextBlock
                {
                    Text = "Repeating: Yes",
                    Margin = new Thickness(5),
                    Foreground = new SolidColorBrush(Colors.Gainsboro)
                });
            else
                nodePanel.Children.Add(new TextBlock
                {
                    Text = "Repeating: No",
                    Margin = new Thickness(5),
                    Foreground = new SolidColorBrush(Colors.Gainsboro)
                });

            if (node.batteryLevel != null)
                nodePanel.Children.Add(new TextBlock { Text = "Battery: " + node.batteryLevel.Value, Margin = new Thickness(5), Foreground = new SolidColorBrush(Colors.Gainsboro) });

            foreach (Sensor sensor in node.sensors)
            {
                StackPanel sensorPanel = CreateSensor(sensor);
                nodePanel.Children.Add(sensorPanel);
            }
            return nodePanel;
        }
        private void AddNode(Node node)
        {
            StackPanel nodePanel = CreateNode(node);

            itemsControl1.Items.Add(nodePanel);
        }