Exemple #1
0
        private void btnAddVLAN_Click(object sender, RoutedEventArgs e)
        {
            var wnd = new AddVLANDialogWindow();

            wnd.Owner = this;

            if (wnd.ShowDialog() == true)
            {
                string VLAN_IdsStr = (wnd.VLAN_IdsStr ?? string.Empty).Trim();

                var nodeIds = VLAN_IdsStr
                              .Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                              .Select(p =>
                {
                    int id = 0;
                    return(int.TryParse(p, out id) ? id : 0);
                })
                              .Where(p => p > 0)
                              .Distinct()
                              .OrderBy(p => p)
                              .ToList();

                if (nodeIds.Count > 2 && nodeIds.All(id => _nodes.Any(node => node.NodeId == id)))
                {
                    var vlan = new VLAN
                    {
                        Color = GetRandomColor()
                    };
                    vlan.NodeIds.AddRange(nodeIds);
                    _vlans.Add(vlan);
                }
                else
                {
                    MessageBox.Show("Not valid node identifiers", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
            }
            ;
        }
        private void btnAddVLAN_Click(object sender, RoutedEventArgs e)
        {
            var wnd = new AddVLANDialogWindow();
            wnd.Owner = this;

            if (wnd.ShowDialog() == true)
            {
                string VLAN_IdsStr = (wnd.VLAN_IdsStr ?? string.Empty).Trim();

                var nodeIds = VLAN_IdsStr
                    .Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                    .Select(p =>
                    {
                        int id = 0;
                        return int.TryParse(p, out id) ? id : 0;
                    })
                    .Where(p => p > 0)
                    .Distinct()
                    .OrderBy(p => p)
                    .ToList();

                if (nodeIds.Count > 2 && nodeIds.All(id => _nodes.Any(node => node.NodeId == id)))
                {
                    var vlan = new VLAN
                    {
                        Color = GetRandomColor()
                    };
                    vlan.NodeIds.AddRange(nodeIds);
                    _vlans.Add(vlan);
                }
                else
                {
                    MessageBox.Show("Not valid node identifiers", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
            };
        }