示例#1
0
        private void commitService( bool modify )
        {
            if (portsAndProtoListView.Items.Count == 0) return; // Not interested

            var service = new Service(serviceNameBox.Text);
            foreach (ListViewItem item in portsAndProtoListView.Items)
            {
                PortRange port_range = new PortRange();
                var ret = port_range.parseRange(item.Text);
                Debug.Assert(ret); // We should have already validated this

                Protocols protocols;
                switch (item.SubItems[1].Text)
                {
                    case "TCP":
                        protocols = Protocols.TCP;
                        break;

                    case "UDP":
                        protocols = Protocols.UDP;
                        break;

                    case "Both":
                        protocols = Protocols.BOTH;
                        break;

                    default:
                        protocols = Protocols.TCP; // Just to make the compiler happy
                        Debug.Assert(false, "Bad case!");
                        break;
                }

                port_range.protocols = protocols;

                service.port_ranges.Add( port_range );
            }

            var bs = (BindingSource)servicesListBox.DataSource;
            bs.Add(service);
            if (modify)
            {
                bs.RemoveCurrent();
            }

            _services.Sort();
            refreshServices(); // Reordered, need to refresh
            servicesListBox.SelectedItem = service;
        }