private void addListenerButton_Click(object sender, RoutedEventArgs e) { try { ListView listView = this.listenerListView; ListenerSettings[] items = listView.Items.Cast <ListenerSettings>().ToArray(); // create a new ListenerSettings ListenerSettings newItem = ListenerSettings.CreateDefaultListenerSettings(items); // prepare a validator Func <ListenerSettings, string> validator = (s) => { // check whether there is no listener which has the same end point ListenerSettings conflicting = items.Where(item => s.HasSameEndPointTo(item)).FirstOrDefault(); return((conflicting == null) ? null : string.Format(Properties.Resources.SettingsWindow_Message_ConflictingListener, s.GetEndPoint())); }; // edit the ListenerSettings ListenerDialog dialog = new ListenerDialog(newItem, validator); dialog.Owner = this; if (dialog.ShowDialog() ?? false) { // add the ListenerSettings AddListItem(listView, dialog.ListenerSettings); } } catch (Exception exception) { ShowErrorDialog(exception.Message); } return; }
private void editListenerButton_Click(object sender, RoutedEventArgs e) { try { ListView listView = this.listenerListView; // edit the selected ListenerSettings ListenerSettings originalItem = listView.SelectedItem as ListenerSettings; if (originalItem == null) { // this item is not editable return; } // create a clone of the selected ListenerSettings ListenerSettings newItem = ListenerSettings.Clone(originalItem); // prepare a validator ListenerSettings[] items = listView.Items.Cast <ListenerSettings>().ToArray(); Func <ListenerSettings, string> validator = (s) => { // check there is no credential which has the same end point ListenerSettings conflicting = items.Where(item => (item != originalItem && s.HasSameEndPointTo(item))).FirstOrDefault(); return((conflicting == null)? null: string.Format(Properties.Resources.SettingsWindow_Message_ConflictingListener, s.GetEndPoint())); }; // edit the clone ListenerDialog dialog = new ListenerDialog(newItem, validator); dialog.Owner = this; if (dialog.ShowDialog() ?? false) { ReplaceSelectedListItemWith(listView, dialog.ListenerSettings); } } catch (Exception exception) { ShowErrorDialog(exception.Message); } return; }