Skip to content

Commit

Permalink
Manually cleanup code in touched files
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriela-trutan-sonarsource committed Jan 8, 2025
1 parent abb6fd9 commit 7c9a162
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 93 deletions.
8 changes: 3 additions & 5 deletions src/ConnectedMode.UnitTests/UI/ConnectedModeServicesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using SonarLint.VisualStudio.Core;
using SonarLint.VisualStudio.TestInfrastructure;
using SonarLint.VisualStudio.ConnectedMode.UI;
using SonarLint.VisualStudio.Core;
using SonarLint.VisualStudio.Core.Binding;
using SonarLint.VisualStudio.Core.Telemetry;
using SonarLint.VisualStudio.TestInfrastructure;

namespace SonarLint.VisualStudio.ConnectedMode.UnitTests.UI;

[TestClass]
public class ConnectedModeServicesTests
{
[TestMethod]
public void MefCtor_CheckIsExported()
{
public void MefCtor_CheckIsExported() =>
MefTestHelpers.CheckTypeCanBeImported<ConnectedModeServices, IConnectedModeServices>(
MefTestHelpers.CreateExport<IBrowserService>(),
MefTestHelpers.CreateExport<IThreadHandling>(),
Expand All @@ -41,5 +40,4 @@ public void MefCtor_CheckIsExported()
MefTestHelpers.CreateExport<IMessageBox>(),
MefTestHelpers.CreateExport<ITelemetryManager>(),
MefTestHelpers.CreateExport<ILogger>());
}
}
11 changes: 5 additions & 6 deletions src/ConnectedMode/UI/ConnectedModeServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/

using System.ComponentModel.Composition;
using SonarLint.VisualStudio.ConnectedMode.Shared;
using SonarLint.VisualStudio.Core;
using SonarLint.VisualStudio.Core.Binding;
using SonarLint.VisualStudio.Core.Telemetry;
Expand All @@ -28,11 +27,11 @@ namespace SonarLint.VisualStudio.ConnectedMode.UI;

public interface IConnectedModeServices
{
public IBrowserService BrowserService { get; }
public IThreadHandling ThreadHandling { get; }
public ILogger Logger { get; }
public ISlCoreConnectionAdapter SlCoreConnectionAdapter { get; }
public IConfigurationProvider ConfigurationProvider { get; }
public IBrowserService BrowserService { get; }
public IThreadHandling ThreadHandling { get; }
public ILogger Logger { get; }
public ISlCoreConnectionAdapter SlCoreConnectionAdapter { get; }
public IConfigurationProvider ConfigurationProvider { get; }
public IServerConnectionsRepositoryAdapter ServerConnectionsRepositoryAdapter { get; }
public IMessageBox MessageBox { get; }
public ITelemetryManager TelemetryManager { get; }
Expand Down
59 changes: 27 additions & 32 deletions src/ConnectedMode/UI/ServerSelection/ServerSelectionDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,35 @@
using System.Windows.Navigation;
using SonarLint.VisualStudio.Core;
using SonarLint.VisualStudio.Core.Telemetry;
using SonarLint.VisualStudio.Integration.Telemetry;

namespace SonarLint.VisualStudio.ConnectedMode.UI.ServerSelection
namespace SonarLint.VisualStudio.ConnectedMode.UI.ServerSelection;

[ExcludeFromCodeCoverage] // UI, not really unit-testable
public partial class ServerSelectionDialog : Window
{
[ExcludeFromCodeCoverage] // UI, not really unit-testable
public partial class ServerSelectionDialog : Window
private readonly IBrowserService browserService;
private readonly ITelemetryManager telemetryManager;

public ServerSelectionViewModel ViewModel { get; } = new();

public ServerSelectionDialog(IBrowserService browserService, ITelemetryManager telemetryManager)
{
this.browserService = browserService;
this.telemetryManager = telemetryManager;
InitializeComponent();
}

private void ViewWebsite(object sender, RequestNavigateEventArgs e) => browserService.Navigate(e.Uri.AbsoluteUri);

private void FreeSonaQubeCloudFreeTier_OnRequestNavigate(object sender, RequestNavigateEventArgs e)
{
ViewWebsite(sender, e);
telemetryManager.LinkClicked(TelemetryLinks.SonarQubeCloudFreeSignUp);
}

private void OkButton_OnClick(object sender, RoutedEventArgs e)
{
private readonly IBrowserService browserService;
private readonly ITelemetryManager telemetryManager;

public ServerSelectionDialog(IBrowserService browserService, ITelemetryManager telemetryManager)
{
this.browserService = browserService;
this.telemetryManager = telemetryManager;
InitializeComponent();
}

public ServerSelectionViewModel ViewModel { get; } = new();

private void ViewWebsite(object sender, RequestNavigateEventArgs e)
{
browserService.Navigate(e.Uri.AbsoluteUri);
}

private void FreeSonaQubeCloudFreeTier_OnRequestNavigate(object sender, RequestNavigateEventArgs e)
{
ViewWebsite(sender, e);
telemetryManager.LinkClicked(TelemetryLinks.SonarQubeCloudFreeSignUp);
}

private void OkButton_OnClick(object sender, RoutedEventArgs e)
{
DialogResult = true;
Close();
}
DialogResult = true;
Close();
}
}
27 changes: 16 additions & 11 deletions src/Core/Telemetry/ITelemetryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,21 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

namespace SonarLint.VisualStudio.Core.Telemetry
namespace SonarLint.VisualStudio.Core.Telemetry;

public interface ITelemetryManager
{
public interface ITelemetryManager
{
SlCoreTelemetryStatus GetStatus();
void OptOut();
void OptIn();
void LanguageAnalyzed(string languageKey, TimeSpan analysisTime);
void TaintIssueInvestigatedLocally();
void TaintIssueInvestigatedRemotely();
void LinkClicked(string linkId);
}
SlCoreTelemetryStatus GetStatus();

void OptOut();

void OptIn();

void LanguageAnalyzed(string languageKey, TimeSpan analysisTime);

void TaintIssueInvestigatedLocally();

void TaintIssueInvestigatedRemotely();

void LinkClicked(string linkId);
}
2 changes: 1 addition & 1 deletion src/Core/Telemetry/TelemetryLinks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

namespace SonarLint.VisualStudio.Integration.Telemetry;
namespace SonarLint.VisualStudio.Core.Telemetry;

public static class TelemetryLinks
{
Expand Down
51 changes: 13 additions & 38 deletions src/Integration/Telemetry/TelemetryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ internal sealed class TelemetryManager : ITelemetryManager,
IQuickFixesTelemetryManager,
IDisposable
{
private readonly ISlCoreTelemetryHelper telemetryHelper;
private readonly IKnownUIContexts knownUiContexts;
private readonly ISlCoreTelemetryHelper telemetryHelper;

[ImportingConstructor]
public TelemetryManager(ISlCoreTelemetryHelper telemetryHelper, IKnownUIContexts knownUIContexts)
Expand All @@ -46,26 +46,19 @@ public TelemetryManager(ISlCoreTelemetryHelper telemetryHelper, IKnownUIContexts
knownUiContexts.VBProjectContextChanged += OnVBProjectContextChanged;
}

public void QuickFixApplied(string ruleId)
public void Dispose()
{
telemetryHelper.Notify(telemetryService => telemetryService.AddQuickFixAppliedForRule(new AddQuickFixAppliedForRuleParams(ruleId)));
knownUiContexts.CSharpProjectContextChanged -= OnCSharpProjectContextChanged;
knownUiContexts.VBProjectContextChanged -= OnVBProjectContextChanged;
}

public SlCoreTelemetryStatus GetStatus()
{
return telemetryHelper.GetStatus();
}
public void QuickFixApplied(string ruleId) => telemetryHelper.Notify(telemetryService => telemetryService.AddQuickFixAppliedForRule(new AddQuickFixAppliedForRuleParams(ruleId)));

public void OptIn()
{
telemetryHelper.Notify(telemetryService => telemetryService.EnableTelemetry());
}
public SlCoreTelemetryStatus GetStatus() => telemetryHelper.GetStatus();

public void OptIn() => telemetryHelper.Notify(telemetryService => telemetryService.EnableTelemetry());

public void OptOut()
{
telemetryHelper.Notify(telemetryService => telemetryService.DisableTelemetry());
}
public void OptOut() => telemetryHelper.Notify(telemetryService => telemetryService.DisableTelemetry());

public void LanguageAnalyzed(string languageKey, TimeSpan analysisTime)
{
Expand All @@ -74,27 +67,11 @@ public void LanguageAnalyzed(string languageKey, TimeSpan analysisTime)
telemetryService.AnalysisDoneOnSingleLanguage(new AnalysisDoneOnSingleLanguageParams(language, (int)Math.Round(analysisTime.TotalMilliseconds))));
}

public void TaintIssueInvestigatedLocally()
{
telemetryHelper.Notify(telemetryService => telemetryService.TaintVulnerabilitiesInvestigatedLocally());
}

public void TaintIssueInvestigatedRemotely()
{
telemetryHelper.Notify(telemetryService => telemetryService.TaintVulnerabilitiesInvestigatedRemotely());
}
public void TaintIssueInvestigatedLocally() => telemetryHelper.Notify(telemetryService => telemetryService.TaintVulnerabilitiesInvestigatedLocally());

public void TaintIssueInvestigatedRemotely() => telemetryHelper.Notify(telemetryService => telemetryService.TaintVulnerabilitiesInvestigatedRemotely());

public void LinkClicked(string linkId)
{
telemetryHelper.Notify(telemetryService => telemetryService.HelpAndFeedbackLinkClicked(new HelpAndFeedbackClickedParams(linkId)));
}

public void Dispose()
{
knownUiContexts.CSharpProjectContextChanged -= OnCSharpProjectContextChanged;
knownUiContexts.VBProjectContextChanged -= OnVBProjectContextChanged;
}
public void LinkClicked(string linkId) => telemetryHelper.Notify(telemetryService => telemetryService.HelpAndFeedbackLinkClicked(new HelpAndFeedbackClickedParams(linkId)));

private void OnCSharpProjectContextChanged(object sender, UIContextChangedEventArgs e)
{
Expand All @@ -112,9 +89,8 @@ private void OnVBProjectContextChanged(object sender, UIContextChangedEventArgs
}
}

private static Language Convert(string languageKey)
{
return languageKey switch
private static Language Convert(string languageKey) =>
languageKey switch
{
SonarLanguageKeys.CPlusPlus => Language.CPP,
SonarLanguageKeys.C => Language.C,
Expand All @@ -126,5 +102,4 @@ private static Language Convert(string languageKey)
SonarLanguageKeys.Secrets => Language.SECRETS,
_ => throw new ArgumentOutOfRangeException(nameof(languageKey), languageKey, null)
};
}
}

0 comments on commit 7c9a162

Please sign in to comment.