private async Task UpdateConnectionAsync()
        {
            ISonarQubeService sonarQubeService = this.extensionHost.SonarQubeService;

            if (sonarQubeService.IsConnected)
            {
                if (this.extensionHost.ActiveSection?.DisconnectCommand.CanExecute(null) == true)
                {
                    this.extensionHost.ActiveSection.DisconnectCommand.Execute(null);
                }
                else
                {
                    sonarQubeService.Disconnect();
                }
            }

            Debug.Assert(!sonarQubeService.IsConnected,
                         "SonarQube service should always be disconnected at this point");

            var boundProject = this.configurationProvider.GetConfiguration().Project;

            if (boundProject != null)
            {
                var connectionInformation = boundProject.CreateConnectionInformation();
                await WebServiceHelper.SafeServiceCallAsync(() => sonarQubeService.ConnectAsync(connectionInformation,
                                                                                                CancellationToken.None), this.logger);
            }

            Debug.Assert((boundProject != null) == sonarQubeService.IsConnected,
                         $"Inconsistent connection state: Solution bound={boundProject != null}, service connected={sonarQubeService.IsConnected}");
        }
        private async Task UpdateConnection()
        {
            ISonarQubeService sonarQubeService = this.extensionHost.SonarQubeService;

            if (sonarQubeService.IsConnected)
            {
                if (this.extensionHost.ActiveSection?.DisconnectCommand.CanExecute(null) == true)
                {
                    this.extensionHost.ActiveSection.DisconnectCommand.Execute(null);
                }
                else
                {
                    sonarQubeService.Disconnect();
                }
            }

            Debug.Assert(!sonarQubeService.IsConnected,
                         "SonarQube service should always be disconnected at this point");

            bool isSolutionCurrentlyBound = this.solutionBindingInformationProvider.IsSolutionBound();

            if (isSolutionCurrentlyBound)
            {
                var connectionInformation = GetConnectionInformation();
                await SafeServiceCall(async() =>
                                      await sonarQubeService.ConnectAsync(connectionInformation, CancellationToken.None));
            }

            Debug.Assert(isSolutionCurrentlyBound == sonarQubeService.IsConnected,
                         $"Inconsistent connection state: Solution bound={isSolutionCurrentlyBound}, service connected={sonarQubeService.IsConnected}");
        }
示例#3
0
        private async Task UpdateConnection()
        {
            ISonarQubeService sqService = this.extensionHost.SonarQubeService;

            if (sqService.IsConnected)
            {
                sqService.Disconnect();

                if (this.extensionHost.ActiveSection?.DisconnectCommand.CanExecute(null) == true)
                {
                    this.extensionHost.ActiveSection.DisconnectCommand.Execute(null);
                }
            }

            bool isSolutionCurrentlyBound = this.solutionBindingInformationProvider.IsSolutionBound();

            if (isSolutionCurrentlyBound)
            {
                var solutionBinding = this.extensionHost.GetService <ISolutionBindingSerializer>();
                solutionBinding.AssertLocalServiceIsNotNull();
                BoundSonarQubeProject boundProject = solutionBinding.ReadSolutionBinding();
                var connectionInformation          = boundProject.CreateConnectionInformation();

                // TODO: handle connection failure
                // TODO: block until the connection is complete
                await this.extensionHost.SonarQubeService.ConnectAsync(connectionInformation, CancellationToken.None);
            }
        }