async private void ButtonAddKnownHost_Click(object sender, EventArgs e) { using (AddKnownHostForm form = new AddKnownHostForm()) { if (form.ShowDialog() == DialogResult.OK) { if (!onAddKnownHost(form.Host, form.AccessToken)) { MessageBox.Show("Such host is already in the list", "Host will not be added", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } _settings.KnownHosts = listViewKnownHosts.Items.Cast <ListViewItem>().Select(i => i.Text).ToList(); _settings.KnownAccessTokens = listViewKnownHosts.Items.Cast <ListViewItem>() .Select(i => i.SubItems[1].Text).ToList(); await changeHostAsync(getInitialHostName()); } } }
private void launchAddKnownHostDialog() { AddKnownHostForm form = new AddKnownHostForm(); if (form.ShowDialog() != DialogResult.OK) { return; } BeginInvoke(new Action(async() => { string hostname = StringUtils.GetHostWithPrefix(form.Host); string accessToken = form.AccessToken; ConnectionCheckStatus status = await ConnectionChecker.CheckConnectionAsync(hostname, accessToken); if (status != ConnectionCheckStatus.OK) { string message = status == ConnectionCheckStatus.BadAccessToken ? "Bad access token" : "Invalid hostname"; MessageBox.Show(message, "Cannot connect to the host", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!addKnownHost(hostname, accessToken)) { MessageBox.Show("Such host is already in the list", "Host will not be added", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } updateKnownHostAndTokensInSettings(); updateHostsDropdownList(); selectHost(PreferredSelection.Latest); reconnect(); })); }