From 14cb4ca0c9323b5223b2f1375b990e15a8e6529c Mon Sep 17 00:00:00 2001 From: Agne Lukoseviciute Date: Thu, 28 Mar 2024 14:38:58 -0700 Subject: [PATCH 1/3] upgrade --- .github/workflows/GitHubExt-CI.yml | 2 +- Directory.Build.props | 11 +++++++ ToolingVersions.props | 2 +- src/GitHubExtension/Client/Validation.cs | 2 +- src/GitHubExtension/Constants.cs | 2 +- .../DataManager/GitHubDataManager.cs | 14 +++++--- .../DataModel/DataObjects/Repository.cs | 2 +- .../DeveloperId/LoginUI/EndPage.cs | 2 +- .../LoginUI/EnterpriseServerPATPage.cs | 8 ++--- .../LoginUI/EnterpriseServerPage.cs | 8 ++--- .../DeveloperId/LoginUI/LoginFailedPage.cs | 4 +-- .../DeveloperId/LoginUI/LoginPage.cs | 6 ++-- .../DeveloperId/LoginUI/LoginSucceededPage.cs | 4 +-- .../DeveloperId/LoginUI/LoginUIPage.cs | 5 +-- .../DeveloperId/LoginUI/WaitingPage.cs | 4 +-- .../DeveloperId/OAuthRequest.cs | 4 +-- src/GitHubExtension/Helpers/IconLoader.cs | 3 +- src/GitHubExtension/Helpers/Json.cs | 23 ++++++------- src/GitHubExtension/Helpers/LocalSettings.cs | 4 +-- src/GitHubExtension/Helpers/TimeSpanHelper.cs | 2 +- .../Notifications/NotificationHandler.cs | 6 ++-- .../Providers/SettingsUIController.cs | 4 +-- .../Widgets/GitHubAssignedWidget.cs | 4 +-- .../Widgets/GitHubIssuesWidget.cs | 4 +-- .../Widgets/GitHubMentionedInWidget.cs | 4 +-- .../Widgets/GitHubPullsWidget.cs | 4 +-- .../Widgets/GitHubReleasesWidget.cs | 4 +-- .../Widgets/GitHubReviewWidget.cs | 4 +-- src/GitHubExtension/Widgets/GitHubWidget.cs | 8 ++--- .../Widgets/WidgetImplFactory`1.cs | 2 +- src/GitHubExtension/Widgets/WidgetProvider.cs | 32 +++++++++---------- src/GitHubExtension/Widgets/WidgetServer.cs | 2 +- src/Logging/helpers/DictionaryExtensions.cs | 5 +-- src/Telemetry/Logger.cs | 2 +- 34 files changed, 97 insertions(+), 100 deletions(-) diff --git a/.github/workflows/GitHubExt-CI.yml b/.github/workflows/GitHubExt-CI.yml index a4420bf6..2c4b2c42 100644 --- a/.github/workflows/GitHubExt-CI.yml +++ b/.github/workflows/GitHubExt-CI.yml @@ -15,7 +15,7 @@ jobs: configuration: [Release, Debug] platform: [x64, x86, arm64] os: [windows-latest] - dotnet-version: ['6.0.x'] + dotnet-version: ['8.0.x'] exclude: - configuration: Debug platform: x64 diff --git a/Directory.Build.props b/Directory.Build.props index e293c534..7c2dc3c1 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -45,4 +45,15 @@ + + + + + true + + + + \ No newline at end of file diff --git a/ToolingVersions.props b/ToolingVersions.props index b6c8d340..f4a87568 100644 --- a/ToolingVersions.props +++ b/ToolingVersions.props @@ -2,7 +2,7 @@ - net6.0-windows10.0.22000.0 + net8.0-windows10.0.22000.0 10.0.19041.0 10.0.19041.0 diff --git a/src/GitHubExtension/Client/Validation.cs b/src/GitHubExtension/Client/Validation.cs index 24f14d5f..e166cffe 100644 --- a/src/GitHubExtension/Client/Validation.cs +++ b/src/GitHubExtension/Client/Validation.cs @@ -209,7 +209,7 @@ private static string AddProtocolToString(string s) private static string[]? GetNameAndRepoFromFullName(string s) { - var n = s.Split(new[] { '/' }); + var n = s.Split(['/']); // This should be exactly two results with no empty strings. if (n.Length != 2 || string.IsNullOrEmpty(n[0]) || string.IsNullOrEmpty(n[1])) diff --git a/src/GitHubExtension/Constants.cs b/src/GitHubExtension/Constants.cs index 3728442f..579cb7c3 100644 --- a/src/GitHubExtension/Constants.cs +++ b/src/GitHubExtension/Constants.cs @@ -3,7 +3,7 @@ namespace GitHubExtension; -internal class Constants +internal sealed class Constants { #pragma warning disable SA1310 // Field names should not contain underscore public const string DEV_HOME_APPLICATION_NAME = "DevHome"; diff --git a/src/GitHubExtension/DataManager/GitHubDataManager.cs b/src/GitHubExtension/DataManager/GitHubDataManager.cs index 36141fe1..ffe57a26 100644 --- a/src/GitHubExtension/DataManager/GitHubDataManager.cs +++ b/src/GitHubExtension/DataManager/GitHubDataManager.cs @@ -101,7 +101,7 @@ await UpdateDataForRepositoryAsync( await UpdatePullRequestsAsync(repository, devId.GitHubClient, parameters.RequestOptions); }); - SendRepositoryUpdateEvent(this, GetFullNameFromOwnerAndRepository(owner, name), new string[] { "Issues", "PullRequests" }); + SendRepositoryUpdateEvent(this, GetFullNameFromOwnerAndRepository(owner, name), IssuesAndPRsStringArray); } public async Task UpdateAllDataForRepositoryAsync(string fullName, RequestOptions? options = null) @@ -130,7 +130,7 @@ await UpdateDataForRepositoryAsync( await UpdatePullRequestsAsync(repository, devId.GitHubClient, parameters.RequestOptions); }); - SendRepositoryUpdateEvent(this, GetFullNameFromOwnerAndRepository(owner, name), new string[] { "PullRequests" }); + SendRepositoryUpdateEvent(this, GetFullNameFromOwnerAndRepository(owner, name), PRsStringArray); } public async Task UpdatePullRequestsForRepositoryAsync(string fullName, RequestOptions? options = null) @@ -159,7 +159,7 @@ await UpdateDataForRepositoryAsync( await UpdateIssuesAsync(repository, devId.GitHubClient, parameters.RequestOptions); }); - SendRepositoryUpdateEvent(this, GetFullNameFromOwnerAndRepository(owner, name), new string[] { "Issues" }); + SendRepositoryUpdateEvent(this, GetFullNameFromOwnerAndRepository(owner, name), IssuesStringArray); } public async Task UpdateIssuesForRepositoryAsync(string fullName, RequestOptions? options = null) @@ -199,7 +199,7 @@ await UpdateDataForRepositoryAsync( await UpdateReleasesAsync(repository, devId.GitHubClient, parameters.RequestOptions); }); - SendRepositoryUpdateEvent(this, GetFullNameFromOwnerAndRepository(owner, name), new string[] { "Releases" }); + SendRepositoryUpdateEvent(this, GetFullNameFromOwnerAndRepository(owner, name), ReleasesStringArray); } public IEnumerable GetRepositories() @@ -785,7 +785,7 @@ private void SetLastUpdatedInMetaData() // Converts fullName -> owner, name. private string[] GetOwnerAndRepositoryNameFromFullName(string fullName) { - var nameSplit = fullName.Split(new[] { '/' }); + var nameSplit = fullName.Split(['/']); if (nameSplit.Length != 2 || string.IsNullOrEmpty(nameSplit[0]) || string.IsNullOrEmpty(nameSplit[1])) { Log.Logger()?.ReportError(Name, $"Invalid repository full name: {fullName}"); @@ -839,6 +839,10 @@ private static DataStoreOptions DefaultOptionsInit() public override string ToString() => "GitHubDataManager"; private bool disposed; // To detect redundant calls. + private static readonly string[] IssuesAndPRsStringArray = new string[] { "Issues", "PullRequests" }; + private static readonly string[] PRsStringArray = new string[] { "PullRequests" }; + private static readonly string[] IssuesStringArray = new string[] { "Issues" }; + private static readonly string[] ReleasesStringArray = new string[] { "Releases" }; protected virtual void Dispose(bool disposing) { diff --git a/src/GitHubExtension/DataModel/DataObjects/Repository.cs b/src/GitHubExtension/DataModel/DataObjects/Repository.cs index 2fbaf5be..9f7e4118 100644 --- a/src/GitHubExtension/DataModel/DataObjects/Repository.cs +++ b/src/GitHubExtension/DataModel/DataObjects/Repository.cs @@ -269,7 +269,7 @@ public static IEnumerable GetAll(DataStore dataStore) public static Repository? Get(DataStore dataStore, string fullName) { - var nameSplit = fullName.Split(new[] { '/' }, 2); + var nameSplit = fullName.Split(['/'], 2); if (nameSplit.Length != 2) { Log.Logger()?.ReportWarn($"Invalid fullName input into Repository.Get: {fullName}"); diff --git a/src/GitHubExtension/DeveloperId/LoginUI/EndPage.cs b/src/GitHubExtension/DeveloperId/LoginUI/EndPage.cs index 51234cc6..8a3cb35d 100644 --- a/src/GitHubExtension/DeveloperId/LoginUI/EndPage.cs +++ b/src/GitHubExtension/DeveloperId/LoginUI/EndPage.cs @@ -3,7 +3,7 @@ namespace GitHubExtension.DeveloperId.LoginUI; -internal class EndPage : LoginUIPage +internal sealed class EndPage : LoginUIPage { public EndPage() : base(LoginUIState.End) diff --git a/src/GitHubExtension/DeveloperId/LoginUI/EnterpriseServerPATPage.cs b/src/GitHubExtension/DeveloperId/LoginUI/EnterpriseServerPATPage.cs index b94740b5..608a0a94 100644 --- a/src/GitHubExtension/DeveloperId/LoginUI/EnterpriseServerPATPage.cs +++ b/src/GitHubExtension/DeveloperId/LoginUI/EnterpriseServerPATPage.cs @@ -6,7 +6,7 @@ namespace GitHubExtension.DeveloperId.LoginUI; -internal class EnterpriseServerPATPage : LoginUIPage +internal sealed class EnterpriseServerPATPage : LoginUIPage { public EnterpriseServerPATPage(Uri hostAddress, string errorText, SecureString inputPAT) : base(LoginUIState.EnterpriseServerPATPage) @@ -21,7 +21,7 @@ public EnterpriseServerPATPage(Uri hostAddress, string errorText, SecureString i }; } - internal class PageData : ILoginUIPageData + internal sealed class PageData : ILoginUIPageData { public string EnterpriseServerPATPageInputValue { get; set; } = string.Empty; @@ -39,7 +39,7 @@ public string GetJson() } } - internal class ActionPayload : SubmitActionPayload + internal sealed class ActionPayload : SubmitActionPayload { public string? URL { @@ -47,7 +47,7 @@ public string? URL } } - internal class InputPayload + internal sealed class InputPayload { public string? PAT { diff --git a/src/GitHubExtension/DeveloperId/LoginUI/EnterpriseServerPage.cs b/src/GitHubExtension/DeveloperId/LoginUI/EnterpriseServerPage.cs index bc6842b2..b5e09908 100644 --- a/src/GitHubExtension/DeveloperId/LoginUI/EnterpriseServerPage.cs +++ b/src/GitHubExtension/DeveloperId/LoginUI/EnterpriseServerPage.cs @@ -5,7 +5,7 @@ namespace GitHubExtension.DeveloperId.LoginUI; -internal class EnterpriseServerPage : LoginUIPage +internal sealed class EnterpriseServerPage : LoginUIPage { public EnterpriseServerPage(Uri? hostAddress, string errorText) : base(LoginUIState.EnterpriseServerPage) @@ -29,7 +29,7 @@ public EnterpriseServerPage(string hostAddress, string errorText) }; } - internal class PageData : ILoginUIPageData + internal sealed class PageData : ILoginUIPageData { public string EnterpriseServerInputValue { get; set; } = string.Empty; @@ -44,11 +44,11 @@ public string GetJson() } } - internal class ActionPayload : SubmitActionPayload + internal sealed class ActionPayload : SubmitActionPayload { } - internal class InputPayload + internal sealed class InputPayload { public string? EnterpriseServer { diff --git a/src/GitHubExtension/DeveloperId/LoginUI/LoginFailedPage.cs b/src/GitHubExtension/DeveloperId/LoginUI/LoginFailedPage.cs index a8144102..cda9985b 100644 --- a/src/GitHubExtension/DeveloperId/LoginUI/LoginFailedPage.cs +++ b/src/GitHubExtension/DeveloperId/LoginUI/LoginFailedPage.cs @@ -5,7 +5,7 @@ namespace GitHubExtension.DeveloperId.LoginUI; -internal class LoginFailedPage : LoginUIPage +internal sealed class LoginFailedPage : LoginUIPage { public LoginFailedPage() : base(LoginUIState.LoginFailedPage) @@ -13,7 +13,7 @@ public LoginFailedPage() Data = new LoginFailedPageData(); } - internal class LoginFailedPageData : ILoginUIPageData + internal sealed class LoginFailedPageData : ILoginUIPageData { public string GetJson() { diff --git a/src/GitHubExtension/DeveloperId/LoginUI/LoginPage.cs b/src/GitHubExtension/DeveloperId/LoginUI/LoginPage.cs index 688ec225..53b542a0 100644 --- a/src/GitHubExtension/DeveloperId/LoginUI/LoginPage.cs +++ b/src/GitHubExtension/DeveloperId/LoginUI/LoginPage.cs @@ -5,7 +5,7 @@ namespace GitHubExtension.DeveloperId.LoginUI; -internal class LoginPage : LoginUIPage +internal sealed class LoginPage : LoginUIPage { public LoginPage() : base(LoginUIState.LoginPage) @@ -13,7 +13,7 @@ public LoginPage() Data = new PageData(); } - internal class PageData : ILoginUIPageData + internal sealed class PageData : ILoginUIPageData { public string GetJson() { @@ -21,7 +21,7 @@ public string GetJson() } } - internal class ActionPayload : SubmitActionPayload + internal sealed class ActionPayload : SubmitActionPayload { public bool IsEnterprise() { diff --git a/src/GitHubExtension/DeveloperId/LoginUI/LoginSucceededPage.cs b/src/GitHubExtension/DeveloperId/LoginUI/LoginSucceededPage.cs index 5ef03649..511c1789 100644 --- a/src/GitHubExtension/DeveloperId/LoginUI/LoginSucceededPage.cs +++ b/src/GitHubExtension/DeveloperId/LoginUI/LoginSucceededPage.cs @@ -6,7 +6,7 @@ namespace GitHubExtension.DeveloperId.LoginUI; -internal class LoginSucceededPage : LoginUIPage +internal sealed class LoginSucceededPage : LoginUIPage { public LoginSucceededPage(IDeveloperId developerId) : base(LoginUIState.LoginSucceededPage) @@ -17,7 +17,7 @@ public LoginSucceededPage(IDeveloperId developerId) }; } - internal class LoginSucceededPageData : ILoginUIPageData + internal sealed class LoginSucceededPageData : ILoginUIPageData { public string? Message { get; set; } = string.Empty; diff --git a/src/GitHubExtension/DeveloperId/LoginUI/LoginUIPage.cs b/src/GitHubExtension/DeveloperId/LoginUI/LoginUIPage.cs index d6fe7453..063cee7d 100644 --- a/src/GitHubExtension/DeveloperId/LoginUI/LoginUIPage.cs +++ b/src/GitHubExtension/DeveloperId/LoginUI/LoginUIPage.cs @@ -31,10 +31,7 @@ public LoginUIPage(LoginUIState state) public ProviderOperationResult UpdateExtensionAdaptiveCard(IExtensionAdaptiveCard adaptiveCard) { - if (adaptiveCard == null) - { - throw new ArgumentNullException(nameof(adaptiveCard)); - } + ArgumentNullException.ThrowIfNull(adaptiveCard); return adaptiveCard.Update(_template, _data?.GetJson(), Enum.GetName(typeof(LoginUIState), _state)); } diff --git a/src/GitHubExtension/DeveloperId/LoginUI/WaitingPage.cs b/src/GitHubExtension/DeveloperId/LoginUI/WaitingPage.cs index 19739c8b..d03a5925 100644 --- a/src/GitHubExtension/DeveloperId/LoginUI/WaitingPage.cs +++ b/src/GitHubExtension/DeveloperId/LoginUI/WaitingPage.cs @@ -5,7 +5,7 @@ namespace GitHubExtension.DeveloperId.LoginUI; -internal class WaitingPage : LoginUIPage +internal sealed class WaitingPage : LoginUIPage { public WaitingPage() : base(LoginUIState.WaitingPage) @@ -13,7 +13,7 @@ public WaitingPage() Data = new WaitingPageData(); } - internal class WaitingPageData : ILoginUIPageData + internal sealed class WaitingPageData : ILoginUIPageData { public string GetJson() { diff --git a/src/GitHubExtension/DeveloperId/OAuthRequest.cs b/src/GitHubExtension/DeveloperId/OAuthRequest.cs index 2c0d3904..1c112409 100644 --- a/src/GitHubExtension/DeveloperId/OAuthRequest.cs +++ b/src/GitHubExtension/DeveloperId/OAuthRequest.cs @@ -10,7 +10,7 @@ namespace GitHubExtension.DeveloperId; -internal class OAuthRequest : IDisposable +internal sealed class OAuthRequest : IDisposable { internal string State { get; private set; } @@ -28,7 +28,7 @@ internal OAuthRequest() State = string.Empty; } - protected virtual void Dispose(bool disposing) + private void Dispose(bool disposing) { if (disposing) { diff --git a/src/GitHubExtension/Helpers/IconLoader.cs b/src/GitHubExtension/Helpers/IconLoader.cs index e10fe374..8447a084 100644 --- a/src/GitHubExtension/Helpers/IconLoader.cs +++ b/src/GitHubExtension/Helpers/IconLoader.cs @@ -12,9 +12,8 @@ public class IconLoader public static string GetIconAsBase64(string filename) { Log.Logger()?.ReportDebug(nameof(IconLoader), $"Asking for icon: {filename}"); - if (!Base64ImageRegistry.ContainsKey(filename)) + if (!Base64ImageRegistry.TryAdd(filename, ConvertIconToDataString(filename))) { - Base64ImageRegistry.Add(filename, ConvertIconToDataString(filename)); Log.Logger()?.ReportDebug(nameof(IconLoader), $"The icon {filename} was converted and is now stored."); } diff --git a/src/GitHubExtension/Helpers/Json.cs b/src/GitHubExtension/Helpers/Json.cs index 314d3a9a..93be1d14 100644 --- a/src/GitHubExtension/Helpers/Json.cs +++ b/src/GitHubExtension/Helpers/Json.cs @@ -9,6 +9,13 @@ namespace GitHubExtension.Helpers; public static class Json { + private static readonly JsonSerializerOptions Options = new() + { + PropertyNameCaseInsensitive = true, + DefaultIgnoreCondition = JsonIgnoreCondition.Never, + IncludeFields = true, + }; + public static async Task ToObjectAsync(string value) { if (typeof(T) == typeof(bool)) @@ -42,14 +49,7 @@ public static string Stringify(T value) return value!.ToString()!.ToLowerInvariant(); } - return System.Text.Json.JsonSerializer.Serialize( - value, - new JsonSerializerOptions - { - PropertyNameCaseInsensitive = true, - DefaultIgnoreCondition = JsonIgnoreCondition.Never, - IncludeFields = true, - }); + return System.Text.Json.JsonSerializer.Serialize(value, Options); } public static T? ToObject(string json) @@ -59,11 +59,6 @@ public static string Stringify(T value) return (T)(object)bool.Parse(json); } - return System.Text.Json.JsonSerializer.Deserialize(json, new JsonSerializerOptions - { - PropertyNameCaseInsensitive = true, - DefaultIgnoreCondition = JsonIgnoreCondition.Never, - IncludeFields = true, - }); + return System.Text.Json.JsonSerializer.Deserialize(json, Options); } } diff --git a/src/GitHubExtension/Helpers/LocalSettings.cs b/src/GitHubExtension/Helpers/LocalSettings.cs index 76563412..542f0252 100644 --- a/src/GitHubExtension/Helpers/LocalSettings.cs +++ b/src/GitHubExtension/Helpers/LocalSettings.cs @@ -11,7 +11,7 @@ public static class LocalSettings private static readonly string _applicationDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DevHome/ApplicationData"); private static readonly string _localSettingsFile = "LocalSettings.json"; - private static IDictionary? _settings; + private static Dictionary? _settings; private static async Task InitializeAsync() { @@ -23,7 +23,7 @@ private static async Task InitializeAsync() } else { - _settings = await Task.Run(() => FileHelper.Read>(_applicationDataFolder, _localSettingsFile)) ?? new Dictionary(); + _settings = await Task.Run(() => FileHelper.Read>(_applicationDataFolder, _localSettingsFile)) ?? new Dictionary(); } } } diff --git a/src/GitHubExtension/Helpers/TimeSpanHelper.cs b/src/GitHubExtension/Helpers/TimeSpanHelper.cs index 9afbc566..6866a95d 100644 --- a/src/GitHubExtension/Helpers/TimeSpanHelper.cs +++ b/src/GitHubExtension/Helpers/TimeSpanHelper.cs @@ -6,7 +6,7 @@ namespace GitHubExtension.Helpers; -internal class TimeSpanHelper +internal sealed class TimeSpanHelper { public static string TimeSpanToDisplayString(TimeSpan timeSpan, Logger? log = null) { diff --git a/src/GitHubExtension/Notifications/NotificationHandler.cs b/src/GitHubExtension/Notifications/NotificationHandler.cs index c6626b7b..b3f13f7b 100644 --- a/src/GitHubExtension/Notifications/NotificationHandler.cs +++ b/src/GitHubExtension/Notifications/NotificationHandler.cs @@ -19,13 +19,13 @@ public static void NotificationActivation(AppNotificationActivatedEventArgs args { Log.Logger()?.ReportInfo($"Notification Activated with args: {NotificationArgsToString(args)}"); - if (args.Arguments.ContainsKey("htmlurl")) + if (args.Arguments.TryGetValue("htmlurl", out var htmlUrl)) { try { // Do not assume this string is a safe URL and blindly execute it; verify that it is // in fact a valid GitHub URL. - var urlString = args.Arguments["htmlurl"]; + var urlString = htmlUrl; if (!Validation.IsValidGitHubURL(urlString)) { throw new InvalidGitHubUrlException($"{urlString} is invalid."); @@ -42,7 +42,7 @@ public static void NotificationActivation(AppNotificationActivatedEventArgs args } catch (Exception ex) { - Log.Logger()?.ReportError($"Failed launching Uri for {args.Arguments["htmlurl"]}", ex); + Log.Logger()?.ReportError($"Failed launching Uri for {htmlUrl}", ex); } return; diff --git a/src/GitHubExtension/Providers/SettingsUIController.cs b/src/GitHubExtension/Providers/SettingsUIController.cs index a4b6fa7e..c9b537fa 100644 --- a/src/GitHubExtension/Providers/SettingsUIController.cs +++ b/src/GitHubExtension/Providers/SettingsUIController.cs @@ -8,7 +8,7 @@ namespace GitHubExtension.Providers; -internal class SettingsUIController : IExtensionAdaptiveCardSession +internal sealed class SettingsUIController : IExtensionAdaptiveCardSession { private static readonly string _notificationsEnabledString = "NotificationsEnabled"; @@ -63,7 +63,7 @@ public IAsyncOperation OnAction(string action, string i } // Adaptive Card Templates for SettingsUI. - private class SettingsUITemplate + private sealed class SettingsUITemplate { internal string GetSettingsUITemplate() { diff --git a/src/GitHubExtension/Widgets/GitHubAssignedWidget.cs b/src/GitHubExtension/Widgets/GitHubAssignedWidget.cs index 45ea2655..7d20b0fa 100644 --- a/src/GitHubExtension/Widgets/GitHubAssignedWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubAssignedWidget.cs @@ -5,7 +5,7 @@ namespace GitHubExtension.Widgets; -internal class GitHubAssignedWidget : GitHubUserWidget +internal sealed class GitHubAssignedWidget : GitHubUserWidget { private static readonly string TitleIconData = "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABGdBTUEAALGPC/xhBQAAAAlwS" + @@ -55,8 +55,6 @@ internal class GitHubAssignedWidget : GitHubUserWidget "qSu2i3mQQP0mcwBzBQei0stR7+mT+v5X9v6Wl8Aqo7k1lqZ/uoAbm/GE7ZbUpqgByOe57MDXG" + "k5sHfmNwyTXv6g+Z9V32JXdGMYwhjGMYQzLYNOm/wESzvR5z0LQ4QAAAABJRU5ErkJggg=="; - protected static readonly new string Name = nameof(GitHubAssignedWidget); - protected override string GetTitleIconData() { return TitleIconData; diff --git a/src/GitHubExtension/Widgets/GitHubIssuesWidget.cs b/src/GitHubExtension/Widgets/GitHubIssuesWidget.cs index 95fc7dda..fb9fa95b 100644 --- a/src/GitHubExtension/Widgets/GitHubIssuesWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubIssuesWidget.cs @@ -10,11 +10,11 @@ namespace GitHubExtension.Widgets; -internal class GitHubIssuesWidget : GitHubRepositoryWidget +internal sealed class GitHubIssuesWidget : GitHubRepositoryWidget { private readonly string issuesIconData = IconLoader.GetIconAsBase64("issues.png"); - protected static readonly new string Name = nameof(GitHubIssuesWidget); + private static readonly new string Name = nameof(GitHubIssuesWidget); public override void DeleteWidget(string widgetId, string customState) { diff --git a/src/GitHubExtension/Widgets/GitHubMentionedInWidget.cs b/src/GitHubExtension/Widgets/GitHubMentionedInWidget.cs index fbae0ed3..1a63b826 100644 --- a/src/GitHubExtension/Widgets/GitHubMentionedInWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubMentionedInWidget.cs @@ -5,7 +5,7 @@ namespace GitHubExtension.Widgets; -internal class GitHubMentionedInWidget : GitHubUserWidget +internal sealed class GitHubMentionedInWidget : GitHubUserWidget { private static readonly string TitleIconData = "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABGdBTUEAALGPC/xhBQAAAA" + @@ -36,8 +36,6 @@ internal class GitHubMentionedInWidget : GitHubUserWidget "W2+XsCNN5MdnNZw38ksp1Odyag9m4AD1g0f1QBnmA2WUN5HPim5V7jiPIsneZsCMdjHvmn" + "ZBE9QJ5KFrH0dFXqxnYisOz0HtBybqufmgwMDAwMDFWCmpq/ANfVYnfzsINAAAAAAElFTkSuQmCC"; - protected static readonly new string Name = nameof(GitHubMentionedInWidget); - protected override string GetTitleIconData() { return TitleIconData; diff --git a/src/GitHubExtension/Widgets/GitHubPullsWidget.cs b/src/GitHubExtension/Widgets/GitHubPullsWidget.cs index 18f4875d..5f15a1e0 100644 --- a/src/GitHubExtension/Widgets/GitHubPullsWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubPullsWidget.cs @@ -10,13 +10,13 @@ namespace GitHubExtension.Widgets; -internal class GitHubPullsWidget : GitHubRepositoryWidget +internal sealed class GitHubPullsWidget : GitHubRepositoryWidget { private readonly string pullsIconData = IconLoader.GetIconAsBase64("pulls.png"); private static Dictionary Templates { get; set; } = new(); - protected static readonly new string Name = nameof(GitHubPullsWidget); + private static readonly new string Name = nameof(GitHubPullsWidget); public override void DeleteWidget(string widgetId, string customState) { diff --git a/src/GitHubExtension/Widgets/GitHubReleasesWidget.cs b/src/GitHubExtension/Widgets/GitHubReleasesWidget.cs index 694d8cf9..ce295949 100644 --- a/src/GitHubExtension/Widgets/GitHubReleasesWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubReleasesWidget.cs @@ -10,11 +10,11 @@ namespace GitHubExtension.Widgets; -internal class GitHubReleasesWidget : GitHubRepositoryWidget +internal sealed class GitHubReleasesWidget : GitHubRepositoryWidget { private readonly string _releasesIconData = IconLoader.GetIconAsBase64("releases.png"); - protected static readonly new string Name = nameof(GitHubReleasesWidget); + private static readonly new string Name = nameof(GitHubReleasesWidget); public override void DeleteWidget(string widgetId, string customState) { diff --git a/src/GitHubExtension/Widgets/GitHubReviewWidget.cs b/src/GitHubExtension/Widgets/GitHubReviewWidget.cs index 9a248426..a35ff0fd 100644 --- a/src/GitHubExtension/Widgets/GitHubReviewWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubReviewWidget.cs @@ -9,10 +9,8 @@ namespace GitHubExtension.Widgets; -internal class GitHubReviewWidget : GitHubUserWidget +internal sealed class GitHubReviewWidget : GitHubUserWidget { - protected static readonly new string Name = nameof(GitHubReviewWidget); - public GitHubReviewWidget() : base() { diff --git a/src/GitHubExtension/Widgets/GitHubWidget.cs b/src/GitHubExtension/Widgets/GitHubWidget.cs index 341fabf2..d768b9a8 100644 --- a/src/GitHubExtension/Widgets/GitHubWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubWidget.cs @@ -79,7 +79,7 @@ public override void CreateWidget(WidgetContext widgetContext, string state) // If there is a state, it is being retrieved from the widget service, so // this widget was pinned before. - if (state.Any()) + if (state.Length != 0) { ResetWidgetInfoFromState(); Saved = true; @@ -200,7 +200,7 @@ public string GetSignIn() public bool IsUserLoggedIn() { - IDeveloperIdProvider authProvider = DeveloperIdProvider.GetInstance(); + DeveloperIdProvider authProvider = DeveloperIdProvider.GetInstance(); return authProvider.GetLoggedInDeveloperIds().DeveloperIds.Any(); } @@ -254,10 +254,10 @@ public virtual string GetData(WidgetPageState page) protected string GetTemplateForPage(WidgetPageState page) { - if (Template.ContainsKey(page)) + if (Template.TryGetValue(page, out var pageTemplate)) { Log.Logger()?.ReportDebug(Name, ShortId, $"Using cached template for {page}"); - return Template[page]; + return pageTemplate; } try diff --git a/src/GitHubExtension/Widgets/WidgetImplFactory`1.cs b/src/GitHubExtension/Widgets/WidgetImplFactory`1.cs index b4ead9f3..33790ef8 100644 --- a/src/GitHubExtension/Widgets/WidgetImplFactory`1.cs +++ b/src/GitHubExtension/Widgets/WidgetImplFactory`1.cs @@ -5,7 +5,7 @@ namespace GitHubExtension.Widgets; -internal class WidgetImplFactory : IWidgetImplFactory +internal sealed class WidgetImplFactory : IWidgetImplFactory where T : WidgetImpl, new() { public WidgetImpl Create(WidgetContext widgetContext, string state) diff --git a/src/GitHubExtension/Widgets/WidgetProvider.cs b/src/GitHubExtension/Widgets/WidgetProvider.cs index 9305b089..2b86da58 100644 --- a/src/GitHubExtension/Widgets/WidgetProvider.cs +++ b/src/GitHubExtension/Widgets/WidgetProvider.cs @@ -36,11 +36,11 @@ private void InitializeWidget(WidgetContext widgetContext, string state) var widgetId = widgetContext.Id; var widgetDefinitionId = widgetContext.DefinitionId; Log.Logger()?.ReportDebug($"Calling Initialize for Widget Id: {widgetId} - {widgetDefinitionId}"); - if (widgetDefinitionRegistry.ContainsKey(widgetDefinitionId)) + if (widgetDefinitionRegistry.TryGetValue(widgetDefinitionId, out var widgetDefinition)) { if (!runningWidgets.ContainsKey(widgetId)) { - var factory = widgetDefinitionRegistry[widgetDefinitionId]; + var factory = widgetDefinition; var widgetImpl = factory.Create(widgetContext, state); runningWidgets.Add(widgetId, widgetImpl); } @@ -95,18 +95,18 @@ public void Activate(WidgetContext widgetContext) { Log.Logger()?.ReportDebug($"Activate id: {widgetContext.Id} definitionId: {widgetContext.DefinitionId}"); var widgetId = widgetContext.Id; - if (runningWidgets.ContainsKey(widgetId)) + if (runningWidgets.TryGetValue(widgetId, out var widget)) { - runningWidgets[widgetId].Activate(widgetContext); + widget.Activate(widgetContext); } else { // Called to activate a widget that we don't know about, which is unexpected. Try to recover by creating it. Log.Logger()?.ReportWarn($"Found WidgetId that was not known: {widgetContext.Id}, attempting to recover by creating it."); CreateWidget(widgetContext); - if (runningWidgets.ContainsKey(widgetId)) + if (runningWidgets.TryGetValue(widgetId, out var newWidget)) { - runningWidgets[widgetId].Activate(widgetContext); + newWidget.Activate(widgetContext); } } } @@ -114,18 +114,18 @@ public void Activate(WidgetContext widgetContext) public void Deactivate(string widgetId) { Log.Logger()?.ReportDebug($"Deactivate id: {widgetId}"); - if (runningWidgets.ContainsKey(widgetId)) + if (runningWidgets.TryGetValue(widgetId, out var widget)) { - runningWidgets[widgetId].Deactivate(widgetId); + widget.Deactivate(widgetId); } } public void DeleteWidget(string widgetId, string customState) { Log.Logger()?.ReportInfo($"DeleteWidget id: {widgetId}"); - if (runningWidgets.ContainsKey(widgetId)) + if (runningWidgets.TryGetValue(widgetId, out var widget)) { - runningWidgets[widgetId].DeleteWidget(widgetId, customState); + widget.DeleteWidget(widgetId, customState); runningWidgets.Remove(widgetId); } } @@ -135,9 +135,9 @@ public void OnActionInvoked(WidgetActionInvokedArgs actionInvokedArgs) Log.Logger()?.ReportDebug($"OnActionInvoked id: {actionInvokedArgs.WidgetContext.Id} definitionId: {actionInvokedArgs.WidgetContext.DefinitionId}"); var widgetContext = actionInvokedArgs.WidgetContext; var widgetId = widgetContext.Id; - if (runningWidgets.ContainsKey(widgetId)) + if (runningWidgets.TryGetValue(widgetId, out var widget)) { - runningWidgets[widgetId].OnActionInvoked(actionInvokedArgs); + widget.OnActionInvoked(actionInvokedArgs); } } @@ -146,9 +146,9 @@ public void OnCustomizationRequested(WidgetCustomizationRequestedArgs customizat Log.Logger()?.ReportDebug($"OnCustomizationRequested id: {customizationRequestedArgs.WidgetContext.Id} definitionId: {customizationRequestedArgs.WidgetContext.DefinitionId}"); var widgetContext = customizationRequestedArgs.WidgetContext; var widgetId = widgetContext.Id; - if (runningWidgets.ContainsKey(widgetId)) + if (runningWidgets.TryGetValue(widgetId, out var widget)) { - runningWidgets[widgetId].OnCustomizationRequested(customizationRequestedArgs); + widget.OnCustomizationRequested(customizationRequestedArgs); } } @@ -157,9 +157,9 @@ public void OnWidgetContextChanged(WidgetContextChangedArgs contextChangedArgs) Log.Logger()?.ReportDebug($"OnWidgetContextChanged id: {contextChangedArgs.WidgetContext.Id} definitionId: {contextChangedArgs.WidgetContext.DefinitionId}"); var widgetContext = contextChangedArgs.WidgetContext; var widgetId = widgetContext.Id; - if (runningWidgets.ContainsKey(widgetId)) + if (runningWidgets.TryGetValue(widgetId, out var widget)) { - runningWidgets[widgetId].OnWidgetContextChanged(contextChangedArgs); + widget.OnWidgetContextChanged(contextChangedArgs); } } } diff --git a/src/GitHubExtension/Widgets/WidgetServer.cs b/src/GitHubExtension/Widgets/WidgetServer.cs index 3cb71466..22a268b2 100644 --- a/src/GitHubExtension/Widgets/WidgetServer.cs +++ b/src/GitHubExtension/Widgets/WidgetServer.cs @@ -62,7 +62,7 @@ public void Dispose() } } - private class Ole32 + private sealed class Ole32 { #pragma warning disable SA1310 // Field names should not contain underscore // https://docs.microsoft.com/windows/win32/api/wtypesbase/ne-wtypesbase-clsctx diff --git a/src/Logging/helpers/DictionaryExtensions.cs b/src/Logging/helpers/DictionaryExtensions.cs index fdc54273..b129aa2a 100644 --- a/src/Logging/helpers/DictionaryExtensions.cs +++ b/src/Logging/helpers/DictionaryExtensions.cs @@ -7,10 +7,7 @@ public static class DictionaryExtensions { public static void DisposeAll(this IDictionary dictionary) { - if (dictionary is null) - { - throw new ArgumentNullException(nameof(dictionary)); - } + ArgumentNullException.ThrowIfNull(dictionary); foreach (var kv in dictionary) { diff --git a/src/Telemetry/Logger.cs b/src/Telemetry/Logger.cs index 4f8275f3..fd688937 100644 --- a/src/Telemetry/Logger.cs +++ b/src/Telemetry/Logger.cs @@ -12,7 +12,7 @@ namespace GitHubExtension.Telemetry; -internal class Logger : ILogger +internal sealed class Logger : ILogger { private const string ProviderName = "Microsoft.GitHubExtension"; From d6d924a9a97d2e2d8da71eb0f8ce846ef5ced62c Mon Sep 17 00:00:00 2001 From: Agne Lukoseviciute Date: Thu, 28 Mar 2024 14:42:39 -0700 Subject: [PATCH 2/3] nit --- .../DataManager/GitHubDataManager.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/GitHubExtension/DataManager/GitHubDataManager.cs b/src/GitHubExtension/DataManager/GitHubDataManager.cs index ffe57a26..6591f30c 100644 --- a/src/GitHubExtension/DataManager/GitHubDataManager.cs +++ b/src/GitHubExtension/DataManager/GitHubDataManager.cs @@ -101,7 +101,7 @@ await UpdateDataForRepositoryAsync( await UpdatePullRequestsAsync(repository, devId.GitHubClient, parameters.RequestOptions); }); - SendRepositoryUpdateEvent(this, GetFullNameFromOwnerAndRepository(owner, name), IssuesAndPRsStringArray); + SendRepositoryUpdateEvent(this, GetFullNameFromOwnerAndRepository(owner, name), _IssuesAndPRs); } public async Task UpdateAllDataForRepositoryAsync(string fullName, RequestOptions? options = null) @@ -130,7 +130,7 @@ await UpdateDataForRepositoryAsync( await UpdatePullRequestsAsync(repository, devId.GitHubClient, parameters.RequestOptions); }); - SendRepositoryUpdateEvent(this, GetFullNameFromOwnerAndRepository(owner, name), PRsStringArray); + SendRepositoryUpdateEvent(this, GetFullNameFromOwnerAndRepository(owner, name), _PRs); } public async Task UpdatePullRequestsForRepositoryAsync(string fullName, RequestOptions? options = null) @@ -159,7 +159,7 @@ await UpdateDataForRepositoryAsync( await UpdateIssuesAsync(repository, devId.GitHubClient, parameters.RequestOptions); }); - SendRepositoryUpdateEvent(this, GetFullNameFromOwnerAndRepository(owner, name), IssuesStringArray); + SendRepositoryUpdateEvent(this, GetFullNameFromOwnerAndRepository(owner, name), _Issues); } public async Task UpdateIssuesForRepositoryAsync(string fullName, RequestOptions? options = null) @@ -199,7 +199,7 @@ await UpdateDataForRepositoryAsync( await UpdateReleasesAsync(repository, devId.GitHubClient, parameters.RequestOptions); }); - SendRepositoryUpdateEvent(this, GetFullNameFromOwnerAndRepository(owner, name), ReleasesStringArray); + SendRepositoryUpdateEvent(this, GetFullNameFromOwnerAndRepository(owner, name), _Releases); } public IEnumerable GetRepositories() @@ -839,10 +839,10 @@ private static DataStoreOptions DefaultOptionsInit() public override string ToString() => "GitHubDataManager"; private bool disposed; // To detect redundant calls. - private static readonly string[] IssuesAndPRsStringArray = new string[] { "Issues", "PullRequests" }; - private static readonly string[] PRsStringArray = new string[] { "PullRequests" }; - private static readonly string[] IssuesStringArray = new string[] { "Issues" }; - private static readonly string[] ReleasesStringArray = new string[] { "Releases" }; + private static readonly string[] _IssuesAndPRs = new string[] { "Issues", "PullRequests" }; + private static readonly string[] _PRs = new string[] { "PullRequests" }; + private static readonly string[] _Issues = new string[] { "Issues" }; + private static readonly string[] _Releases = new string[] { "Releases" }; protected virtual void Dispose(bool disposing) { From 121595f016b38ff0b6a8ae984079e4c307876d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agne=20Lukoseviciute=20=F0=9F=A6=8B?= Date: Thu, 11 Apr 2024 14:36:54 -0700 Subject: [PATCH 3/3] merge fix --- src/GitHubExtension/Widgets/WidgetImplFactory.cs | 2 +- src/GitHubExtension/Widgets/WidgetProvider.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/GitHubExtension/Widgets/WidgetImplFactory.cs b/src/GitHubExtension/Widgets/WidgetImplFactory.cs index d2664179..602a4f2e 100644 --- a/src/GitHubExtension/Widgets/WidgetImplFactory.cs +++ b/src/GitHubExtension/Widgets/WidgetImplFactory.cs @@ -7,7 +7,7 @@ namespace GitHubExtension.Widgets; [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649:File name should match first type name", Justification = "Templated class")] -internal class WidgetImplFactory : IWidgetImplFactory +internal sealed class WidgetImplFactory : IWidgetImplFactory where T : WidgetImpl, new() { public WidgetImpl Create(WidgetContext widgetContext, string state) diff --git a/src/GitHubExtension/Widgets/WidgetProvider.cs b/src/GitHubExtension/Widgets/WidgetProvider.cs index 97013609..16d523d9 100644 --- a/src/GitHubExtension/Widgets/WidgetProvider.cs +++ b/src/GitHubExtension/Widgets/WidgetProvider.cs @@ -34,7 +34,7 @@ private void InitializeWidget(WidgetContext widgetContext, string state) var widgetId = widgetContext.Id; var widgetDefinitionId = widgetContext.DefinitionId; _log.Verbose($"Calling Initialize for Widget Id: {widgetId} - {widgetDefinitionId}"); - if (widgetDefinitionRegistry.ContainsKey(widgetDefinitionId)) + if (widgetDefinitionRegistry.TryGetValue(widgetDefinitionId, out var widgetDefinition)) { if (!runningWidgets.ContainsKey(widgetId)) { @@ -112,7 +112,7 @@ public void Activate(WidgetContext widgetContext) public void Deactivate(string widgetId) { _log.Verbose($"Deactivate id: {widgetId}"); - if (runningWidgets.ContainsKey(widgetId)) + if (runningWidgets.TryGetValue(widgetId, out var widget)) { widget.Deactivate(widgetId); } @@ -121,7 +121,7 @@ public void Deactivate(string widgetId) public void DeleteWidget(string widgetId, string customState) { _log.Information($"DeleteWidget id: {widgetId}"); - if (runningWidgets.ContainsKey(widgetId)) + if (runningWidgets.TryGetValue(widgetId, out var widget)) { widget.DeleteWidget(widgetId, customState); runningWidgets.Remove(widgetId);