public async Task ConnectAsync(ConnectionInformation connection, CancellationToken token) { if (this.sonarqubeClient != null) { throw new InvalidOperationException("This operation expects the service not to be connected."); } var connectionRequest = new ConnectionRequest { Authentication = connection.Authentication, ServerUri = connection.ServerUri, Login = connection.UserName, Password = connection.Password }; var client = this.sonarqubeClientFactory.Create(connectionRequest); var credentialsValidationResult = await client.ValidateCredentialsAsync(token); credentialsValidationResult.EnsureSuccess(); if (!credentialsValidationResult.Value.IsValid) { throw new Exception("Invalid credentials."); // TODO: Provide better exception } var versionResult = await client.GetVersionAsync(token); versionResult.EnsureSuccess(); this.serverVersion = Version.Parse(versionResult.Value.Version); this.sonarqubeClient = client; this.connection = connection; }
/// <summary> /// Navigates to the project view page. /// </summary> /// <param name="client">Client for the SonarQube API.</param> private void NavigateToProjectPage(ISonarQubeClient client) { _teamExplorer.NavigateToPage(new Guid(SonarLinkProjectPage.PageId), new SonarLinkProjectPage.PageContext() { Client = client, Filter = string.Empty }); }
/// <summary> /// Handler which attempts to sign in to a SonarQube server. /// </summary> private async Task OnSignInAsync(object parameter) { var connectionInfo = ConnectionInformationDialog.ShowDialog(_lastAttemptedSignIn); if (connectionInfo is null) { return; } _lastAttemptedSignIn = connectionInfo; ISonarQubeClient client = null; IsSignedIn = false; IsSigningIn = true; try { client = await _clientManager.LogInAsync(new Uri(connectionInfo.ServerUrl), connectionInfo.Login, connectionInfo.Password); IsSignedIn = (null != client); } catch { IsSignedIn = false; } IsSigningIn = false; if (IsSignedIn) { _teamExplorer.HideNotification(ConnectionNotificationId); NavigateToProjectPage(client); } else { _teamExplorer.ShowNotification($"Could not connect to \"{connectionInfo.ServerUrl}\".", NotificationType.Error, NotificationFlags.None, null, ConnectionNotificationId); } }
/// <summary> /// Constructor /// </summary> /// <param name="service">SonarQube server</param> public ErrorListProvider(ISonarQubeClient client) { _client = client; }
public void Disconnect() { (this.sonarqubeClient as IDisposable)?.Dispose(); this.sonarqubeClient = null; this.serverVersion = null; }