diff --git a/.editorconfig b/.editorconfig index 984a626..557eb2e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -47,7 +47,7 @@ csharp_space_between_method_declaration_parameter_list_parentheses = false #Formatting - wrapping options #leave code block on separate lines -csharp_preserve_single_line_blocks = false +csharp_preserve_single_line_blocks = true #Style - Code block preferences diff --git a/Directory.Build.props b/Directory.Build.props index b4a1e11..e293c53 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -32,7 +32,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/codeAnalysis/GlobalSuppressions.cs b/codeAnalysis/GlobalSuppressions.cs index 6adc7ff..3edd0bd 100644 --- a/codeAnalysis/GlobalSuppressions.cs +++ b/codeAnalysis/GlobalSuppressions.cs @@ -7,9 +7,6 @@ // a specific target and scoped to a namespace, type, member, etc. using System.Diagnostics.CodeAnalysis; -[assembly: SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1009:ClosingParenthesisMustBeSpacedCorrectly", Justification = "All current violations are due to Tuple shorthand and so valid.")] -[assembly: SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1011:ClosingSquareBracketsMustBeSpacedCorrectly", Justification = "Optional arrays need to be supported. Ex []?")] - [assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:PrefixLocalCallsWithThis", Justification = "We follow the C# Core Coding Style which avoids using `this` unless absolutely necessary.")] [assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1200:UsingDirectivesMustBePlacedWithinNamespace", Justification = "We follow the C# Core Coding Style which puts using statements outside the namespace.")] diff --git a/src/GitHubExtension/Client/Exceptions.cs b/src/GitHubExtension/Client/Exceptions.cs deleted file mode 100644 index ef04f59..0000000 --- a/src/GitHubExtension/Client/Exceptions.cs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -namespace GitHubExtension.Client; - -public class InvalidUrlException : Exception -{ - public InvalidUrlException() - { - } - - public InvalidUrlException(string message) - : base(message) - { - } -} - -public class InvalidGitHubUrlException : Exception -{ - public InvalidGitHubUrlException() - { - } - - public InvalidGitHubUrlException(string message) - : base(message) - { - } -} - -public class InvalidApiException : Exception -{ - public InvalidApiException() - { - } - - public InvalidApiException(string message) - : base(message) - { - } -} diff --git a/src/GitHubExtension/Client/GithubClientProvider.cs b/src/GitHubExtension/Client/GithubClientProvider.cs index 830bc53..bc53d0b 100644 --- a/src/GitHubExtension/Client/GithubClientProvider.cs +++ b/src/GitHubExtension/Client/GithubClientProvider.cs @@ -12,7 +12,7 @@ public class GitHubClientProvider { private readonly GitHubClient publicRepoClient; - private static readonly object InstanceLock = new (); + private static readonly object InstanceLock = new(); private static GitHubClientProvider? _instance; diff --git a/src/GitHubExtension/Client/InvalidApiException.cs b/src/GitHubExtension/Client/InvalidApiException.cs new file mode 100644 index 0000000..7354738 --- /dev/null +++ b/src/GitHubExtension/Client/InvalidApiException.cs @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace GitHubExtension.Client; + +public class InvalidApiException : Exception +{ + public InvalidApiException() + { + } + + public InvalidApiException(string message) + : base(message) + { + } +} diff --git a/src/GitHubExtension/Client/InvalidGitHubUrlException.cs b/src/GitHubExtension/Client/InvalidGitHubUrlException.cs new file mode 100644 index 0000000..2084491 --- /dev/null +++ b/src/GitHubExtension/Client/InvalidGitHubUrlException.cs @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace GitHubExtension.Client; + +public class InvalidGitHubUrlException : Exception +{ + public InvalidGitHubUrlException() + { + } + + public InvalidGitHubUrlException(string message) + : base(message) + { + } +} diff --git a/src/GitHubExtension/Client/InvalidUrlException.cs b/src/GitHubExtension/Client/InvalidUrlException.cs new file mode 100644 index 0000000..44d0bd1 --- /dev/null +++ b/src/GitHubExtension/Client/InvalidUrlException.cs @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace GitHubExtension.Client; + +public class InvalidUrlException : Exception +{ + public InvalidUrlException() + { + } + + public InvalidUrlException(string message) + : base(message) + { + } +} diff --git a/src/GitHubExtension/DataManager/Exceptions.cs b/src/GitHubExtension/DataManager/DataStoreInaccessibleException.cs similarity index 57% rename from src/GitHubExtension/DataManager/Exceptions.cs rename to src/GitHubExtension/DataManager/DataStoreInaccessibleException.cs index 3fd9078..d39f4f3 100644 --- a/src/GitHubExtension/DataManager/Exceptions.cs +++ b/src/GitHubExtension/DataManager/DataStoreInaccessibleException.cs @@ -3,18 +3,6 @@ namespace GitHubExtension; -public class RepositoryNotFoundException : ApplicationException -{ - public RepositoryNotFoundException() - { - } - - public RepositoryNotFoundException(string message) - : base(message) - { - } -} - public class DataStoreInaccessibleException : ApplicationException { public DataStoreInaccessibleException() diff --git a/src/GitHubExtension/DataManager/DataStoreOperationParameters.cs b/src/GitHubExtension/DataManager/DataStoreOperationParameters.cs index bb1a8c4..1fee039 100644 --- a/src/GitHubExtension/DataManager/DataStoreOperationParameters.cs +++ b/src/GitHubExtension/DataManager/DataStoreOperationParameters.cs @@ -1,9 +1,10 @@ -// Copyright (c) Microsoft Corporation. +// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using Microsoft.Windows.DevHome.SDK; namespace GitHubExtension; + public class DataStoreOperationParameters { // parameters for updating the data store. diff --git a/src/GitHubExtension/DataManager/GitHubDataManager.cs b/src/GitHubExtension/DataManager/GitHubDataManager.cs index c5b3ec3..d86299c 100644 --- a/src/GitHubExtension/DataManager/GitHubDataManager.cs +++ b/src/GitHubExtension/DataManager/GitHubDataManager.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. +// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using GitHubExtension.Client; @@ -763,7 +763,7 @@ private void ValidateDataStore() // Making the default options a singleton to avoid repeatedly calling the storage APIs and // creating a new GitHubDataStoreSchema when not necessary. - private static readonly Lazy LazyDataStoreOptions = new (DefaultOptionsInit); + private static readonly Lazy LazyDataStoreOptions = new(DefaultOptionsInit); private static DataStoreOptions DefaultOptions => LazyDataStoreOptions.Value; diff --git a/src/GitHubExtension/DataManager/RepositoryNotFoundException.cs b/src/GitHubExtension/DataManager/RepositoryNotFoundException.cs new file mode 100644 index 0000000..d72de9b --- /dev/null +++ b/src/GitHubExtension/DataManager/RepositoryNotFoundException.cs @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace GitHubExtension.DataManager; + +public class RepositoryNotFoundException : ApplicationException +{ + public RepositoryNotFoundException() + { + } + + public RepositoryNotFoundException(string message) + : base(message) + { + } +} diff --git a/src/GitHubExtension/DataModel/GitHubDataStoreSchema.cs b/src/GitHubExtension/DataModel/GitHubDataStoreSchema.cs index 13fe1dd..ffeb916 100644 --- a/src/GitHubExtension/DataModel/GitHubDataStoreSchema.cs +++ b/src/GitHubExtension/DataModel/GitHubDataStoreSchema.cs @@ -249,7 +249,7 @@ public GitHubDataStoreSchema() "CREATE UNIQUE INDEX IDX_Review_InternalId ON Review (InternalId);"; // All Sqls together. - private static readonly List SchemaSqlsValue = new () + private static readonly List SchemaSqlsValue = new() { Metadata, User, diff --git a/src/GitHubExtension/DataModel/Logging.cs b/src/GitHubExtension/DataModel/Log.cs similarity index 100% rename from src/GitHubExtension/DataModel/Logging.cs rename to src/GitHubExtension/DataModel/Log.cs diff --git a/src/GitHubExtension/DeveloperId/CredentialVault.cs b/src/GitHubExtension/DeveloperId/CredentialVault.cs index 99a678c..cfe453e 100644 --- a/src/GitHubExtension/DeveloperId/CredentialVault.cs +++ b/src/GitHubExtension/DeveloperId/CredentialVault.cs @@ -112,7 +112,7 @@ public void SaveCredentials(string loginId, SecureString? accessToken) Marshal.Copy(credentialObject.CredentialBlob, accessTokenInChars, 0, accessTokenInChars.Length); // convert accessTokenInChars to string - string accessTokenString = new (accessTokenInChars); + string accessTokenString = new(accessTokenInChars); for (var i = 0; i < accessTokenInChars.Length; i++) { diff --git a/src/GitHubExtension/DeveloperId/DeveloperId.cs b/src/GitHubExtension/DeveloperId/DeveloperId.cs index 48fd4e8..c085e0d 100644 --- a/src/GitHubExtension/DeveloperId/DeveloperId.cs +++ b/src/GitHubExtension/DeveloperId/DeveloperId.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. +// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using Microsoft.Windows.DevHome.SDK; @@ -26,7 +26,7 @@ public DeveloperId() DisplayName = string.Empty; Email = string.Empty; Url = string.Empty; - GitHubClient = new (new ProductHeaderValue(Constants.DEV_HOME_APPLICATION_NAME)); + GitHubClient = new(new ProductHeaderValue(Constants.DEV_HOME_APPLICATION_NAME)); } public DeveloperId(string loginId, string displayName, string email, string url, GitHubClient gitHubClient) @@ -65,7 +65,7 @@ public Windows.Security.Credentials.PasswordCredential RefreshDeveloperId() CredentialExpiryTime = DateTime.MaxValue; DeveloperIdProvider.GetInstance().RefreshDeveloperId(this); var credential = DeveloperIdProvider.GetInstance().GetCredentials(this) ?? throw new InvalidOperationException("Invalid credential present for valid DeveloperId"); - GitHubClient.Credentials = new (credential.Password); + GitHubClient.Credentials = new(credential.Password); return credential; } diff --git a/src/GitHubExtension/DeveloperId/DeveloperIdProvider.cs b/src/GitHubExtension/DeveloperId/DeveloperIdProvider.cs index 566949f..a47f67f 100644 --- a/src/GitHubExtension/DeveloperId/DeveloperIdProvider.cs +++ b/src/GitHubExtension/DeveloperId/DeveloperIdProvider.cs @@ -14,9 +14,9 @@ namespace GitHubExtension.DeveloperId; public class DeveloperIdProvider : IDeveloperIdProviderInternal { // Locks to control access to Singleton class members. - private static readonly object _developerIdsLock = new (); + private static readonly object _developerIdsLock = new(); - private static readonly object _oAuthRequestsLock = new (); + private static readonly object _oAuthRequestsLock = new(); // DeveloperId list containing all Logged in Ids. private List DeveloperIds @@ -39,7 +39,7 @@ private List OAuthRequests public string DisplayName => "GitHub"; // DeveloperIdProvider uses singleton pattern. - private static Lazy _singletonDeveloperIdProvider = new (() => new DeveloperIdProvider()); + private static Lazy _singletonDeveloperIdProvider = new(() => new DeveloperIdProvider()); public static DeveloperIdProvider GetInstance() { @@ -51,7 +51,7 @@ private DeveloperIdProvider() { Log.Logger()?.ReportInfo($"Creating DeveloperIdProvider singleton instance"); - _credentialVault = new (() => new CredentialVault()); + _credentialVault = new(() => new CredentialVault()); lock (_oAuthRequestsLock) { @@ -76,7 +76,7 @@ private DeveloperIdProvider() public DeveloperIdsResult GetLoggedInDeveloperIds() { - List iDeveloperIds = new (); + List iDeveloperIds = new(); lock (_developerIdsLock) { iDeveloperIds.AddRange(DeveloperIds); @@ -113,11 +113,11 @@ public DeveloperId LoginNewDeveloperIdWithPAT(Uri hostAddress, SecureString pers { try { - GitHubClient gitHubClient = new (new ProductHeaderValue(Constants.DEV_HOME_APPLICATION_NAME), hostAddress); + GitHubClient gitHubClient = new(new ProductHeaderValue(Constants.DEV_HOME_APPLICATION_NAME), hostAddress); var credentials = new Credentials(new System.Net.NetworkCredential(string.Empty, personalAccessToken).Password); gitHubClient.Credentials = credentials; var newUser = gitHubClient.User.Current().Result; - DeveloperId developerId = new (newUser.Login, newUser.Name, newUser.Email, newUser.Url, gitHubClient); + DeveloperId developerId = new(newUser.Login, newUser.Name, newUser.Email, newUser.Url, gitHubClient); SaveOrOverwriteDeveloperId(developerId, personalAccessToken); Log.Logger()?.ReportInfo($"{developerId.LoginId} logged in with PAT flow to {developerId.GetHostAddress()}"); @@ -133,7 +133,7 @@ public DeveloperId LoginNewDeveloperIdWithPAT(Uri hostAddress, SecureString pers private OAuthRequest? LoginNewDeveloperId() { - OAuthRequest oauthRequest = new (); + OAuthRequest oauthRequest = new(); lock (_oAuthRequestsLock) { @@ -222,7 +222,7 @@ public void HandleOauthRedirection(Uri authorizationResponse) public IEnumerable GetLoggedInDeveloperIdsInternal() { - List iDeveloperIds = new (); + List iDeveloperIds = new(); lock (_developerIdsLock) { iDeveloperIds.AddRange(DeveloperIds); @@ -321,15 +321,15 @@ private void RestoreDeveloperIds(IEnumerable loginIdsAndUrls) // For loginIds without URL, use GitHub.com as default. var hostAddress = isUrl ? new Uri(loginIdOrUrl) : new Uri(Constants.GITHUB_COM_URL); - GitHubClient gitHubClient = new (new ProductHeaderValue(Constants.DEV_HOME_APPLICATION_NAME), hostAddress) + GitHubClient gitHubClient = new(new ProductHeaderValue(Constants.DEV_HOME_APPLICATION_NAME), hostAddress) { - Credentials = new (_credentialVault.Value.GetCredentials(loginIdOrUrl)?.Password), + Credentials = new(_credentialVault.Value.GetCredentials(loginIdOrUrl)?.Password), }; try { var user = gitHubClient.User.Current().Result; - DeveloperId developerId = new (user.Login, user.Name, user.Email, user.Url, gitHubClient); + DeveloperId developerId = new(user.Login, user.Name, user.Email, user.Url, gitHubClient); lock (_developerIdsLock) { DeveloperIds.Add(developerId); @@ -396,7 +396,7 @@ public void Dispose() // This function is to be used for testing purposes only. public static void ResetInstanceForTests() { - _singletonDeveloperIdProvider = new (() => new DeveloperIdProvider()); + _singletonDeveloperIdProvider = new(() => new DeveloperIdProvider()); } public IAsyncOperation ShowLogonSession(WindowId windowHandle) => throw new NotImplementedException(); diff --git a/src/GitHubExtension/DeveloperId/Logging.cs b/src/GitHubExtension/DeveloperId/Log.cs similarity index 100% rename from src/GitHubExtension/DeveloperId/Logging.cs rename to src/GitHubExtension/DeveloperId/Log.cs diff --git a/src/GitHubExtension/DeveloperId/OAuthRequest.cs b/src/GitHubExtension/DeveloperId/OAuthRequest.cs index 826fd6e..2c0d390 100644 --- a/src/GitHubExtension/DeveloperId/OAuthRequest.cs +++ b/src/GitHubExtension/DeveloperId/OAuthRequest.cs @@ -23,8 +23,8 @@ internal DateTime StartTime internal OAuthRequest() { - gitHubClient = new (new ProductHeaderValue(Constants.DEV_HOME_APPLICATION_NAME)); - oAuthCompleted = new (0); + gitHubClient = new(new ProductHeaderValue(Constants.DEV_HOME_APPLICATION_NAME)); + oAuthCompleted = new(0); State = string.Empty; } @@ -133,7 +133,7 @@ internal DeveloperId RetrieveDeveloperId() } var newUser = gitHubClient.User.Current().Result; - DeveloperId developerId = new (newUser.Login, newUser.Name, newUser.Email, newUser.Url, gitHubClient); + DeveloperId developerId = new(newUser.Login, newUser.Name, newUser.Email, newUser.Url, gitHubClient); return developerId; } diff --git a/src/GitHubExtension/Helpers/EnumHelper.cs b/src/GitHubExtension/Helpers/EnumHelper.cs index e0db3c4..f7d3500 100644 --- a/src/GitHubExtension/Helpers/EnumHelper.cs +++ b/src/GitHubExtension/Helpers/EnumHelper.cs @@ -12,7 +12,7 @@ public class EnumHelper SearchCategory.Issues => "Issues", SearchCategory.PullRequests => "PullRequests", SearchCategory.IssuesAndPullRequests => "IssuesAndPullRequests", - _ => "unknown" + _ => "unknown", }; public static SearchCategory StringToSearchCategory(string value) diff --git a/src/GitHubExtension/Helpers/IconLoader.cs b/src/GitHubExtension/Helpers/IconLoader.cs index c6a1764..e10fe37 100644 --- a/src/GitHubExtension/Helpers/IconLoader.cs +++ b/src/GitHubExtension/Helpers/IconLoader.cs @@ -7,7 +7,7 @@ namespace GitHubExtension.Helpers; public class IconLoader { - private static readonly Dictionary Base64ImageRegistry = new (); + private static readonly Dictionary Base64ImageRegistry = new(); public static string GetIconAsBase64(string filename) { diff --git a/src/GitHubExtension/Notifications/Logging.cs b/src/GitHubExtension/Notifications/Log.cs similarity index 100% rename from src/GitHubExtension/Notifications/Logging.cs rename to src/GitHubExtension/Notifications/Log.cs diff --git a/src/GitHubExtension/Providers/Logging.cs b/src/GitHubExtension/Providers/Log.cs similarity index 100% rename from src/GitHubExtension/Providers/Logging.cs rename to src/GitHubExtension/Providers/Log.cs diff --git a/src/GitHubExtension/Providers/RepositoryProvider.cs b/src/GitHubExtension/Providers/RepositoryProvider.cs index 47b1fc2..d3895c4 100644 --- a/src/GitHubExtension/Providers/RepositoryProvider.cs +++ b/src/GitHubExtension/Providers/RepositoryProvider.cs @@ -64,7 +64,7 @@ IAsyncOperation IRepositoryProvider.GetRepositoriesAsync(IDe var repositoryList = new List(); try { - ApiOptions apiOptions = new () + ApiOptions apiOptions = new() { PageSize = 50, PageCount = 1, diff --git a/src/GitHubExtension/Providers/SettingsUIController.cs b/src/GitHubExtension/Providers/SettingsUIController.cs index 6c8cfa3..a4b6fa7 100644 --- a/src/GitHubExtension/Providers/SettingsUIController.cs +++ b/src/GitHubExtension/Providers/SettingsUIController.cs @@ -13,7 +13,7 @@ internal class SettingsUIController : IExtensionAdaptiveCardSession private static readonly string _notificationsEnabledString = "NotificationsEnabled"; private IExtensionAdaptiveCard? _settingsUI; - private static readonly SettingsUITemplate _settingsUITemplate = new (); + private static readonly SettingsUITemplate _settingsUITemplate = new(); public void Dispose() { diff --git a/src/GitHubExtension/Widgets/GitHubPullsWidget.cs b/src/GitHubExtension/Widgets/GitHubPullsWidget.cs index df5362d..18f4875 100644 --- a/src/GitHubExtension/Widgets/GitHubPullsWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubPullsWidget.cs @@ -14,7 +14,7 @@ internal class GitHubPullsWidget : GitHubRepositoryWidget { private readonly string pullsIconData = IconLoader.GetIconAsBase64("pulls.png"); - private static Dictionary Templates { get; set; } = new (); + private static Dictionary Templates { get; set; } = new(); protected static readonly new string Name = nameof(GitHubPullsWidget); diff --git a/src/GitHubExtension/Widgets/GitHubWidget.cs b/src/GitHubExtension/Widgets/GitHubWidget.cs index dc20840..341fabf 100644 --- a/src/GitHubExtension/Widgets/GitHubWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubWidget.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. +// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System.Text; @@ -34,7 +34,7 @@ public abstract class GitHubWidget : WidgetImpl protected bool Saved { get; set; } - protected Dictionary Template { get; set; } = new (); + protected Dictionary Template { get; set; } = new(); protected string ConfigurationData { @@ -231,7 +231,7 @@ public virtual void UpdateActivityState() public void UpdateWidget() { - WidgetUpdateRequestOptions updateOptions = new (Id) + WidgetUpdateRequestOptions updateOptions = new(Id) { Data = GetData(Page), Template = GetTemplateForPage(Page), diff --git a/src/GitHubExtension/Widgets/Logging.cs b/src/GitHubExtension/Widgets/Log.cs similarity index 100% rename from src/GitHubExtension/Widgets/Logging.cs rename to src/GitHubExtension/Widgets/Log.cs diff --git a/src/GitHubExtension/Widgets/WidgetImplFactory.cs b/src/GitHubExtension/Widgets/WidgetImplFactory`1.cs similarity index 100% rename from src/GitHubExtension/Widgets/WidgetImplFactory.cs rename to src/GitHubExtension/Widgets/WidgetImplFactory`1.cs diff --git a/src/GitHubExtension/Widgets/WidgetProvider.cs b/src/GitHubExtension/Widgets/WidgetProvider.cs index 74dce35..a275f4e 100644 --- a/src/GitHubExtension/Widgets/WidgetProvider.cs +++ b/src/GitHubExtension/Widgets/WidgetProvider.cs @@ -27,8 +27,8 @@ public WidgetProvider() Log.Logger()?.Dispose(); } - private readonly Dictionary widgetDefinitionRegistry = new (); - private readonly Dictionary runningWidgets = new (); + private readonly Dictionary widgetDefinitionRegistry = new(); + private readonly Dictionary runningWidgets = new(); private void InitializeWidget(WidgetContext widgetContext, string state) { diff --git a/src/GitHubExtension/Widgets/WidgetProviderFactory.cs b/src/GitHubExtension/Widgets/WidgetProviderFactory`1.cs similarity index 100% rename from src/GitHubExtension/Widgets/WidgetProviderFactory.cs rename to src/GitHubExtension/Widgets/WidgetProviderFactory`1.cs diff --git a/src/GitHubExtension/Widgets/WidgetServer.cs b/src/GitHubExtension/Widgets/WidgetServer.cs index 28a526c..3cb7146 100644 --- a/src/GitHubExtension/Widgets/WidgetServer.cs +++ b/src/GitHubExtension/Widgets/WidgetServer.cs @@ -10,7 +10,7 @@ namespace GitHubExtension.Widgets; public sealed class WidgetServer : IDisposable { - private readonly HashSet registrationCookies = new (); + private readonly HashSet registrationCookies = new(); [UnconditionalSuppressMessage( "ReflectionAnalysis", diff --git a/src/GitHubExtensionServer/Logging.cs b/src/GitHubExtensionServer/Log.cs similarity index 100% rename from src/GitHubExtensionServer/Logging.cs rename to src/GitHubExtensionServer/Log.cs diff --git a/src/Logging/listeners/StdoutListener.cs b/src/Logging/listeners/StdoutListener.cs index c8e8954..7f80c01 100644 --- a/src/Logging/listeners/StdoutListener.cs +++ b/src/Logging/listeners/StdoutListener.cs @@ -19,7 +19,7 @@ public class StdoutListener : ListenerBase // Static lock object so different instances of the Stdout listener do not simultaneously write // to stdout and have interleaved tearing of messages. - private static readonly object _stdoutLock = new (); + private static readonly object _stdoutLock = new(); public StdoutListener(string name) : base(name) diff --git a/src/Logging/logger/SeverityLevel.cs b/src/Logging/logger/FailFast.cs similarity index 100% rename from src/Logging/logger/SeverityLevel.cs rename to src/Logging/logger/FailFast.cs diff --git a/src/Logging/logger/LogEvent.cs b/src/Logging/logger/LogEvent.cs index a555a41..b1ef61d 100644 --- a/src/Logging/logger/LogEvent.cs +++ b/src/Logging/logger/LogEvent.cs @@ -47,7 +47,7 @@ public TimeSpan Elapsed public static long NoElapsedTicks => -1L; - public static TimeSpan NoElapsed => new (NoElapsedTicks); + public static TimeSpan NoElapsed => new(NoElapsedTicks); public bool HasElapsed => Elapsed.Ticks >= 0; @@ -68,7 +68,7 @@ private LogEvent(string source, string subSource, SeverityLevel severity, string public static LogEvent Create(string source, string subSource, SeverityLevel severity, string message, TimeSpan elapsed) => Create(source, subSource, severity, message, null, elapsed); - public static LogEvent Create(string source, string subSource, SeverityLevel severity, string message, Exception? exception, TimeSpan elapsed) => new (source, subSource, severity, message, exception!, elapsed); + public static LogEvent Create(string source, string subSource, SeverityLevel severity, string message, Exception? exception, TimeSpan elapsed) => new(source, subSource, severity, message, exception!, elapsed); public string FullSourceName { diff --git a/src/Logging/logger/Logger.cs b/src/Logging/logger/Logger.cs index 1601c2a..932c79d 100644 --- a/src/Logging/logger/Logger.cs +++ b/src/Logging/logger/Logger.cs @@ -45,9 +45,9 @@ public Logger(string name, Options options) Dispose(); } - private readonly BlockingCollection eventQueue = new (new ConcurrentQueue()); + private readonly BlockingCollection eventQueue = new(new ConcurrentQueue()); - private readonly ManualResetEvent processorCanceledEvent = new (true); + private readonly ManualResetEvent processorCanceledEvent = new(true); private CancellationTokenSource? cancelTokenSource; diff --git a/src/Telemetry/Logger.cs b/src/Telemetry/Logger.cs index 21af0ee..4f8275f 100644 --- a/src/Telemetry/Logger.cs +++ b/src/Telemetry/Logger.cs @@ -37,48 +37,48 @@ internal class Logger : ILogger /// Logs telemetry locally, but shouldn't upload it. Similar to an ETW event. /// Should be the same as EventSourceOptions(), as Verbose is the default level. /// - private static readonly EventSourceOptions LocalOption = new () { Level = EventLevel.Verbose }; + private static readonly EventSourceOptions LocalOption = new() { Level = EventLevel.Verbose }; /// /// Logs error telemetry locally, but shouldn't upload it. Similar to an ETW event. /// - private static readonly EventSourceOptions LocalErrorOption = new () { Level = EventLevel.Error }; + private static readonly EventSourceOptions LocalErrorOption = new() { Level = EventLevel.Error }; /// /// Logs telemetry. /// Currently this is at 0% sampling for both internal and external retail devices. /// - private static readonly EventSourceOptions InfoOption = new () { Keywords = TelemetryEventSource.TelemetryKeyword }; + private static readonly EventSourceOptions InfoOption = new() { Keywords = TelemetryEventSource.TelemetryKeyword }; /// /// Logs error telemetry. /// Currently this is at 0% sampling for both internal and external retail devices. /// - private static readonly EventSourceOptions InfoErrorOption = new () { Level = EventLevel.Error, Keywords = TelemetryEventSource.TelemetryKeyword }; + private static readonly EventSourceOptions InfoErrorOption = new() { Level = EventLevel.Error, Keywords = TelemetryEventSource.TelemetryKeyword }; /// /// Logs measure telemetry. /// This should be sent back on internal devices, and a small, sampled % of external retail devices. /// - private static readonly EventSourceOptions MeasureOption = new () { Keywords = TelemetryEventSource.MeasuresKeyword }; + private static readonly EventSourceOptions MeasureOption = new() { Keywords = TelemetryEventSource.MeasuresKeyword }; /// /// Logs measure error telemetry. /// This should be sent back on internal devices, and a small, sampled % of external retail devices. /// - private static readonly EventSourceOptions MeasureErrorOption = new () { Level = EventLevel.Error, Keywords = TelemetryEventSource.MeasuresKeyword }; + private static readonly EventSourceOptions MeasureErrorOption = new() { Level = EventLevel.Error, Keywords = TelemetryEventSource.MeasuresKeyword }; /// /// Logs critical telemetry. /// This should be sent back on all devices sampled at 100%. /// - private static readonly EventSourceOptions CriticalDataOption = new () { Keywords = TelemetryEventSource.CriticalDataKeyword }; + private static readonly EventSourceOptions CriticalDataOption = new() { Keywords = TelemetryEventSource.CriticalDataKeyword }; /// /// Logs critical error telemetry. /// This should be sent back on all devices sampled at 100%. /// - private static readonly EventSourceOptions CriticalDataErrorOption = new () { Level = EventLevel.Error, Keywords = TelemetryEventSource.CriticalDataKeyword }; + private static readonly EventSourceOptions CriticalDataErrorOption = new() { Level = EventLevel.Error, Keywords = TelemetryEventSource.CriticalDataKeyword }; /// /// ActivityId so we can correlate all events in the same run @@ -88,7 +88,7 @@ internal class Logger : ILogger /// /// List of strings we should try removing for sensitivity reasons. /// - private readonly List> sensitiveStrings = new (); + private readonly List> sensitiveStrings = new(); /// /// Initializes a new instance of the class. diff --git a/src/Telemetry/LoggerFactory.cs b/src/Telemetry/LoggerFactory.cs index 600c85a..8aa3ea9 100644 --- a/src/Telemetry/LoggerFactory.cs +++ b/src/Telemetry/LoggerFactory.cs @@ -8,7 +8,7 @@ namespace GitHubExtension.Telemetry; /// This would be useful for future when we have updated interfaces for logger like ILogger2, ILogger3 and so on public class LoggerFactory { - private static readonly object LockObj = new (); + private static readonly object LockObj = new(); private static Logger loggerInstance; diff --git a/test/GitHubExtension/DataStore/DataStoreTestsSetup.cs b/test/GitHubExtension/DataStore/DataStoreTestsSetup.cs index 45e5b77..407cbc1 100644 --- a/test/GitHubExtension/DataStore/DataStoreTestsSetup.cs +++ b/test/GitHubExtension/DataStore/DataStoreTestsSetup.cs @@ -12,7 +12,7 @@ public TestContext? TestContext set; } - private TestOptions testOptions = new (); + private TestOptions testOptions = new(); private TestOptions TestOptions { diff --git a/test/GitHubExtension/DeveloperId/DeveloperIdTestsSetup.cs b/test/GitHubExtension/DeveloperId/DeveloperIdTestsSetup.cs index 950d82e..c0a0e8d 100644 --- a/test/GitHubExtension/DeveloperId/DeveloperIdTestsSetup.cs +++ b/test/GitHubExtension/DeveloperId/DeveloperIdTestsSetup.cs @@ -42,7 +42,7 @@ public TestContext? TestContext set; } - private TestOptions testOptions = new (); + private TestOptions testOptions = new(); private TestOptions TestOptions { diff --git a/test/GitHubExtension/MockExtensionAdaptiveCard.cs b/test/GitHubExtension/MockExtensionAdaptiveCard.cs new file mode 100644 index 0000000..581eff5 --- /dev/null +++ b/test/GitHubExtension/MockExtensionAdaptiveCard.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using Microsoft.Windows.DevHome.SDK; + +namespace GitHubExtension.Test; + +public class MockExtensionAdaptiveCard : IExtensionAdaptiveCard +{ + private int updateCount; + + public int UpdateCount + { + get => updateCount; + set => updateCount = value; + } + + public MockExtensionAdaptiveCard(string templateJson, string dataJson, string state) + { + TemplateJson = templateJson; + DataJson = dataJson; + State = state; + } + + public string DataJson + { + get; set; + } + + public string State + { + get; set; + } + + public string TemplateJson + { + get; set; + } + + public ProviderOperationResult Update(string templateJson, string dataJson, string state) + { + UpdateCount++; + TemplateJson = templateJson; + DataJson = dataJson; + State = state; + return new ProviderOperationResult(ProviderOperationStatus.Success, null, "Update() succeeded", "Update() succeeded"); + } +} diff --git a/test/GitHubExtension/Mocks/DeveloperIdProvider.cs b/test/GitHubExtension/Mocks/MockDeveloperIdProvider.cs similarity index 69% rename from test/GitHubExtension/Mocks/DeveloperIdProvider.cs rename to test/GitHubExtension/Mocks/MockDeveloperIdProvider.cs index 4800dfe..63b7b6b 100644 --- a/test/GitHubExtension/Mocks/DeveloperIdProvider.cs +++ b/test/GitHubExtension/Mocks/MockDeveloperIdProvider.cs @@ -27,7 +27,7 @@ public void Dispose() public AuthenticationState GetDeveloperIdState(IDeveloperId developerId) => throw new NotImplementedException(); - public DeveloperIdsResult GetLoggedInDeveloperIds() => new (new List()); + public DeveloperIdsResult GetLoggedInDeveloperIds() => new(new List()); public AdaptiveCardSessionResult GetLoginAdaptiveCardSession() => throw new NotImplementedException(); @@ -69,45 +69,3 @@ public static MockDeveloperIdProvider GetInstance() public IEnumerable GetLoggedInDeveloperIdsInternal() => new List(); } - -public class MockExtensionAdaptiveCard : IExtensionAdaptiveCard -{ - private int updateCount; - - public int UpdateCount - { - get => updateCount; - set => updateCount = value; - } - - public MockExtensionAdaptiveCard(string templateJson, string dataJson, string state) - { - TemplateJson = templateJson; - DataJson = dataJson; - State = state; - } - - public string DataJson - { - get; set; - } - - public string State - { - get; set; - } - - public string TemplateJson - { - get; set; - } - - public ProviderOperationResult Update(string templateJson, string dataJson, string state) - { - UpdateCount++; - TemplateJson = templateJson; - DataJson = dataJson; - State = state; - return new ProviderOperationResult(ProviderOperationStatus.Success, null, "Update() succeeded", "Update() succeeded"); - } -} diff --git a/test/GitHubExtension/Mocks/Repository.cs b/test/GitHubExtension/Mocks/MockRepository.cs similarity index 100% rename from test/GitHubExtension/Mocks/Repository.cs rename to test/GitHubExtension/Mocks/MockRepository.cs diff --git a/test/GitHubExtension/TestClass.cs b/test/GitHubExtension/TestClass.cs index 1bb75d5..e86ec9d 100644 --- a/test/GitHubExtension/TestClass.cs +++ b/test/GitHubExtension/TestClass.cs @@ -50,7 +50,7 @@ private static void RemoveTestRepo() } } - private static readonly Semaphore AuthenticationEventTriggered = new (initialCount: 0, maximumCount: 1); + private static readonly Semaphore AuthenticationEventTriggered = new(initialCount: 0, maximumCount: 1); public void AuthenticationEvent(object? sender, IDeveloperId developerId) { diff --git a/test/GitHubExtension/Widgets/WidgetTestsSetup.cs b/test/GitHubExtension/Widgets/WidgetTestsSetup.cs index a6eb4c8..a699992 100644 --- a/test/GitHubExtension/Widgets/WidgetTestsSetup.cs +++ b/test/GitHubExtension/Widgets/WidgetTestsSetup.cs @@ -12,7 +12,7 @@ public TestContext? TestContext set; } - private TestOptions testOptions = new (); + private TestOptions testOptions = new(); private TestOptions TestOptions {