예제 #1
0
        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();
            }));
        }