private void AddOrUpdateFromTextBoxes() { if (ValidateServerBox()) { string name = txtName.Text.Trim(); string host = txtServer.Text.Trim(); var entry = FindMatchingEntry(txtServer.Text); if (entry == null) { entry = new AddressBookEntry(host, name); Entries.Add(entry); } else entry.Name = name; listView.Items.Refresh(); listView.ScrollIntoView(entry); listView.SelectedItem = entry; txtName.Text = txtServer.Text = string.Empty; } }
private static void LoadSettings() { var settings = Settings.Container; Entries.Clear(); var items = settings.AddressBook; if (items != null) { foreach (var item in items) { var parts = item.Split(new char[] { ';' }, StringSplitOptions.None); if (parts.Length >= 2) { var name = string.Join(";", parts.Take(parts.Length - 1)); var address = parts.Last(); string password = null; if(address.Contains("@")) { var addrParts = address.Split('@'); password = addrParts[0]; address = addrParts[1]; } try { var entry = new AddressBookEntry(address, name, password); Entries.Add(entry); } catch (ArgumentException) { } } } } else Entries.Add(new AddressBookEntry(IpAndPortString: "127.0.0.1:5150", name: "Localhost")); }