Ejemplo n.º 1
0
        private void onTimer(object sender, ElapsedEventArgs e)
        {
            _synchronizeInvoke.BeginInvoke(new Action(async() =>
            {
                if (isConnected() || _checking)
                {
                    return;
                }

                _checking = true;
                try
                {
                    string token = HostProperties.GetAccessToken(HostName);
                    ConnectionCheckStatus result = await ConnectionChecker.CheckConnectionAsync(HostName, token);
                    if (!isConnected() && result == ConnectionCheckStatus.OK)
                    {
                        // isConnected() check is needed because connection has been probably already restored
                        // while we awaited for a CheckConnectionAsync() result
                        Trace.TraceInformation("[GitLabInstance] ConnectionChecker.CheckConnection() returned OK");
                        onConnectionRestored();
                    }
                }
                finally
                {
                    _checking = false;
                }
            }), null);
        }
Ejemplo n.º 2
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();
            }));
        }