private void MenuItem_SockEdit_Click(object sender, RoutedEventArgs e) { SockUnit sock = treeSock.SelectedItem as SockUnit; if (sock == null || sock.State != SockState.Closed) { return; } using (SockInputDialog input = new SockInputDialog()) { input.Owner = this; input.Title = "Edit"; input.textBoxID.Text = sock.ID; input.textBoxName.Text = sock.Name; if (sock.Type == SockType.listen) { input.textBoxEP.Text = sock.Lep.ToString(); input.radioButtonListen.IsChecked = true; } else { input.textBoxEP.Text = sock.Rep.ToString(); input.radioButtonConnect.IsChecked = true; } input.checkBoxAutorun.IsChecked = sock.Autorun; input.textBoxEP.Focus(); input.textBoxEP.SelectionStart = input.textBoxEP.Text.Length; if (input.ShowDialog() == false) { return; } sock.ID = input.textBoxID.Text; sock.Name = input.textBoxName.Text; string[] str = input.textBoxEP.Text.Split(':'); if (str.Count() != 2) { return; } if (input.radioButtonListen.IsChecked == true) { sock.Type = SockType.listen; sock.Lep = new IPEndPoint(IPAddress.Parse(str[0]), int.Parse(str[1])); } else { sock.Type = SockType.connect; var host = Dns.GetHostEntry(str[0]); sock.Rep = new IPEndPoint(host.AddressList[0], int.Parse(str[1])); } sock.Autorun = (bool)input.checkBoxAutorun.IsChecked; sock.UpdateTitle(); } }
private void MenuItem_SockAdd_Click(object sender, RoutedEventArgs e) { using (SockInputDialog input = new SockInputDialog()) { input.Owner = this; input.Title = "Add"; input.textBoxID.Focus(); if (input.ShowDialog() == false) { return; } SockUnit sock = new SockUnit(); sock.ID = input.textBoxID.Text; sock.Name = input.textBoxName.Text; string[] str = input.textBoxEP.Text.Split(':'); if (str.Count() != 2) { return; } if (input.radioButtonListen.IsChecked == true) { sock.Type = SockType.listen; sock.Lep = new IPEndPoint(IPAddress.Parse(str[0]), int.Parse(str[1])); } else { sock.Type = SockType.connect; sock.Rep = new IPEndPoint(IPAddress.Parse(str[0]), int.Parse(str[1])); } sock.Autorun = (bool)input.checkBoxAutorun.IsChecked; sock.UpdateTitle(); (treeSock.ItemsSource as ObservableCollection <SockUnit>).Add(sock); } }