private void CurrentErrorWindowInfoBar_ButtonClick(object sender, EventArgs e) { if (this.currentErrorWindowInfoBarHandlingClick) { // Info bar doesn't expose a way to disable the command // and since the code is asynchronous the user can click // on the button multiple times and get multiple binds return; } // Don't log unprocessed events var componentModel = host.GetService <SComponentModel, IComponentModel>(); TelemetryLoggerAccessor.GetLogger(componentModel)?.ReportEvent(TelemetryEvent.ErrorListInfoBarUpdateCalled); BindingConfiguration binding = configProvider.GetConfiguration(); if (binding == null || binding.Mode != SonarLintMode.LegacyConnected || this.infoBarBinding == null || binding.Project.ServerUri != this.infoBarBinding.ServerUri || !SonarQubeProject.KeyComparer.Equals(binding.Project.ProjectKey, this.infoBarBinding.ProjectKey)) { // Not bound anymore, or bound to something else entirely this.ClearCurrentInfoBar(); this.OutputMessage(Strings.SonarLintInfoBarUpdateCommandInvalidSolutionBindings); } else { // Prevent click handling this.currentErrorWindowInfoBarHandlingClick = true; this.ExecuteUpdate(binding.Project); } }
private void CurrentErrorWindowInfoBar_ButtonClick(object sender, EventArgs e) { if (this.currentErrorWindowInfoBarHandlingClick) { // Info bar doesn't expose a way to disable the command // and since the code is asynchronous the user can click // on the button multiple times and get multiple binds return; } // Don't log unprocessed events TelemetryLoggerAccessor.GetLogger(this.host)?.ReportEvent(TelemetryEvent.ErrorListInfoBarUpdateCalled); var bindingSerialzer = this.host.GetService <ISolutionBindingSerializer>(); bindingSerialzer.AssertLocalServiceIsNotNull(); BoundSonarQubeProject binding = bindingSerialzer.ReadSolutionBinding(); if (binding == null || this.infoBarBinding == null || binding.ServerUri != this.infoBarBinding.ServerUri || !ProjectInformation.KeyComparer.Equals(binding.ProjectKey, this.infoBarBinding.ProjectKey)) { // Not bound anymore, or bound to something else entirely this.ClearCurrentInfoBar(); this.OutputMessage(Strings.SonarLintInfoBarUpdateCommandInvalidSolutionBindings); } else { // Prevent click handling this.currentErrorWindowInfoBarHandlingClick = true; this.ExecuteUpdate(binding); } }
/// <summary> /// Update /// </summary> /// <param name="customInfoBarMessage">Optional. If provided than this will be the message that will appear in info bar, otherwise a standard one will appear instead</param> private void UpdateRequired(string customInfoBarMessage = null) { this.AssertOnUIThread(); IInfoBarManager manager = this.host.GetMefService <IInfoBarManager>(); if (manager == null) { Debug.Fail("Cannot find IInfoBarManager"); return; } this.currentErrorWindowInfoBar = manager.AttachInfoBarWithButton( ErrorListToolWindowGuid, customInfoBarMessage ?? Strings.SonarLintInfoBarUnboundProjectsMessage, Strings.SonarLintInfoBarUpdateCommandText, KnownMonikers.RuleWarning); if (this.currentErrorWindowInfoBar == null) { this.OutputMessage(Strings.SonarLintFailedToAttachInfoBarToErrorList); Debug.Fail("Failed to add an info bar to the error list tool window"); } else { var componentModel = host.GetService <SComponentModel, IComponentModel>(); TelemetryLoggerAccessor.GetLogger(componentModel)?.ReportEvent(TelemetryEvent.ErrorListInfoBarShow); this.currentErrorWindowInfoBar.Closed += this.CurrentErrorWindowInfoBar_Closed; this.currentErrorWindowInfoBar.ButtonClick += this.CurrentErrorWindowInfoBar_ButtonClick; // Need to capture the current binding information since the user can change the binding // and running the Update should just no-op in that case. this.infoBarBinding = configProvider.GetConfiguration().Project; } }