Ejemplo n.º 1
0
        private async void _loadProjects_Click(object sender, EventArgs e)
        {
            if (LoadProjectsEnabled())
            {
                var url = _serverUrl.Text;
                if (_factories.SelectedItem is IDevOpsConnectorFactory factory && !string.IsNullOrWhiteSpace(url))
                {
                    if (_connector?.IsConnected() ?? false)
                    {
                        _connector.Disconnect();
                    }

                    _connector = factory.Create();
                    _connector.Connect(url, _accessToken.Text);
                    var projects = (await _connector.GetProjectsAsync())?.ToArray();
                    if (projects?.Any() ?? false)
                    {
                        _tokenManager.SetSecret(_serverUrl.Text, _accessToken.Text);
                        _projectList.Items.Clear();
                        _projectList.Items.AddRange(projects);

                        if (!string.IsNullOrWhiteSpace(_projectName))
                        {
                            var index = _projectList.FindStringExact(_projectName);
                            if (index >= 0)
                            {
                                _projectList.SelectedIndex = index;
                            }
                        }
                    }
                    else
                    {
                        _connector.Disconnect();
                        MessageBox.Show(this, "No Project has been found.", "Error", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                }
            }
        }