diff --git a/.editorconfig b/.editorconfig index ecb4b86..984a626 100644 --- a/.editorconfig +++ b/.editorconfig @@ -4,6 +4,8 @@ [*.cs] +file_header_template = Copyright (c) Microsoft Corporation.\r\nLicensed under the MIT License. + #Core editorconfig formatting - indentation #use soft tabs (spaces) for indentation diff --git a/GitHubExtension.sln b/GitHubExtension.sln index 4082b7e..8e7e8aa 100644 --- a/GitHubExtension.sln +++ b/GitHubExtension.sln @@ -48,6 +48,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{E4D6 test\scripts\CleanWidgets.ps1 = test\scripts\CleanWidgets.ps1 EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{864DD9CD-9F45-47E8-847F-B72ED182626B}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + exclusion.dic = exclusion.dic + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/build/scripts/Build.ps1 b/build/scripts/Build.ps1 index 4ae8b97..dab04cd 100644 --- a/build/scripts/Build.ps1 +++ b/build/scripts/Build.ps1 @@ -14,7 +14,7 @@ $StartTime = Get-Date if ($Help) { Write-Host @" -Copyright (c) Microsoft Corporation and Contributors. +Copyright (c) Microsoft Corporation. Licensed under the MIT License. Syntax: diff --git a/build/scripts/Test.ps1 b/build/scripts/Test.ps1 index d637b44..b52c976 100644 --- a/build/scripts/Test.ps1 +++ b/build/scripts/Test.ps1 @@ -9,7 +9,7 @@ $StartTime = Get-Date if ($Help) { Write-Host @" -Copyright (c) Microsoft Corporation and Contributors. +Copyright (c) Microsoft Corporation. Licensed under the MIT License. Syntax: diff --git a/codeAnalysis/GlobalSuppressions.cs b/codeAnalysis/GlobalSuppressions.cs index 303231c..6adc7ff 100644 --- a/codeAnalysis/GlobalSuppressions.cs +++ b/codeAnalysis/GlobalSuppressions.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. // This file is used by Code Analysis to maintain SuppressMessage // attributes that are applied to this project. @@ -13,10 +13,10 @@ [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.")] -[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1201:ElementsMustAppearInTheCorrectOrder", Justification = "It is not a priority and have hight impact in code changes.")] -[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1202:ElementsMustBeOrderedByAccess", Justification = "It is not a priority and have hight impact in code changes.")] -[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1203:ConstantsMustAppearBeforeFields", Justification = "It is not a priority and have hight impact in code changes.")] -[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1204:StaticElementsMustAppearBeforeInstanceElements", Justification = "It is not a priority and have hight impact in code changes.")] +[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1201:ElementsMustAppearInTheCorrectOrder", Justification = "It is not a priority and has high impact in code changes.")] +[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1202:ElementsMustBeOrderedByAccess", Justification = "It is not a priority and has high impact in code changes.")] +[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1203:ConstantsMustAppearBeforeFields", Justification = "It is not a priority and has high impact in code changes.")] +[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1204:StaticElementsMustAppearBeforeInstanceElements", Justification = "It is not a priority and has high impact in code changes.")] [assembly: SuppressMessage("StyleCop.CSharp.NamingRules", "SA1309:FieldNamesMustNotBeginWithUnderscore", Justification = "We follow the C# Core Coding Style which uses underscores as prefixes rather than using `this.`.")] diff --git a/codeAnalysis/StyleCop.json b/codeAnalysis/StyleCop.json index bb7d02c..f13fa14 100644 --- a/codeAnalysis/StyleCop.json +++ b/codeAnalysis/StyleCop.json @@ -3,7 +3,7 @@ "settings": { "documentationRules": { "companyName": "Microsoft Corporation", - "copyrightText": "Copyright (c) Microsoft Corporation and Contributors\r\nLicensed under the MIT license.", + "copyrightText": "Copyright (c) Microsoft Corporation.\r\nLicensed under the MIT License.", "xmlHeader": false, "headerDecoration": "", "fileNamingConvention": "metadata", diff --git a/exclusion.dic b/exclusion.dic index d0e2204..548f38a 100644 --- a/exclusion.dic +++ b/exclusion.dic @@ -1 +1,14 @@ devhome +enums +Octokit +advapi +Urls +Dependabot +github.com +inlines +abcd +Doggos +Stringify +riid +Impl +microsoft diff --git a/src/GitHubExtension/Client/Exceptions.cs b/src/GitHubExtension/Client/Exceptions.cs index bf26512..44b5f99 100644 --- a/src/GitHubExtension/Client/Exceptions.cs +++ b/src/GitHubExtension/Client/Exceptions.cs @@ -1,7 +1,8 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace GitHubExtension.Client; -namespace GitHubExtension.Client; public class InvalidUrlException : Exception { public InvalidUrlException() diff --git a/src/GitHubExtension/Client/GithubClientProvider.cs b/src/GitHubExtension/Client/GithubClientProvider.cs index 02cd910..830bc53 100644 --- a/src/GitHubExtension/Client/GithubClientProvider.cs +++ b/src/GitHubExtension/Client/GithubClientProvider.cs @@ -1,99 +1,99 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. - -using DevHome.Logging.Helpers; -using GitHubExtension.DeveloperId; +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using DevHome.Logging.Helpers; +using GitHubExtension.DeveloperId; using Microsoft.Windows.DevHome.SDK; -using Octokit; - -namespace GitHubExtension.Client; - -public class GitHubClientProvider -{ - private readonly GitHubClient publicRepoClient; - - private static readonly object InstanceLock = new (); - - private static GitHubClientProvider? _instance; - - public static GitHubClientProvider Instance - { - get - { - if (_instance == null) - { - lock (InstanceLock) - { - _instance = new GitHubClientProvider(); - } - } - - return _instance; - } - } - - public GitHubClientProvider() - { - publicRepoClient = new GitHubClient(new ProductHeaderValue(Constants.DEV_HOME_APPLICATION_NAME)); - } - - public GitHubClient? GetClient(IDeveloperId devId) - { - var devIdInternal = DeveloperIdProvider.GetInstance().GetDeveloperIdInternal(devId) ?? throw new ArgumentException(devId.LoginId); - return devIdInternal.GitHubClient; - } - - public GitHubClient GetClient(string url) - { - var devIdInternal = DeveloperIdProvider.GetInstance().GetLoggedInDeveloperIdsInternal().Where(i => i.Url.Equals(url, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); - if (devIdInternal == null) - { - return publicRepoClient; - } - - return devIdInternal.GitHubClient; - } - - public GitHubClient GetClient() - { - return publicRepoClient; - } - - public async Task GetClientForLoggedInDeveloper(bool logRateLimit = false) - { - var authProvider = DeveloperIdProvider.GetInstance(); - var devIds = authProvider.GetLoggedInDeveloperIdsInternal(); - GitHubClient client; - if (devIds == null || !devIds.Any()) - { - Log.Logger()?.ReportInfo($"No logged in developer, using public GitHub client."); - client = Instance.GetClient(); - } - else - { - Log.Logger()?.ReportInfo($"Using authenticated user: {devIds.First().LoginId}"); - client = devIds.First().GitHubClient; - } - - if (client == null) - { - Log.Logger()?.ReportError($"Failed creating GitHubClient."); - return client!; - } - - if (logRateLimit) +using Octokit; + +namespace GitHubExtension.Client; + +public class GitHubClientProvider +{ + private readonly GitHubClient publicRepoClient; + + private static readonly object InstanceLock = new (); + + private static GitHubClientProvider? _instance; + + public static GitHubClientProvider Instance + { + get + { + if (_instance == null) + { + lock (InstanceLock) + { + _instance = new GitHubClientProvider(); + } + } + + return _instance; + } + } + + public GitHubClientProvider() + { + publicRepoClient = new GitHubClient(new ProductHeaderValue(Constants.DEV_HOME_APPLICATION_NAME)); + } + + public GitHubClient? GetClient(IDeveloperId devId) + { + var devIdInternal = DeveloperIdProvider.GetInstance().GetDeveloperIdInternal(devId) ?? throw new ArgumentException(devId.LoginId); + return devIdInternal.GitHubClient; + } + + public GitHubClient GetClient(string url) + { + var devIdInternal = DeveloperIdProvider.GetInstance().GetLoggedInDeveloperIdsInternal().Where(i => i.Url.Equals(url, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); + if (devIdInternal == null) + { + return publicRepoClient; + } + + return devIdInternal.GitHubClient; + } + + public GitHubClient GetClient() + { + return publicRepoClient; + } + + public async Task GetClientForLoggedInDeveloper(bool logRateLimit = false) + { + var authProvider = DeveloperIdProvider.GetInstance(); + var devIds = authProvider.GetLoggedInDeveloperIdsInternal(); + GitHubClient client; + if (devIds == null || !devIds.Any()) + { + Log.Logger()?.ReportInfo($"No logged in developer, using public GitHub client."); + client = Instance.GetClient(); + } + else + { + Log.Logger()?.ReportInfo($"Using authenticated user: {devIds.First().LoginId}"); + client = devIds.First().GitHubClient; + } + + if (client == null) + { + Log.Logger()?.ReportError($"Failed creating GitHubClient."); + return client!; + } + + if (logRateLimit) { try { var miscRateLimit = await client.RateLimit.GetRateLimits(); Log.Logger()?.ReportInfo($"Rate Limit: Remaining: {miscRateLimit.Resources.Core.Remaining} Total: {miscRateLimit.Resources.Core.Limit} Resets: {miscRateLimit.Resources.Core.Reset.ToStringInvariant()}"); - } + } catch (Exception ex) { Log.Logger()?.ReportError($"Rate limiting not enabled for server.", ex); - } - } - - return client; - } -} + } + } + + return client; + } +} diff --git a/src/GitHubExtension/Client/Validation.cs b/src/GitHubExtension/Client/Validation.cs index d38bde4..24f14d5 100644 --- a/src/GitHubExtension/Client/Validation.cs +++ b/src/GitHubExtension/Client/Validation.cs @@ -1,5 +1,6 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + using GitHubExtension.DataModel; using Octokit; diff --git a/src/GitHubExtension/Configuration/DeveloperOAuthConfiguration.cs b/src/GitHubExtension/Configuration/DeveloperOAuthConfiguration.cs index 040da66..1eb28a6 100644 --- a/src/GitHubExtension/Configuration/DeveloperOAuthConfiguration.cs +++ b/src/GitHubExtension/Configuration/DeveloperOAuthConfiguration.cs @@ -1,7 +1,8 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension; + internal static class DeveloperOAuthConfiguration { //// Follow this link https://docs.github.com/en/developers/apps/building-oauth-apps/creating-an-oauth-app diff --git a/src/GitHubExtension/Configuration/OAuthConfiguration.cs b/src/GitHubExtension/Configuration/OAuthConfiguration.cs index 14f1d7b..45841ba 100644 --- a/src/GitHubExtension/Configuration/OAuthConfiguration.cs +++ b/src/GitHubExtension/Configuration/OAuthConfiguration.cs @@ -1,7 +1,8 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension; + internal static class OauthConfiguration { // This redirect url has to be configured into the OAuth app. This package has "devhome://" diff --git a/src/GitHubExtension/Constants.cs b/src/GitHubExtension/Constants.cs index bdac2e0..3728442 100644 --- a/src/GitHubExtension/Constants.cs +++ b/src/GitHubExtension/Constants.cs @@ -1,7 +1,8 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension; + internal class Constants { #pragma warning disable SA1310 // Field names should not contain underscore diff --git a/src/GitHubExtension/DataManager/DataManagerUpdateEventArgs.cs b/src/GitHubExtension/DataManager/DataManagerUpdateEventArgs.cs index b42abed..25d468c 100644 --- a/src/GitHubExtension/DataManager/DataManagerUpdateEventArgs.cs +++ b/src/GitHubExtension/DataManager/DataManagerUpdateEventArgs.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension.DataManager; diff --git a/src/GitHubExtension/DataManager/DataStoreOperationParameters.cs b/src/GitHubExtension/DataManager/DataStoreOperationParameters.cs index 07f6b5a..bb1a8c4 100644 --- a/src/GitHubExtension/DataManager/DataStoreOperationParameters.cs +++ b/src/GitHubExtension/DataManager/DataStoreOperationParameters.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Microsoft.Windows.DevHome.SDK; diff --git a/src/GitHubExtension/DataManager/DataUpdater.cs b/src/GitHubExtension/DataManager/DataUpdater.cs index ff906d9..a2b9f5d 100644 --- a/src/GitHubExtension/DataManager/DataUpdater.cs +++ b/src/GitHubExtension/DataManager/DataUpdater.cs @@ -1,7 +1,8 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension.DataManager; + public class DataUpdater : IDisposable { // This is the default interval the timer will run. It is not the interval that we necessarily do work. diff --git a/src/GitHubExtension/DataManager/Enums/SearchCategory.cs b/src/GitHubExtension/DataManager/Enums/SearchCategory.cs index 227faea..539f403 100644 --- a/src/GitHubExtension/DataManager/Enums/SearchCategory.cs +++ b/src/GitHubExtension/DataManager/Enums/SearchCategory.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension.DataManager; diff --git a/src/GitHubExtension/DataManager/Exceptions.cs b/src/GitHubExtension/DataManager/Exceptions.cs index 87f6f33..3fd9078 100644 --- a/src/GitHubExtension/DataManager/Exceptions.cs +++ b/src/GitHubExtension/DataManager/Exceptions.cs @@ -1,7 +1,8 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension; + public class RepositoryNotFoundException : ApplicationException { public RepositoryNotFoundException() diff --git a/src/GitHubExtension/DataManager/GitHubDataManager.cs b/src/GitHubExtension/DataManager/GitHubDataManager.cs index 2b3031e..c5b3ec3 100644 --- a/src/GitHubExtension/DataManager/GitHubDataManager.cs +++ b/src/GitHubExtension/DataManager/GitHubDataManager.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using GitHubExtension.Client; using GitHubExtension.DataManager; @@ -8,6 +8,7 @@ using Windows.Storage; namespace GitHubExtension; + public partial class GitHubDataManager : IGitHubDataManager, IDisposable { public static event DataManagerUpdateEventHandler? OnUpdate; diff --git a/src/GitHubExtension/DataManager/GitHubDataManagerUpdate.cs b/src/GitHubExtension/DataManager/GitHubDataManagerUpdate.cs index 9db4fc5..1082f6f 100644 --- a/src/GitHubExtension/DataManager/GitHubDataManagerUpdate.cs +++ b/src/GitHubExtension/DataManager/GitHubDataManagerUpdate.cs @@ -1,10 +1,11 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using GitHubExtension.DataManager; using GitHubExtension.DataModel; namespace GitHubExtension; + public partial class GitHubDataManager { // This is how frequently the DataStore update occurs. diff --git a/src/GitHubExtension/DataManager/GitHubSearchManger.cs b/src/GitHubExtension/DataManager/GitHubSearchManger.cs index aff6bda..d75a037 100644 --- a/src/GitHubExtension/DataManager/GitHubSearchManger.cs +++ b/src/GitHubExtension/DataManager/GitHubSearchManger.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using GitHubExtension.Client; using GitHubExtension.DataManager; diff --git a/src/GitHubExtension/DataManager/IGitHubDataManager.cs b/src/GitHubExtension/DataManager/IGitHubDataManager.cs index 9ec3231..a7f6e21 100644 --- a/src/GitHubExtension/DataManager/IGitHubDataManager.cs +++ b/src/GitHubExtension/DataManager/IGitHubDataManager.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using GitHubExtension.DataModel; diff --git a/src/GitHubExtension/DataManager/IGitHubSearchManager.cs b/src/GitHubExtension/DataManager/IGitHubSearchManager.cs index 68514e8..ec19eee 100644 --- a/src/GitHubExtension/DataManager/IGitHubSearchManager.cs +++ b/src/GitHubExtension/DataManager/IGitHubSearchManager.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using GitHubExtension.DataManager; using Microsoft.Windows.DevHome.SDK; diff --git a/src/GitHubExtension/DataManager/RequestOptions.cs b/src/GitHubExtension/DataManager/RequestOptions.cs index aa69f23..3f5380e 100644 --- a/src/GitHubExtension/DataManager/RequestOptions.cs +++ b/src/GitHubExtension/DataManager/RequestOptions.cs @@ -1,9 +1,10 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Octokit; namespace GitHubExtension; + public class RequestOptions { // Request options for making queries to GitHub. diff --git a/src/GitHubExtension/DataModel/DataObjects/CheckRun.cs b/src/GitHubExtension/DataModel/DataObjects/CheckRun.cs index 482e6da..0e2911d 100644 --- a/src/GitHubExtension/DataModel/DataObjects/CheckRun.cs +++ b/src/GitHubExtension/DataModel/DataObjects/CheckRun.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Dapper; using Dapper.Contrib.Extensions; diff --git a/src/GitHubExtension/DataModel/DataObjects/CheckSuite.cs b/src/GitHubExtension/DataModel/DataObjects/CheckSuite.cs index e846ac2..ef09e60 100644 --- a/src/GitHubExtension/DataModel/DataObjects/CheckSuite.cs +++ b/src/GitHubExtension/DataModel/DataObjects/CheckSuite.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Dapper; using Dapper.Contrib.Extensions; diff --git a/src/GitHubExtension/DataModel/DataObjects/CommitCombinedStatus.cs b/src/GitHubExtension/DataModel/DataObjects/CommitCombinedStatus.cs index fe19fe4..267d905 100644 --- a/src/GitHubExtension/DataModel/DataObjects/CommitCombinedStatus.cs +++ b/src/GitHubExtension/DataModel/DataObjects/CommitCombinedStatus.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Dapper; using Dapper.Contrib.Extensions; diff --git a/src/GitHubExtension/DataModel/DataObjects/Issue.cs b/src/GitHubExtension/DataModel/DataObjects/Issue.cs index e735794..8eadcc5 100644 --- a/src/GitHubExtension/DataModel/DataObjects/Issue.cs +++ b/src/GitHubExtension/DataModel/DataObjects/Issue.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Dapper; using Dapper.Contrib.Extensions; diff --git a/src/GitHubExtension/DataModel/DataObjects/IssueAssign.cs b/src/GitHubExtension/DataModel/DataObjects/IssueAssign.cs index c4284b8..578ab91 100644 --- a/src/GitHubExtension/DataModel/DataObjects/IssueAssign.cs +++ b/src/GitHubExtension/DataModel/DataObjects/IssueAssign.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Dapper; using Dapper.Contrib.Extensions; diff --git a/src/GitHubExtension/DataModel/DataObjects/IssueLabel.cs b/src/GitHubExtension/DataModel/DataObjects/IssueLabel.cs index 01ef27b..5ab44d4 100644 --- a/src/GitHubExtension/DataModel/DataObjects/IssueLabel.cs +++ b/src/GitHubExtension/DataModel/DataObjects/IssueLabel.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Dapper; using Dapper.Contrib.Extensions; diff --git a/src/GitHubExtension/DataModel/DataObjects/Label.cs b/src/GitHubExtension/DataModel/DataObjects/Label.cs index 7f738a4..016f836 100644 --- a/src/GitHubExtension/DataModel/DataObjects/Label.cs +++ b/src/GitHubExtension/DataModel/DataObjects/Label.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Dapper; using Dapper.Contrib.Extensions; diff --git a/src/GitHubExtension/DataModel/DataObjects/MetaData.cs b/src/GitHubExtension/DataModel/DataObjects/MetaData.cs index b855ff9..2a2e878 100644 --- a/src/GitHubExtension/DataModel/DataObjects/MetaData.cs +++ b/src/GitHubExtension/DataModel/DataObjects/MetaData.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Dapper; using Dapper.Contrib.Extensions; diff --git a/src/GitHubExtension/DataModel/DataObjects/Notification.cs b/src/GitHubExtension/DataModel/DataObjects/Notification.cs index 14b3fa0..3f7e715 100644 --- a/src/GitHubExtension/DataModel/DataObjects/Notification.cs +++ b/src/GitHubExtension/DataModel/DataObjects/Notification.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Dapper; using Dapper.Contrib.Extensions; diff --git a/src/GitHubExtension/DataModel/DataObjects/PullRequest.cs b/src/GitHubExtension/DataModel/DataObjects/PullRequest.cs index f7e02e4..c07052c 100644 --- a/src/GitHubExtension/DataModel/DataObjects/PullRequest.cs +++ b/src/GitHubExtension/DataModel/DataObjects/PullRequest.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Dapper; using Dapper.Contrib.Extensions; @@ -385,7 +385,7 @@ private static PullRequest CreateFromOctokitPullRequest(DataStore dataStore, Oct pull.AssigneeIds = string.Join(",", assignees); - // Owner is a rowid in the User table + // Owner is a rowId in the User table var author = User.GetOrCreateByOctokitUser(dataStore, okitPull.User); pull.AuthorId = author.Id; diff --git a/src/GitHubExtension/DataModel/DataObjects/PullRequestAssign.cs b/src/GitHubExtension/DataModel/DataObjects/PullRequestAssign.cs index 1723fac..3034cfe 100644 --- a/src/GitHubExtension/DataModel/DataObjects/PullRequestAssign.cs +++ b/src/GitHubExtension/DataModel/DataObjects/PullRequestAssign.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Dapper; using Dapper.Contrib.Extensions; diff --git a/src/GitHubExtension/DataModel/DataObjects/PullRequestLabel.cs b/src/GitHubExtension/DataModel/DataObjects/PullRequestLabel.cs index 28cc446..ffd0807 100644 --- a/src/GitHubExtension/DataModel/DataObjects/PullRequestLabel.cs +++ b/src/GitHubExtension/DataModel/DataObjects/PullRequestLabel.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Dapper; using Dapper.Contrib.Extensions; diff --git a/src/GitHubExtension/DataModel/DataObjects/PullRequestStatus.cs b/src/GitHubExtension/DataModel/DataObjects/PullRequestStatus.cs index 8fcbfe1..4de8ea5 100644 --- a/src/GitHubExtension/DataModel/DataObjects/PullRequestStatus.cs +++ b/src/GitHubExtension/DataModel/DataObjects/PullRequestStatus.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Dapper; using Dapper.Contrib.Extensions; diff --git a/src/GitHubExtension/DataModel/DataObjects/Repository.cs b/src/GitHubExtension/DataModel/DataObjects/Repository.cs index 61a7913..f0fc3d8 100644 --- a/src/GitHubExtension/DataModel/DataObjects/Repository.cs +++ b/src/GitHubExtension/DataModel/DataObjects/Repository.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Dapper; using Dapper.Contrib.Extensions; @@ -149,7 +149,7 @@ private static Repository CreateFromOctokitRepository(DataStore dataStore, Octok TimePushed = octokitRepository.UpdatedAt.DateTime.ToDataStoreInteger(), }; - // Owner is a rowid in the User table + // Owner is a rowId in the User table var owner = User.GetOrCreateByOctokitUser(dataStore, octokitRepository.Owner); repo.OwnerId = owner.Id; @@ -250,12 +250,12 @@ public static IEnumerable GetAll(DataStore dataStore) return repo; } - public static Repository? Get(DataStore dataStore, string fullname) + public static Repository? Get(DataStore dataStore, string fullName) { - var nameSplit = fullname.Split(new[] { '/' }, 2); + var nameSplit = fullName.Split(new[] { '/' }, 2); if (nameSplit.Length != 2) { - Log.Logger()?.ReportWarn($"Invalid fullname input into Repository.Get: {fullname}"); + Log.Logger()?.ReportWarn($"Invalid fullName input into Repository.Get: {fullName}"); return null; } diff --git a/src/GitHubExtension/DataModel/DataObjects/Review.cs b/src/GitHubExtension/DataModel/DataObjects/Review.cs index 7fc7686..5438c60 100644 --- a/src/GitHubExtension/DataModel/DataObjects/Review.cs +++ b/src/GitHubExtension/DataModel/DataObjects/Review.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Dapper; using Dapper.Contrib.Extensions; diff --git a/src/GitHubExtension/DataModel/DataObjects/Search.cs b/src/GitHubExtension/DataModel/DataObjects/Search.cs index f64a103..e445c6d 100644 --- a/src/GitHubExtension/DataModel/DataObjects/Search.cs +++ b/src/GitHubExtension/DataModel/DataObjects/Search.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Dapper; using Dapper.Contrib.Extensions; diff --git a/src/GitHubExtension/DataModel/DataObjects/SearchIssue.cs b/src/GitHubExtension/DataModel/DataObjects/SearchIssue.cs index 4d90325..7c22649 100644 --- a/src/GitHubExtension/DataModel/DataObjects/SearchIssue.cs +++ b/src/GitHubExtension/DataModel/DataObjects/SearchIssue.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Dapper; using Dapper.Contrib.Extensions; diff --git a/src/GitHubExtension/DataModel/DataObjects/User.cs b/src/GitHubExtension/DataModel/DataObjects/User.cs index d00f024..50407a7 100644 --- a/src/GitHubExtension/DataModel/DataObjects/User.cs +++ b/src/GitHubExtension/DataModel/DataObjects/User.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Dapper; using Dapper.Contrib.Extensions; diff --git a/src/GitHubExtension/DataModel/DataStore.cs b/src/GitHubExtension/DataModel/DataStore.cs index 95169d8..dc6379a 100644 --- a/src/GitHubExtension/DataModel/DataStore.cs +++ b/src/GitHubExtension/DataModel/DataStore.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Globalization; using System.Reflection; diff --git a/src/GitHubExtension/DataModel/DataStoreOptions.cs b/src/GitHubExtension/DataModel/DataStoreOptions.cs index 818c6b7..c3da336 100644 --- a/src/GitHubExtension/DataModel/DataStoreOptions.cs +++ b/src/GitHubExtension/DataModel/DataStoreOptions.cs @@ -1,7 +1,8 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace GitHubExtension.DataModel; -namespace GitHubExtension.DataModel; public partial class DataStoreOptions { private const string DataStoreFileNameDefault = "GitHubData.db"; diff --git a/src/GitHubExtension/DataModel/DataStoreTransaction.cs b/src/GitHubExtension/DataModel/DataStoreTransaction.cs index bcc3c14..494c778 100644 --- a/src/GitHubExtension/DataModel/DataStoreTransaction.cs +++ b/src/GitHubExtension/DataModel/DataStoreTransaction.cs @@ -1,9 +1,10 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Microsoft.Data.Sqlite; -namespace GitHubExtension.DataModel; +namespace GitHubExtension.DataModel; + public class DataStoreTransaction : IDataStoreTransaction { private SqliteTransaction? transaction; diff --git a/src/GitHubExtension/DataModel/Enums/CheckConclusion.cs b/src/GitHubExtension/DataModel/Enums/CheckConclusion.cs index 6c48c6a..e1048d5 100644 --- a/src/GitHubExtension/DataModel/Enums/CheckConclusion.cs +++ b/src/GitHubExtension/DataModel/Enums/CheckConclusion.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension.DataModel; diff --git a/src/GitHubExtension/DataModel/Enums/CheckStatus.cs b/src/GitHubExtension/DataModel/Enums/CheckStatus.cs index dca3e59..a20774b 100644 --- a/src/GitHubExtension/DataModel/Enums/CheckStatus.cs +++ b/src/GitHubExtension/DataModel/Enums/CheckStatus.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension.DataModel; diff --git a/src/GitHubExtension/DataModel/Enums/CommitState.cs b/src/GitHubExtension/DataModel/Enums/CommitState.cs index fcbe67d..0525daf 100644 --- a/src/GitHubExtension/DataModel/Enums/CommitState.cs +++ b/src/GitHubExtension/DataModel/Enums/CommitState.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension.DataModel; diff --git a/src/GitHubExtension/DataModel/Enums/NotificationType.cs b/src/GitHubExtension/DataModel/Enums/NotificationType.cs index 2091ae0..bf35e15 100644 --- a/src/GitHubExtension/DataModel/Enums/NotificationType.cs +++ b/src/GitHubExtension/DataModel/Enums/NotificationType.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension.DataModel; diff --git a/src/GitHubExtension/DataModel/Enums/PullRequestCombinedStatus.cs b/src/GitHubExtension/DataModel/Enums/PullRequestCombinedStatus.cs index 91f653f..11ef877 100644 --- a/src/GitHubExtension/DataModel/Enums/PullRequestCombinedStatus.cs +++ b/src/GitHubExtension/DataModel/Enums/PullRequestCombinedStatus.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension.DataModel; diff --git a/src/GitHubExtension/DataModel/GitHubDataStoreSchema.cs b/src/GitHubExtension/DataModel/GitHubDataStoreSchema.cs index fd84a95..13fe1dd 100644 --- a/src/GitHubExtension/DataModel/GitHubDataStoreSchema.cs +++ b/src/GitHubExtension/DataModel/GitHubDataStoreSchema.cs @@ -1,7 +1,8 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension.DataModel; + public class GitHubDataStoreSchema : IDataStoreSchema { public long SchemaVersion => SchemaVersionValue; diff --git a/src/GitHubExtension/DataModel/IDataStoreSchema.cs b/src/GitHubExtension/DataModel/IDataStoreSchema.cs index db28e45..b77a869 100644 --- a/src/GitHubExtension/DataModel/IDataStoreSchema.cs +++ b/src/GitHubExtension/DataModel/IDataStoreSchema.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension.DataModel; diff --git a/src/GitHubExtension/DataModel/IDataStoreTransaction.cs b/src/GitHubExtension/DataModel/IDataStoreTransaction.cs index a6d4236..7e8012b 100644 --- a/src/GitHubExtension/DataModel/IDataStoreTransaction.cs +++ b/src/GitHubExtension/DataModel/IDataStoreTransaction.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension.DataModel; diff --git a/src/GitHubExtension/DataModel/Logging.cs b/src/GitHubExtension/DataModel/Logging.cs index 2a14568..4898760 100644 --- a/src/GitHubExtension/DataModel/Logging.cs +++ b/src/GitHubExtension/DataModel/Logging.cs @@ -1,10 +1,11 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using DevHome.Logging; using Windows.Storage; namespace GitHubExtension.DataModel; + public class Log { private static Logger? _logger; diff --git a/src/GitHubExtension/DeveloperId/CredentialManager.cs b/src/GitHubExtension/DeveloperId/CredentialManager.cs index 96835e0..68f9a27 100644 --- a/src/GitHubExtension/DeveloperId/CredentialManager.cs +++ b/src/GitHubExtension/DeveloperId/CredentialManager.cs @@ -1,64 +1,65 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. - -using System.Runtime.InteropServices; - -namespace GitHubExtension.DeveloperId; -public static class CredentialManager -{ - public enum CRED_TYPE : int - { - GENERIC = 1, - DOMAIN_PASSWORD = 2, - DOMAIN_CERTIFICATE = 3, - DOMAIN_VISIBLE_PASSWORD = 4, - MAXIMUM = 5, - } - - public enum CRED_PERSIST : uint - { - Session = 1, - LocalMachine = 2, - Enterprise = 3, - } - - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] - public struct CREDENTIAL - { - public int Flags; - public CRED_TYPE Type; - [MarshalAs(UnmanagedType.LPWStr)] - public string TargetName; - [MarshalAs(UnmanagedType.LPWStr)] - public string Comment; - public System.Runtime.InteropServices.ComTypes.FILETIME LastWritten; - public int CredentialBlobSize; - public IntPtr CredentialBlob; - public int Persist; - public int AttributeCount; - public IntPtr CredAttribute; - [MarshalAs(UnmanagedType.LPWStr)] - public string TargetAlias; - [MarshalAs(UnmanagedType.LPWStr)] - public string UserName; - } - - [DllImport("advapi32.dll", EntryPoint = "CredWriteW", CharSet = CharSet.Unicode, SetLastError = true)] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool CredWrite(CREDENTIAL credential, int flags); - - [DllImport("advapi32.dll", EntryPoint = "CredDeleteW", CharSet = CharSet.Unicode)] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool CredDelete(string target, CRED_TYPE type, int flags); - - [DllImport("advapi32.dll", EntryPoint = "CredReadW", CharSet = CharSet.Unicode, SetLastError = true)] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool CredRead(string target, CRED_TYPE type, int flags, out IntPtr credential); - - [DllImport("advapi32.dll", EntryPoint = "CredEnumerateW", CharSet = CharSet.Unicode, SetLastError = true)] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool CredEnumerate(string filter, uint flags, out uint count, out IntPtr credentials); - - [DllImport("advapi32.dll", EntryPoint = "CredFree", CharSet = CharSet.Unicode)] - internal static extern void CredFree(IntPtr buffer); -} +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System.Runtime.InteropServices; + +namespace GitHubExtension.DeveloperId; + +public static class CredentialManager +{ + public enum CRED_TYPE : int + { + GENERIC = 1, + DOMAIN_PASSWORD = 2, + DOMAIN_CERTIFICATE = 3, + DOMAIN_VISIBLE_PASSWORD = 4, + MAXIMUM = 5, + } + + public enum CRED_PERSIST : uint + { + Session = 1, + LocalMachine = 2, + Enterprise = 3, + } + + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + public struct CREDENTIAL + { + public int Flags; + public CRED_TYPE Type; + [MarshalAs(UnmanagedType.LPWStr)] + public string TargetName; + [MarshalAs(UnmanagedType.LPWStr)] + public string Comment; + public System.Runtime.InteropServices.ComTypes.FILETIME LastWritten; + public int CredentialBlobSize; + public IntPtr CredentialBlob; + public int Persist; + public int AttributeCount; + public IntPtr CredAttribute; + [MarshalAs(UnmanagedType.LPWStr)] + public string TargetAlias; + [MarshalAs(UnmanagedType.LPWStr)] + public string UserName; + } + + [DllImport("advapi32.dll", EntryPoint = "CredWriteW", CharSet = CharSet.Unicode, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static extern bool CredWrite(CREDENTIAL credential, int flags); + + [DllImport("advapi32.dll", EntryPoint = "CredDeleteW", CharSet = CharSet.Unicode)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static extern bool CredDelete(string target, CRED_TYPE type, int flags); + + [DllImport("advapi32.dll", EntryPoint = "CredReadW", CharSet = CharSet.Unicode, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static extern bool CredRead(string target, CRED_TYPE type, int flags, out IntPtr credential); + + [DllImport("advapi32.dll", EntryPoint = "CredEnumerateW", CharSet = CharSet.Unicode, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static extern bool CredEnumerate(string filter, uint flags, out uint count, out IntPtr credentials); + + [DllImport("advapi32.dll", EntryPoint = "CredFree", CharSet = CharSet.Unicode)] + internal static extern void CredFree(IntPtr buffer); +} diff --git a/src/GitHubExtension/DeveloperId/CredentialVault.cs b/src/GitHubExtension/DeveloperId/CredentialVault.cs index 3c3abcf..99a678c 100644 --- a/src/GitHubExtension/DeveloperId/CredentialVault.cs +++ b/src/GitHubExtension/DeveloperId/CredentialVault.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.ComponentModel; using System.Runtime.InteropServices; @@ -8,6 +8,7 @@ using static GitHubExtension.DeveloperId.CredentialManager; namespace GitHubExtension.DeveloperId; + public class CredentialVault : ICredentialVault { private readonly string _credentialResourceName; diff --git a/src/GitHubExtension/DeveloperId/DeveloperId.cs b/src/GitHubExtension/DeveloperId/DeveloperId.cs index f2a821d..48fd4e8 100644 --- a/src/GitHubExtension/DeveloperId/DeveloperId.cs +++ b/src/GitHubExtension/DeveloperId/DeveloperId.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Microsoft.Windows.DevHome.SDK; using Octokit; diff --git a/src/GitHubExtension/DeveloperId/DeveloperIdProvider.cs b/src/GitHubExtension/DeveloperId/DeveloperIdProvider.cs index 895ff03..566949f 100644 --- a/src/GitHubExtension/DeveloperId/DeveloperIdProvider.cs +++ b/src/GitHubExtension/DeveloperId/DeveloperIdProvider.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Net; using System.Security; diff --git a/src/GitHubExtension/DeveloperId/Enums/LoginUIState.cs b/src/GitHubExtension/DeveloperId/Enums/LoginUIState.cs index 2a340c8..eacdd59 100644 --- a/src/GitHubExtension/DeveloperId/Enums/LoginUIState.cs +++ b/src/GitHubExtension/DeveloperId/Enums/LoginUIState.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension.DeveloperId; diff --git a/src/GitHubExtension/DeveloperId/ICredentialVault.cs b/src/GitHubExtension/DeveloperId/ICredentialVault.cs index dd6a187..b7ef13d 100644 --- a/src/GitHubExtension/DeveloperId/ICredentialVault.cs +++ b/src/GitHubExtension/DeveloperId/ICredentialVault.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Security; using Windows.Security.Credentials; diff --git a/src/GitHubExtension/DeveloperId/IDeveloperIdProviderInternal.cs b/src/GitHubExtension/DeveloperId/IDeveloperIdProviderInternal.cs index 1ac2896..2651172 100644 --- a/src/GitHubExtension/DeveloperId/IDeveloperIdProviderInternal.cs +++ b/src/GitHubExtension/DeveloperId/IDeveloperIdProviderInternal.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Security; using Microsoft.Windows.DevHome.SDK; diff --git a/src/GitHubExtension/DeveloperId/Logging.cs b/src/GitHubExtension/DeveloperId/Logging.cs index dae84d6..1d8e628 100644 --- a/src/GitHubExtension/DeveloperId/Logging.cs +++ b/src/GitHubExtension/DeveloperId/Logging.cs @@ -1,10 +1,11 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using DevHome.Logging; using Windows.Storage; namespace GitHubExtension.DeveloperId; + public class Log { private static Logger? _logger; diff --git a/src/GitHubExtension/DeveloperId/LoginUI/EndPage.cs b/src/GitHubExtension/DeveloperId/LoginUI/EndPage.cs index c66895e..51234cc 100644 --- a/src/GitHubExtension/DeveloperId/LoginUI/EndPage.cs +++ b/src/GitHubExtension/DeveloperId/LoginUI/EndPage.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension.DeveloperId.LoginUI; diff --git a/src/GitHubExtension/DeveloperId/LoginUI/EnterpriseServerPATPage.cs b/src/GitHubExtension/DeveloperId/LoginUI/EnterpriseServerPATPage.cs index de7bc31..b94740b 100644 --- a/src/GitHubExtension/DeveloperId/LoginUI/EnterpriseServerPATPage.cs +++ b/src/GitHubExtension/DeveloperId/LoginUI/EnterpriseServerPATPage.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Security; using GitHubExtension.Helpers; diff --git a/src/GitHubExtension/DeveloperId/LoginUI/EnterpriseServerPage.cs b/src/GitHubExtension/DeveloperId/LoginUI/EnterpriseServerPage.cs index de2fb90..bc6842b 100644 --- a/src/GitHubExtension/DeveloperId/LoginUI/EnterpriseServerPage.cs +++ b/src/GitHubExtension/DeveloperId/LoginUI/EnterpriseServerPage.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using GitHubExtension.Helpers; diff --git a/src/GitHubExtension/DeveloperId/LoginUI/LoginFailedPage.cs b/src/GitHubExtension/DeveloperId/LoginUI/LoginFailedPage.cs index 3d54686..a814410 100644 --- a/src/GitHubExtension/DeveloperId/LoginUI/LoginFailedPage.cs +++ b/src/GitHubExtension/DeveloperId/LoginUI/LoginFailedPage.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using GitHubExtension.Helpers; diff --git a/src/GitHubExtension/DeveloperId/LoginUI/LoginPage.cs b/src/GitHubExtension/DeveloperId/LoginUI/LoginPage.cs index cc7bd0b..688ec22 100644 --- a/src/GitHubExtension/DeveloperId/LoginUI/LoginPage.cs +++ b/src/GitHubExtension/DeveloperId/LoginUI/LoginPage.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using GitHubExtension.Helpers; diff --git a/src/GitHubExtension/DeveloperId/LoginUI/LoginSucceededPage.cs b/src/GitHubExtension/DeveloperId/LoginUI/LoginSucceededPage.cs index 942fbb0..5ef0364 100644 --- a/src/GitHubExtension/DeveloperId/LoginUI/LoginSucceededPage.cs +++ b/src/GitHubExtension/DeveloperId/LoginUI/LoginSucceededPage.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using GitHubExtension.Helpers; using Microsoft.Windows.DevHome.SDK; diff --git a/src/GitHubExtension/DeveloperId/LoginUI/LoginUIPage.cs b/src/GitHubExtension/DeveloperId/LoginUI/LoginUIPage.cs index 34c5a3a..d6fe745 100644 --- a/src/GitHubExtension/DeveloperId/LoginUI/LoginUIPage.cs +++ b/src/GitHubExtension/DeveloperId/LoginUI/LoginUIPage.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using GitHubExtension.Helpers; using Microsoft.Windows.DevHome.SDK; diff --git a/src/GitHubExtension/DeveloperId/LoginUI/WaitingPage.cs b/src/GitHubExtension/DeveloperId/LoginUI/WaitingPage.cs index 7401ea0..19739c8 100644 --- a/src/GitHubExtension/DeveloperId/LoginUI/WaitingPage.cs +++ b/src/GitHubExtension/DeveloperId/LoginUI/WaitingPage.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using GitHubExtension.Helpers; diff --git a/src/GitHubExtension/DeveloperId/LoginUIController.cs b/src/GitHubExtension/DeveloperId/LoginUIController.cs index 08ddf6c..e29bb00 100644 --- a/src/GitHubExtension/DeveloperId/LoginUIController.cs +++ b/src/GitHubExtension/DeveloperId/LoginUIController.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Net; using GitHubExtension.Client; @@ -9,6 +9,7 @@ using Windows.Foundation; namespace GitHubExtension.DeveloperId; + public class LoginUIController : IExtensionAdaptiveCardSession { private readonly IDeveloperIdProviderInternal _developerIdProvider; diff --git a/src/GitHubExtension/DeveloperId/OAuthRequest.cs b/src/GitHubExtension/DeveloperId/OAuthRequest.cs index b6d0843..826fd6e 100644 --- a/src/GitHubExtension/DeveloperId/OAuthRequest.cs +++ b/src/GitHubExtension/DeveloperId/OAuthRequest.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Net; using System.Security; @@ -9,6 +9,7 @@ using Octokit; namespace GitHubExtension.DeveloperId; + internal class OAuthRequest : IDisposable { internal string State { get; private set; } diff --git a/src/GitHubExtension/GitHubExtension.cs b/src/GitHubExtension/GitHubExtension.cs index 609ed65..9dd8204 100644 --- a/src/GitHubExtension/GitHubExtension.cs +++ b/src/GitHubExtension/GitHubExtension.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Runtime.InteropServices; using GitHubExtension.DeveloperId; diff --git a/src/GitHubExtension/Helpers/DateTimeExtensions.cs b/src/GitHubExtension/Helpers/DateTimeExtensions.cs index 0462311..f1236cb 100644 --- a/src/GitHubExtension/Helpers/DateTimeExtensions.cs +++ b/src/GitHubExtension/Helpers/DateTimeExtensions.cs @@ -1,9 +1,10 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Globalization; namespace GitHubExtension.Helpers; + public static class DateTimeExtensions { // Data store stores time as integers, which is just the Ticks so we don't lose precision. diff --git a/src/GitHubExtension/Helpers/EnumHelper.cs b/src/GitHubExtension/Helpers/EnumHelper.cs index ab8d3c9..e0db3c4 100644 --- a/src/GitHubExtension/Helpers/EnumHelper.cs +++ b/src/GitHubExtension/Helpers/EnumHelper.cs @@ -1,29 +1,30 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. -using GitHubExtension.DataManager; - -namespace GitHubExtension.Helpers; -public class EnumHelper -{ - public static string SearchCategoryToString(SearchCategory searchCategory) => searchCategory switch - { - SearchCategory.Issues => "Issues", - SearchCategory.PullRequests => "PullRequests", - SearchCategory.IssuesAndPullRequests => "IssuesAndPullRequests", - _ => "unknown" - }; - - public static SearchCategory StringToSearchCategory(string value) - { - try - { - return Enum.Parse(value); - } - catch (Exception) - { - // Invalid value. - return SearchCategory.Unknown; - } - } -} +using GitHubExtension.DataManager; + +namespace GitHubExtension.Helpers; + +public class EnumHelper +{ + public static string SearchCategoryToString(SearchCategory searchCategory) => searchCategory switch + { + SearchCategory.Issues => "Issues", + SearchCategory.PullRequests => "PullRequests", + SearchCategory.IssuesAndPullRequests => "IssuesAndPullRequests", + _ => "unknown" + }; + + public static SearchCategory StringToSearchCategory(string value) + { + try + { + return Enum.Parse(value); + } + catch (Exception) + { + // Invalid value. + return SearchCategory.Unknown; + } + } +} diff --git a/src/GitHubExtension/Helpers/FileHelper.cs b/src/GitHubExtension/Helpers/FileHelper.cs index a2f1633..8580af2 100644 --- a/src/GitHubExtension/Helpers/FileHelper.cs +++ b/src/GitHubExtension/Helpers/FileHelper.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Text; using Newtonsoft.Json; diff --git a/src/GitHubExtension/Helpers/IconLoader.cs b/src/GitHubExtension/Helpers/IconLoader.cs index ba2c870..c6a1764 100644 --- a/src/GitHubExtension/Helpers/IconLoader.cs +++ b/src/GitHubExtension/Helpers/IconLoader.cs @@ -1,9 +1,10 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using GitHubExtension.DataModel; namespace GitHubExtension.Helpers; + public class IconLoader { private static readonly Dictionary Base64ImageRegistry = new (); diff --git a/src/GitHubExtension/Helpers/Json.cs b/src/GitHubExtension/Helpers/Json.cs index ff3c48b..314d3a9 100644 --- a/src/GitHubExtension/Helpers/Json.cs +++ b/src/GitHubExtension/Helpers/Json.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Text.Json; using System.Text.Json.Serialization; diff --git a/src/GitHubExtension/Helpers/LocalSettings.cs b/src/GitHubExtension/Helpers/LocalSettings.cs index 9aabb7b..7656341 100644 --- a/src/GitHubExtension/Helpers/LocalSettings.cs +++ b/src/GitHubExtension/Helpers/LocalSettings.cs @@ -1,10 +1,11 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using DevHome.Common.Services; using Windows.Storage; namespace GitHubExtension.Helpers; + public static class LocalSettings { private static readonly string _applicationDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DevHome/ApplicationData"); diff --git a/src/GitHubExtension/Helpers/Resources.cs b/src/GitHubExtension/Helpers/Resources.cs index 29b4df7..2ddc1ab 100644 --- a/src/GitHubExtension/Helpers/Resources.cs +++ b/src/GitHubExtension/Helpers/Resources.cs @@ -1,10 +1,11 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using DevHome.Logging; using Microsoft.Windows.ApplicationModel.Resources; namespace GitHubExtension.Helpers; + public static class Resources { private static ResourceLoader? _resourceLoader; diff --git a/src/GitHubExtension/Helpers/RuntimeHelper.cs b/src/GitHubExtension/Helpers/RuntimeHelper.cs index 7cd3f57..59c9f95 100644 --- a/src/GitHubExtension/Helpers/RuntimeHelper.cs +++ b/src/GitHubExtension/Helpers/RuntimeHelper.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Windows.Win32; using Windows.Win32.Foundation; diff --git a/src/GitHubExtension/Helpers/StringExtensions.cs b/src/GitHubExtension/Helpers/StringExtensions.cs index 59da8db..9b8440b 100644 --- a/src/GitHubExtension/Helpers/StringExtensions.cs +++ b/src/GitHubExtension/Helpers/StringExtensions.cs @@ -1,15 +1,16 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. - -using System.Globalization; - -namespace GitHubExtension.Helpers; -public static class StringExtensions -{ - public static string ToStringInvariant(this T value) => Convert.ToString(value, CultureInfo.InvariantCulture)!; - - public static string FormatInvariant(this string value, params object[] arguments) - { - return string.Format(CultureInfo.InvariantCulture, value, arguments); - } -} +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System.Globalization; + +namespace GitHubExtension.Helpers; + +public static class StringExtensions +{ + public static string ToStringInvariant(this T value) => Convert.ToString(value, CultureInfo.InvariantCulture)!; + + public static string FormatInvariant(this string value, params object[] arguments) + { + return string.Format(CultureInfo.InvariantCulture, value, arguments); + } +} diff --git a/src/GitHubExtension/Helpers/TimeSpanHelper.cs b/src/GitHubExtension/Helpers/TimeSpanHelper.cs index fe6f8db..9afbc56 100644 --- a/src/GitHubExtension/Helpers/TimeSpanHelper.cs +++ b/src/GitHubExtension/Helpers/TimeSpanHelper.cs @@ -1,10 +1,11 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using DevHome.Logging; using Jeffijoe.MessageFormat; namespace GitHubExtension.Helpers; + internal class TimeSpanHelper { public static string TimeSpanToDisplayString(TimeSpan timeSpan, Logger? log = null) diff --git a/src/GitHubExtension/Notifications/Logging.cs b/src/GitHubExtension/Notifications/Logging.cs index fe1d6a0..390d7ff 100644 --- a/src/GitHubExtension/Notifications/Logging.cs +++ b/src/GitHubExtension/Notifications/Logging.cs @@ -1,10 +1,11 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using DevHome.Logging; using Windows.Storage; namespace GitHubExtension.Notifications; + public class Log { private static Logger? _logger; diff --git a/src/GitHubExtension/Notifications/NotificationHandler.cs b/src/GitHubExtension/Notifications/NotificationHandler.cs index fef7086..c6626b7 100644 --- a/src/GitHubExtension/Notifications/NotificationHandler.cs +++ b/src/GitHubExtension/Notifications/NotificationHandler.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Diagnostics; using System.Globalization; @@ -8,6 +8,7 @@ using Microsoft.Windows.AppNotifications; namespace GitHubExtension.Notifications; + public class NotificationHandler { #pragma warning disable IDE0060 // Remove unused parameter diff --git a/src/GitHubExtension/Notifications/NotificationManager.cs b/src/GitHubExtension/Notifications/NotificationManager.cs index 1155f6f..3d9e375 100644 --- a/src/GitHubExtension/Notifications/NotificationManager.cs +++ b/src/GitHubExtension/Notifications/NotificationManager.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Microsoft.Windows.AppNotifications; diff --git a/src/GitHubExtension/Providers/DevHomeRepository.cs b/src/GitHubExtension/Providers/DevHomeRepository.cs index bc13040..fe86428 100644 --- a/src/GitHubExtension/Providers/DevHomeRepository.cs +++ b/src/GitHubExtension/Providers/DevHomeRepository.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using GitHubExtension.Client; @@ -29,13 +29,13 @@ public class DevHomeRepository : Microsoft.Windows.DevHome.SDK.IRepository /// /// Initializes a new instance of the class. /// - /// The repository received from ocktokit - public DevHomeRepository(Octokit.Repository ocktokitRepository) + /// The repository received from octokit + public DevHomeRepository(Octokit.Repository octokitRepository) { - this.name = ocktokitRepository.Name; - this.cloneUrl = new Uri(ocktokitRepository.CloneUrl); + this.name = octokitRepository.Name; + this.cloneUrl = new Uri(octokitRepository.CloneUrl); - _lastUpdated = ocktokitRepository.UpdatedAt; - _isPrivate = ocktokitRepository.Private; + _lastUpdated = octokitRepository.UpdatedAt; + _isPrivate = octokitRepository.Private; } } diff --git a/src/GitHubExtension/Providers/Logging.cs b/src/GitHubExtension/Providers/Logging.cs index 938284e..af5e21a 100644 --- a/src/GitHubExtension/Providers/Logging.cs +++ b/src/GitHubExtension/Providers/Logging.cs @@ -1,10 +1,11 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using DevHome.Logging; using Windows.Storage; namespace GitHubExtension.Providers; + public class Log { private static Logger? _logger; diff --git a/src/GitHubExtension/Providers/RepositoryProvider.cs b/src/GitHubExtension/Providers/RepositoryProvider.cs index 463272d..47b1fc2 100644 --- a/src/GitHubExtension/Providers/RepositoryProvider.cs +++ b/src/GitHubExtension/Providers/RepositoryProvider.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using GitHubExtension.Client; using GitHubExtension.DeveloperId; @@ -129,7 +129,7 @@ public IAsyncOperation GetRepositoryFromUriAsync(Uri uri, IDev return new RepositoryResult(exception, $"{exception.Message} HResult: {exception.HResult}"); } - Octokit.Repository? ocktokitRepo = null; + Octokit.Repository? octokitRepo = null; var owner = Validation.ParseOwnerFromGitHubURL(uri); var repoName = Validation.ParseRepositoryFromGitHubURL(uri); @@ -147,7 +147,7 @@ public IAsyncOperation GetRepositoryFromUriAsync(Uri uri, IDev gitHubClient = GitHubClientProvider.Instance.GetClient(); } - ocktokitRepo = gitHubClient.Repository.Get(owner, repoName).Result; + octokitRepo = gitHubClient.Repository.Get(owner, repoName).Result; } catch (AggregateException e) { @@ -176,13 +176,13 @@ public IAsyncOperation GetRepositoryFromUriAsync(Uri uri, IDev return new RepositoryResult(e, $"Unspecified error when cloning a repo. HResult: {e.HResult}"); } - if (ocktokitRepo == null) + if (octokitRepo == null) { return new RepositoryResult(new ArgumentException("Repo is still null"), "Repo is still null"); } else { - return new RepositoryResult(new DevHomeRepository(ocktokitRepo)); + return new RepositoryResult(new DevHomeRepository(octokitRepo)); } }).AsAsyncOperation(); } diff --git a/src/GitHubExtension/Providers/SettingsProvider.cs b/src/GitHubExtension/Providers/SettingsProvider.cs index 09ee8ef..420f6c5 100644 --- a/src/GitHubExtension/Providers/SettingsProvider.cs +++ b/src/GitHubExtension/Providers/SettingsProvider.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using GitHubExtension.Helpers; using Microsoft.Windows.DevHome.SDK; diff --git a/src/GitHubExtension/Providers/SettingsUIController.cs b/src/GitHubExtension/Providers/SettingsUIController.cs index 98904ce..6c8cfa3 100644 --- a/src/GitHubExtension/Providers/SettingsUIController.cs +++ b/src/GitHubExtension/Providers/SettingsUIController.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using GitHubExtension.Helpers; using Microsoft.Windows.ApplicationModel.Resources; @@ -7,6 +7,7 @@ using Windows.Foundation; namespace GitHubExtension.Providers; + internal class SettingsUIController : IExtensionAdaptiveCardSession { private static readonly string _notificationsEnabledString = "NotificationsEnabled"; diff --git a/src/GitHubExtension/Widgets/Enums/WidgetAction.cs b/src/GitHubExtension/Widgets/Enums/WidgetAction.cs index 671fc66..a732257 100644 --- a/src/GitHubExtension/Widgets/Enums/WidgetAction.cs +++ b/src/GitHubExtension/Widgets/Enums/WidgetAction.cs @@ -1,7 +1,8 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension.Widgets.Enums; + public enum WidgetAction { /// diff --git a/src/GitHubExtension/Widgets/Enums/WidgetActivityState.cs b/src/GitHubExtension/Widgets/Enums/WidgetActivityState.cs index 20ecab9..aa67814 100644 --- a/src/GitHubExtension/Widgets/Enums/WidgetActivityState.cs +++ b/src/GitHubExtension/Widgets/Enums/WidgetActivityState.cs @@ -1,7 +1,8 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension.Widgets.Enums; + public enum WidgetActivityState { /// diff --git a/src/GitHubExtension/Widgets/Enums/WidgetDataState.cs b/src/GitHubExtension/Widgets/Enums/WidgetDataState.cs index 545f7be..23ea2cc 100644 --- a/src/GitHubExtension/Widgets/Enums/WidgetDataState.cs +++ b/src/GitHubExtension/Widgets/Enums/WidgetDataState.cs @@ -1,7 +1,8 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension.Widgets; + public enum WidgetDataState { Unknown, diff --git a/src/GitHubExtension/Widgets/Enums/WidgetPageState.cs b/src/GitHubExtension/Widgets/Enums/WidgetPageState.cs index 47b0a38..70e1bf7 100644 --- a/src/GitHubExtension/Widgets/Enums/WidgetPageState.cs +++ b/src/GitHubExtension/Widgets/Enums/WidgetPageState.cs @@ -1,7 +1,8 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension.Widgets; + public enum WidgetPageState { Unknown, diff --git a/src/GitHubExtension/Widgets/GitHubAssignedWidget.cs b/src/GitHubExtension/Widgets/GitHubAssignedWidget.cs index bdfd067..e70f8f0 100644 --- a/src/GitHubExtension/Widgets/GitHubAssignedWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubAssignedWidget.cs @@ -1,9 +1,10 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Octokit; -namespace GitHubExtension.Widgets; +namespace GitHubExtension.Widgets; + internal class GitHubAssignedWidget : GitHubUserWidget { private static readonly string TitleIconData = diff --git a/src/GitHubExtension/Widgets/GitHubIssuesWidget.cs b/src/GitHubExtension/Widgets/GitHubIssuesWidget.cs index 0205a66..95fc7dd 100644 --- a/src/GitHubExtension/Widgets/GitHubIssuesWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubIssuesWidget.cs @@ -1,15 +1,15 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Text.Json.Nodes; using GitHubExtension.Client; using GitHubExtension.DataManager; using GitHubExtension.Helpers; using GitHubExtension.Widgets.Enums; -using Microsoft.Windows.Widgets.Providers; using Octokit; namespace GitHubExtension.Widgets; + internal class GitHubIssuesWidget : GitHubRepositoryWidget { private readonly string issuesIconData = IconLoader.GetIconAsBase64("issues.png"); diff --git a/src/GitHubExtension/Widgets/GitHubMentionedInWidget.cs b/src/GitHubExtension/Widgets/GitHubMentionedInWidget.cs index 524f165..426abc2 100644 --- a/src/GitHubExtension/Widgets/GitHubMentionedInWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubMentionedInWidget.cs @@ -1,9 +1,10 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Octokit; -namespace GitHubExtension.Widgets; +namespace GitHubExtension.Widgets; + internal class GitHubMentionedInWidget : GitHubUserWidget { private static readonly string TitleIconData = diff --git a/src/GitHubExtension/Widgets/GitHubPullsWidget.cs b/src/GitHubExtension/Widgets/GitHubPullsWidget.cs index 318c425..df5362d 100644 --- a/src/GitHubExtension/Widgets/GitHubPullsWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubPullsWidget.cs @@ -1,15 +1,15 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Text.Json.Nodes; using GitHubExtension.Client; using GitHubExtension.DataManager; using GitHubExtension.Helpers; using GitHubExtension.Widgets.Enums; -using Microsoft.Windows.Widgets.Providers; using Octokit; namespace GitHubExtension.Widgets; + internal class GitHubPullsWidget : GitHubRepositoryWidget { private readonly string pullsIconData = IconLoader.GetIconAsBase64("pulls.png"); diff --git a/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs b/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs index 09b9501..c8a1051 100644 --- a/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs @@ -1,15 +1,12 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. -using System.Text; using System.Text.Json; using System.Text.Json.Nodes; using GitHubExtension.Client; using GitHubExtension.DataManager; -using GitHubExtension.DeveloperId; using GitHubExtension.Helpers; using GitHubExtension.Widgets.Enums; -using Microsoft.Windows.DevHome.SDK; using Microsoft.Windows.Widgets.Providers; namespace GitHubExtension.Widgets; diff --git a/src/GitHubExtension/Widgets/GitHubReviewWidget.cs b/src/GitHubExtension/Widgets/GitHubReviewWidget.cs index 03907b9..db53f32 100644 --- a/src/GitHubExtension/Widgets/GitHubReviewWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubReviewWidget.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Text.Json.Nodes; using GitHubExtension.DataManager; @@ -7,7 +7,8 @@ using Microsoft.Windows.Widgets.Providers; using Octokit; -namespace GitHubExtension.Widgets; +namespace GitHubExtension.Widgets; + internal class GitHubReviewWidget : GitHubUserWidget { protected static readonly new string Name = nameof(GitHubReviewWidget); @@ -15,7 +16,7 @@ internal class GitHubReviewWidget : GitHubUserWidget public GitHubReviewWidget() : base() { - // This widget doest not allow customization, so this value will not change. + // This widget does not allow customization, so this value will not change. ShowCategory = SearchCategory.PullRequests; } diff --git a/src/GitHubExtension/Widgets/GitHubUserWidget.cs b/src/GitHubExtension/Widgets/GitHubUserWidget.cs index d348761..38796c4 100644 --- a/src/GitHubExtension/Widgets/GitHubUserWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubUserWidget.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Text.Json; using System.Text.Json.Nodes; @@ -12,6 +12,7 @@ using Octokit; namespace GitHubExtension.Widgets; + internal abstract class GitHubUserWidget : GitHubWidget { protected static readonly new string Name = nameof(GitHubUserWidget); @@ -318,11 +319,11 @@ public override string GetData(WidgetPageState page) protected IDeveloperId? GetWidgetDeveloperId() { - foreach (var devid in DeveloperIdProvider.GetInstance().GetLoggedInDeveloperIds().DeveloperIds) + foreach (var devId in DeveloperIdProvider.GetInstance().GetLoggedInDeveloperIds().DeveloperIds) { - if (devid.LoginId == DeveloperLoginId) + if (devId.LoginId == DeveloperLoginId) { - return devid; + return devId; } } diff --git a/src/GitHubExtension/Widgets/GitHubWidget.cs b/src/GitHubExtension/Widgets/GitHubWidget.cs index 8d89ff4..dc20840 100644 --- a/src/GitHubExtension/Widgets/GitHubWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubWidget.cs @@ -1,9 +1,8 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Text; using System.Text.Json.Nodes; -using GitHubExtension.Client; using GitHubExtension.DataManager; using GitHubExtension.DeveloperId; using GitHubExtension.Helpers; diff --git a/src/GitHubExtension/Widgets/Guids.cs b/src/GitHubExtension/Widgets/Guids.cs index 78b08ee..7a4a54d 100644 --- a/src/GitHubExtension/Widgets/Guids.cs +++ b/src/GitHubExtension/Widgets/Guids.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Runtime.InteropServices; diff --git a/src/GitHubExtension/Widgets/IWidgetImplFactory.cs b/src/GitHubExtension/Widgets/IWidgetImplFactory.cs index b1aa02c..5d07a78 100644 --- a/src/GitHubExtension/Widgets/IWidgetImplFactory.cs +++ b/src/GitHubExtension/Widgets/IWidgetImplFactory.cs @@ -1,9 +1,10 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Microsoft.Windows.Widgets.Providers; namespace GitHubExtension.Widgets; + internal interface IWidgetImplFactory { public WidgetImpl Create(WidgetContext widgetContext, string state); diff --git a/src/GitHubExtension/Widgets/Logging.cs b/src/GitHubExtension/Widgets/Logging.cs index df2bea8..60ae63a 100644 --- a/src/GitHubExtension/Widgets/Logging.cs +++ b/src/GitHubExtension/Widgets/Logging.cs @@ -1,10 +1,11 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using DevHome.Logging; using Windows.Storage; namespace GitHubExtension.Widgets; + public class Log { private static Logger? _logger; diff --git a/src/GitHubExtension/Widgets/WidgetImpl.cs b/src/GitHubExtension/Widgets/WidgetImpl.cs index f25454c..c6ee2c8 100644 --- a/src/GitHubExtension/Widgets/WidgetImpl.cs +++ b/src/GitHubExtension/Widgets/WidgetImpl.cs @@ -1,10 +1,11 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using GitHubExtension.Telemetry; using Microsoft.Windows.Widgets.Providers; namespace GitHubExtension.Widgets; + public abstract class WidgetImpl { private readonly ILogger logger; diff --git a/src/GitHubExtension/Widgets/WidgetImplFactory.cs b/src/GitHubExtension/Widgets/WidgetImplFactory.cs index 1090d05..b4ead9f 100644 --- a/src/GitHubExtension/Widgets/WidgetImplFactory.cs +++ b/src/GitHubExtension/Widgets/WidgetImplFactory.cs @@ -1,9 +1,10 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Microsoft.Windows.Widgets.Providers; namespace GitHubExtension.Widgets; + internal class WidgetImplFactory : IWidgetImplFactory where T : WidgetImpl, new() { diff --git a/src/GitHubExtension/Widgets/WidgetProvider.cs b/src/GitHubExtension/Widgets/WidgetProvider.cs index 40066a5..74dce35 100644 --- a/src/GitHubExtension/Widgets/WidgetProvider.cs +++ b/src/GitHubExtension/Widgets/WidgetProvider.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Runtime.InteropServices; using Microsoft.Windows.Widgets.Providers; diff --git a/src/GitHubExtension/Widgets/WidgetProviderFactory.cs b/src/GitHubExtension/Widgets/WidgetProviderFactory.cs index 197a07c..a72d36d 100644 --- a/src/GitHubExtension/Widgets/WidgetProviderFactory.cs +++ b/src/GitHubExtension/Widgets/WidgetProviderFactory.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Runtime.InteropServices; using GitHubExtension.Widgets.COM; diff --git a/src/GitHubExtension/Widgets/WidgetServer.cs b/src/GitHubExtension/Widgets/WidgetServer.cs index fb2e343..28a526c 100644 --- a/src/GitHubExtension/Widgets/WidgetServer.cs +++ b/src/GitHubExtension/Widgets/WidgetServer.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Diagnostics; using System.Diagnostics.CodeAnalysis; @@ -7,6 +7,7 @@ using Microsoft.Windows.Widgets.Providers; namespace GitHubExtension.Widgets; + public sealed class WidgetServer : IDisposable { private readonly HashSet registrationCookies = new (); diff --git a/src/GitHubExtensionServer/Logging.cs b/src/GitHubExtensionServer/Logging.cs index 206e05f..f0a12cf 100644 --- a/src/GitHubExtensionServer/Logging.cs +++ b/src/GitHubExtensionServer/Logging.cs @@ -1,10 +1,11 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using DevHome.Logging; using Windows.Storage; namespace GitHubExtension.ExtensionServer; + public class Log { private static Logger? _logger; diff --git a/src/GitHubExtensionServer/Program.cs b/src/GitHubExtensionServer/Program.cs index 0e32e29..17b0a19 100644 --- a/src/GitHubExtensionServer/Program.cs +++ b/src/GitHubExtensionServer/Program.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using GitHubExtension.ExtensionServer; using Microsoft.Windows.AppLifecycle; @@ -8,6 +8,7 @@ using Windows.Management.Deployment; namespace GitHubExtension; + public sealed class Program { [MTAThread] @@ -126,7 +127,7 @@ private static void HandleCOMServerActivation() using var dataUpdater = new DataManager.DataUpdater(GitHubDataManager.Update); _ = dataUpdater.Start(); - // This will make the main thread wait until the event is signalled by the extension class. + // This will make the main thread wait until the event is signaled by the extension class. // Since we have single instance of the extension object, we exit as soon as it is disposed. extensionDisposedEvent.WaitOne(); Log.Logger()?.ReportInfo($"Extension is disposed."); @@ -148,7 +149,7 @@ private static void LogPackageInformation() { foreach (var package in packageManager.FindPackagesForUser(string.Empty, pfn)) { - Log.Logger()?.ReportInfo($"{package.Id.FullName} Devmode: {package.IsDevelopmentMode} Signature: {package.SignatureKind}"); + Log.Logger()?.ReportInfo($"{package.Id.FullName} DevMode: {package.IsDevelopmentMode} Signature: {package.SignatureKind}"); } } } diff --git a/src/Logging/helpers/DictionaryExtensions.cs b/src/Logging/helpers/DictionaryExtensions.cs index ef55d69..3684f0e 100644 --- a/src/Logging/helpers/DictionaryExtensions.cs +++ b/src/Logging/helpers/DictionaryExtensions.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace DevHome.Logging.Helpers; diff --git a/src/Logging/helpers/FileSystem.cs b/src/Logging/helpers/FileSystem.cs index 234bbc8..8a82b41 100644 --- a/src/Logging/helpers/FileSystem.cs +++ b/src/Logging/helpers/FileSystem.cs @@ -1,7 +1,8 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace DevHome.Logging.Helpers; -namespace DevHome.Logging.Helpers; public class FileSystem { public static string BuildOutputFilename(string filename, string outputFolder, bool createPathIfNecessary = true) diff --git a/src/Logging/helpers/StringExtensions.cs b/src/Logging/helpers/StringExtensions.cs index bdc9acf..f560bc3 100644 --- a/src/Logging/helpers/StringExtensions.cs +++ b/src/Logging/helpers/StringExtensions.cs @@ -1,9 +1,10 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Globalization; -namespace DevHome.Logging.Helpers; +namespace DevHome.Logging.Helpers; + public static class StringExtensions { public static string ToStringInvariant(this T value) => Convert.ToString(value, CultureInfo.InvariantCulture)!; diff --git a/src/Logging/listeners/DebugListener.cs b/src/Logging/listeners/DebugListener.cs index 6eb7e1c..2f5fa8f 100644 --- a/src/Logging/listeners/DebugListener.cs +++ b/src/Logging/listeners/DebugListener.cs @@ -1,11 +1,12 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Diagnostics; using System.Globalization; using System.Text; namespace DevHome.Logging.Listeners; + public class DebugListener : ListenerBase { public DebugListener(string name) diff --git a/src/Logging/listeners/DebugListenerOptions.cs b/src/Logging/listeners/DebugListenerOptions.cs index dacd9b2..bdf9fd4 100644 --- a/src/Logging/listeners/DebugListenerOptions.cs +++ b/src/Logging/listeners/DebugListenerOptions.cs @@ -1,7 +1,8 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace DevHome.Logging; + public partial class Options { public bool DebugListenerEnabled { get; set; } = true; diff --git a/src/Logging/listeners/IListener.cs b/src/Logging/listeners/IListener.cs index 65e574e..6bb582e 100644 --- a/src/Logging/listeners/IListener.cs +++ b/src/Logging/listeners/IListener.cs @@ -1,19 +1,20 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. - -namespace DevHome.Logging.Listeners; -public interface IListener -{ - string Name - { - get; - } - - ILoggerHost? Host - { - get; - set; - } - - void HandleLogEvent(LogEvent evt); -} +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace DevHome.Logging.Listeners; + +public interface IListener +{ + string Name + { + get; + } + + ILoggerHost? Host + { + get; + set; + } + + void HandleLogEvent(LogEvent evt); +} diff --git a/src/Logging/listeners/ListenerBase.cs b/src/Logging/listeners/ListenerBase.cs index 8b9c6be..7d6a500 100644 --- a/src/Logging/listeners/ListenerBase.cs +++ b/src/Logging/listeners/ListenerBase.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace DevHome.Logging.Listeners; diff --git a/src/Logging/listeners/LogFileListener.cs b/src/Logging/listeners/LogFileListener.cs index 8a29397..72d505e 100644 --- a/src/Logging/listeners/LogFileListener.cs +++ b/src/Logging/listeners/LogFileListener.cs @@ -1,9 +1,10 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Globalization; namespace DevHome.Logging.Listeners; + public class LogFileListener : ListenerBase, IDisposable { private readonly TextWriter? writer; diff --git a/src/Logging/listeners/LogFileListenerOptions.cs b/src/Logging/listeners/LogFileListenerOptions.cs index 2e035bc..fadf7d8 100644 --- a/src/Logging/listeners/LogFileListenerOptions.cs +++ b/src/Logging/listeners/LogFileListenerOptions.cs @@ -1,7 +1,8 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace DevHome.Logging; -namespace DevHome.Logging; public partial class Options { private const string LogFileNameDefault = "DevHomeGitHubExtension.log"; diff --git a/src/Logging/listeners/StdoutListener.cs b/src/Logging/listeners/StdoutListener.cs index 3a9ab4e..c3375c8 100644 --- a/src/Logging/listeners/StdoutListener.cs +++ b/src/Logging/listeners/StdoutListener.cs @@ -1,9 +1,10 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Globalization; -namespace DevHome.Logging.Listeners; +namespace DevHome.Logging.Listeners; + public class StdoutListener : ListenerBase { private static readonly ConsoleColor CDefaultColor = ConsoleColor.White; diff --git a/src/Logging/listeners/StdoutListenerOptions.cs b/src/Logging/listeners/StdoutListenerOptions.cs index f0e1fb0..7b0c9df 100644 --- a/src/Logging/listeners/StdoutListenerOptions.cs +++ b/src/Logging/listeners/StdoutListenerOptions.cs @@ -1,7 +1,8 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace DevHome.Logging; -namespace DevHome.Logging; public partial class Options { public bool LogStdoutEnabled { get; set; } = true; diff --git a/src/Logging/logger/ILoggerHost.cs b/src/Logging/logger/ILoggerHost.cs index eaaa25c..c085283 100644 --- a/src/Logging/logger/ILoggerHost.cs +++ b/src/Logging/logger/ILoggerHost.cs @@ -1,70 +1,71 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. - -using DevHome.Logging.Listeners; - -namespace DevHome.Logging; -public interface ILoggerHost : IDisposable -{ - string Name - { - get; - } - - Options Options - { - get; - } - - void AddListener(IListener listener); - - void ReportEvent(LogEvent evt); - - void ReportEvent(string component, SeverityLevel severity, string message); - - void ReportEvent(string component, SeverityLevel severity, string message, System.Exception exception); - - void ReportEvent(string component, string subComponent, SeverityLevel severity, string message); - - void ReportEvent(string component, string subComponent, SeverityLevel severity, string message, System.Exception exception); - - void ReportDebug(string component, string message); - - void ReportDebug(string component, string message, Exception exception); - - void ReportDebug(string component, string subComponent, string message); - - void ReportDebug(string component, string subComponent, string message, Exception exception); - - void ReportInfo(string component, string message); - - void ReportInfo(string component, string message, Exception exception); - - void ReportInfo(string component, string subComponent, string message); - - void ReportInfo(string component, string subComponent, string message, Exception exception); - - void ReportWarn(string component, string message); - - void ReportWarn(string component, string message, Exception exception); - - void ReportWarn(string component, string subComponent, string message); - - void ReportWarn(string component, string subComponent, string message, Exception exception); - - void ReportError(string component, string message); - - void ReportError(string component, string message, Exception exception); - - void ReportError(string component, string subComponent, string message); - - void ReportError(string component, string subComponent, string message, Exception exception); - - void ReportCritical(string component, string message); - - void ReportCritical(string component, string message, Exception exception); - - void ReportCritical(string component, string subComponent, string message); - - void ReportCritical(string component, string subComponent, string message, Exception exception); -} +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using DevHome.Logging.Listeners; + +namespace DevHome.Logging; + +public interface ILoggerHost : IDisposable +{ + string Name + { + get; + } + + Options Options + { + get; + } + + void AddListener(IListener listener); + + void ReportEvent(LogEvent evt); + + void ReportEvent(string component, SeverityLevel severity, string message); + + void ReportEvent(string component, SeverityLevel severity, string message, System.Exception exception); + + void ReportEvent(string component, string subComponent, SeverityLevel severity, string message); + + void ReportEvent(string component, string subComponent, SeverityLevel severity, string message, System.Exception exception); + + void ReportDebug(string component, string message); + + void ReportDebug(string component, string message, Exception exception); + + void ReportDebug(string component, string subComponent, string message); + + void ReportDebug(string component, string subComponent, string message, Exception exception); + + void ReportInfo(string component, string message); + + void ReportInfo(string component, string message, Exception exception); + + void ReportInfo(string component, string subComponent, string message); + + void ReportInfo(string component, string subComponent, string message, Exception exception); + + void ReportWarn(string component, string message); + + void ReportWarn(string component, string message, Exception exception); + + void ReportWarn(string component, string subComponent, string message); + + void ReportWarn(string component, string subComponent, string message, Exception exception); + + void ReportError(string component, string message); + + void ReportError(string component, string message, Exception exception); + + void ReportError(string component, string subComponent, string message); + + void ReportError(string component, string subComponent, string message, Exception exception); + + void ReportCritical(string component, string message); + + void ReportCritical(string component, string message, Exception exception); + + void ReportCritical(string component, string subComponent, string message); + + void ReportCritical(string component, string subComponent, string message, Exception exception); +} diff --git a/src/Logging/logger/LogEvent.cs b/src/Logging/logger/LogEvent.cs index 9664afe..a555a41 100644 --- a/src/Logging/logger/LogEvent.cs +++ b/src/Logging/logger/LogEvent.cs @@ -1,108 +1,109 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. - -using DevHome.Logging.Helpers; - -namespace DevHome.Logging; -public class LogEvent -{ - public string Source - { - get; - } - - public string? SubSource - { - get; - } - - public SeverityLevel Severity - { - get; - } - - public string Message - { - get; - } - - public Exception? Exception - { - get; - } +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using DevHome.Logging.Helpers; + +namespace DevHome.Logging; + +public class LogEvent +{ + public string Source + { + get; + } + + public string? SubSource + { + get; + } + + public SeverityLevel Severity + { + get; + } + + public string Message + { + get; + } + + public Exception? Exception + { + get; + } public DateTime Created { get; } - - public TimeSpan Elapsed - { - get; - private set; - } - - internal void SetElapsed(TimeSpan elapsed) => Elapsed = elapsed; - - public static long NoElapsedTicks => -1L; - - public static TimeSpan NoElapsed => new (NoElapsedTicks); - - public bool HasElapsed => Elapsed.Ticks >= 0; - - private LogEvent(string source, string subSource, SeverityLevel severity, string message, Exception exception, TimeSpan elapsed) - { - Source = source; - SubSource = subSource; - Severity = severity; - Message = message; - Exception = exception; + + public TimeSpan Elapsed + { + get; + private set; + } + + internal void SetElapsed(TimeSpan elapsed) => Elapsed = elapsed; + + public static long NoElapsedTicks => -1L; + + public static TimeSpan NoElapsed => new (NoElapsedTicks); + + public bool HasElapsed => Elapsed.Ticks >= 0; + + private LogEvent(string source, string subSource, SeverityLevel severity, string message, Exception exception, TimeSpan elapsed) + { + Source = source; + SubSource = subSource; + Severity = severity; + Message = message; + Exception = exception; Elapsed = elapsed; - Created = DateTime.UtcNow; - } - - public static LogEvent Create(string source, string subSource, SeverityLevel severity, string message) => Create(source, subSource, severity, message, null, NoElapsed); - - public static LogEvent Create(string source, string subSource, SeverityLevel severity, string message, Exception exception) => Create(source, subSource, severity, message, exception, NoElapsed); - - 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 string FullSourceName - { - get - { - if (SubSource != null) - { - return $"{Source}/{SubSource}"; - } - else - { - return Source; - } - } - } - - public override string ToString() - { - var hasException = Exception != null; - - if (hasException && HasElapsed) - { - return "[{0}] {1} {2} {3} {4}".FormatInvariant(FullSourceName, Severity.ToString(), Message, Exception!, Elapsed); - } - else if (hasException && !HasElapsed) - { - return "[{0}] {1} {2} {3}".FormatInvariant(FullSourceName, Severity.ToString(), Message, Exception!); - } - else if (!hasException && HasElapsed) - { - return "[{0}] {1} {2} {3}".FormatInvariant(FullSourceName, Severity.ToString(), Message, Elapsed); - } - else - { - return "[{0}] {1} {2}".FormatInvariant(FullSourceName, Severity.ToString(), Message); - } - } -} + Created = DateTime.UtcNow; + } + + public static LogEvent Create(string source, string subSource, SeverityLevel severity, string message) => Create(source, subSource, severity, message, null, NoElapsed); + + public static LogEvent Create(string source, string subSource, SeverityLevel severity, string message, Exception exception) => Create(source, subSource, severity, message, exception, NoElapsed); + + 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 string FullSourceName + { + get + { + if (SubSource != null) + { + return $"{Source}/{SubSource}"; + } + else + { + return Source; + } + } + } + + public override string ToString() + { + var hasException = Exception != null; + + if (hasException && HasElapsed) + { + return "[{0}] {1} {2} {3} {4}".FormatInvariant(FullSourceName, Severity.ToString(), Message, Exception!, Elapsed); + } + else if (hasException && !HasElapsed) + { + return "[{0}] {1} {2} {3}".FormatInvariant(FullSourceName, Severity.ToString(), Message, Exception!); + } + else if (!hasException && HasElapsed) + { + return "[{0}] {1} {2} {3}".FormatInvariant(FullSourceName, Severity.ToString(), Message, Elapsed); + } + else + { + return "[{0}] {1} {2}".FormatInvariant(FullSourceName, Severity.ToString(), Message); + } + } +} diff --git a/src/Logging/logger/Logger.cs b/src/Logging/logger/Logger.cs index f4ed48a..1601c2a 100644 --- a/src/Logging/logger/Logger.cs +++ b/src/Logging/logger/Logger.cs @@ -1,11 +1,12 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Collections.Concurrent; using DevHome.Logging.Helpers; using DevHome.Logging.Listeners; namespace DevHome.Logging; + public class Logger : ILoggerHost, IDisposable { public Logger(string name, Options options) @@ -13,7 +14,7 @@ public Logger(string name, Options options) Name = name; Options = options; - // Debug Listneer + // Debug listener if (options.DebugListenerEnabled) { var debugListener = new DebugListener("Debug"); diff --git a/src/Logging/logger/Options.cs b/src/Logging/logger/Options.cs index e724748..69971b0 100644 --- a/src/Logging/logger/Options.cs +++ b/src/Logging/logger/Options.cs @@ -1,7 +1,8 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace DevHome.Logging; -namespace DevHome.Logging; public partial class Options : ICloneable { public FailFastSeverityLevel FailFastSeverity { get; set; } = FailFastSeverityLevel.Critical; diff --git a/src/Logging/logger/SeverityLevel.cs b/src/Logging/logger/SeverityLevel.cs index 0471f04..a5565a3 100644 --- a/src/Logging/logger/SeverityLevel.cs +++ b/src/Logging/logger/SeverityLevel.cs @@ -1,37 +1,38 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. - -namespace DevHome.Logging; -public enum SeverityLevel -{ - Debug, - Info, - Warn, - Error, - Critical, -} - -// For setting fail-fast behavior, at what level of failure will we conduct a fail-fast? -// This is mostly intended for specifying whether any error or any critical error causes an FailFast. -// By default we assume any critical failure is by definition something we should not continue after detecting. -public enum FailFastSeverityLevel -{ - Ignore = -1, - Warning = SeverityLevel.Warn, - Error = SeverityLevel.Error, - Critical = SeverityLevel.Critical, -} - -public class FailFast -{ - public static bool IsFailFastSeverityLevel(SeverityLevel severity, FailFastSeverityLevel failFastSeverity) - { - return failFastSeverity switch - { - FailFastSeverityLevel.Warning => severity >= SeverityLevel.Warn, - FailFastSeverityLevel.Error => severity >= SeverityLevel.Error, - FailFastSeverityLevel.Critical => severity >= SeverityLevel.Critical, - _ => false, - }; - } -} +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace DevHome.Logging; + +public enum SeverityLevel +{ + Debug, + Info, + Warn, + Error, + Critical, +} + +// For setting fail-fast behavior, at what level of failure will we conduct a fail-fast? +// This is mostly intended for specifying whether any error or any critical error causes an FailFast. +// By default we assume any critical failure is by definition something we should not continue after detecting. +public enum FailFastSeverityLevel +{ + Ignore = -1, + Warning = SeverityLevel.Warn, + Error = SeverityLevel.Error, + Critical = SeverityLevel.Critical, +} + +public class FailFast +{ + public static bool IsFailFastSeverityLevel(SeverityLevel severity, FailFastSeverityLevel failFastSeverity) + { + return failFastSeverity switch + { + FailFastSeverityLevel.Warning => severity >= SeverityLevel.Warn, + FailFastSeverityLevel.Error => severity >= SeverityLevel.Error, + FailFastSeverityLevel.Critical => severity >= SeverityLevel.Critical, + _ => false, + }; + } +} diff --git a/src/Telemetry/ILogger.cs b/src/Telemetry/ILogger.cs index 2a14d53..965b543 100644 --- a/src/Telemetry/ILogger.cs +++ b/src/Telemetry/ILogger.cs @@ -1,67 +1,67 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. - -using System; +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; using System.Diagnostics.CodeAnalysis; - -namespace GitHubExtension.Telemetry; - -/// -/// To create an instance call LoggerFactory.Get() -/// -public interface ILogger -{ - /// - /// Add a string that we should try stripping out of some of our telemetry for sensitivity reasons (ex. VM name, etc.). - /// We can never be 100% sure we can remove every string, but this should greatly reduce us collecting PII. - /// Note that the order in which AddSensitive is called matters, as later when we call ReplaceSensitiveStrings, it will try - /// finding and replacing the earlier strings first. This can be helpful, since we can target specific - /// strings (like username) first, which should help preserve more information helpful for diagnosis. - /// - /// Sensitive string to add (ex. "c:\xyz") - /// string to replace it with (ex. "-path-") - public void AddSensitiveString(string name, string replaceWith); - - /// - /// Gets a value indicating whether telemetry is on - /// For future use if we add a registry key or some other setting to check if telemetry is turned on. - public bool IsTelemetryOn { get; } - - /// - /// Logs an exception at Measure level. To log at Critical level, the event name needs approval. - /// - /// What we trying to do when the exception occurred. - /// Exception object - /// Optional relatedActivityId which will allow to correlate this telemetry with other telemetry in the same action/activity or thread and corelate them - public void LogException(string action, Exception e, Guid? relatedActivityId = null); - - /// - /// Log the time an action took (ex. time spent on a tool). - /// - /// The measurement we're performing (ex. "DeployTime"). - /// How long the action took in milliseconds. - /// Optional relatedActivityId which will allow to correlate this telemetry with other telemetry in the same action/activity or thread and corelate them - public void LogTimeTaken(string eventName, uint timeTakenMilliseconds, Guid? relatedActivityId = null); - - /// - /// Log an informational event. Typically used for just a single event that's only called one place in the code. - /// If you are logging the same event multiple times, it's best to add a helper method in Logger - /// - /// Name of the error event - /// Determines whether to upload the data to our servers, and on how many machines. - /// Values to send to the telemetry system. - /// Optional relatedActivityId which will allow to correlate this telemetry with other telemetry in the same action/activity or thread and corelate them - /// Anonymous type. - public void Log<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(string eventName, LogLevel level, T data, Guid? relatedActivityId = null); - - /// - /// Log an error event. Typically used for just a single event that's only called one place in the code. - /// If you are logging the same event multiple times, it's best to add a helper method in Logger - /// - /// Name of the error event - /// Determines whether to upload the data to our servers, and on how many machines. - /// Values to send to the telemetry system. - /// Optional Optional relatedActivityId which will allow to correlate this telemetry with other telemetry in the same action/activity or thread and corelate them - /// Anonymous type. - public void LogError<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(string eventName, LogLevel level, T data, Guid? relatedActivityId = null); -} + +namespace GitHubExtension.Telemetry; + +/// +/// To create an instance call LoggerFactory.Get() +/// +public interface ILogger +{ + /// + /// Add a string that we should try stripping out of some of our telemetry for sensitivity reasons (ex. VM name, etc.). + /// We can never be 100% sure we can remove every string, but this should greatly reduce us collecting PII. + /// Note that the order in which AddSensitive is called matters, as later when we call ReplaceSensitiveStrings, it will try + /// finding and replacing the earlier strings first. This can be helpful, since we can target specific + /// strings (like username) first, which should help preserve more information helpful for diagnosis. + /// + /// Sensitive string to add (ex. "c:\xyz") + /// string to replace it with (ex. "-path-") + public void AddSensitiveString(string name, string replaceWith); + + /// + /// Gets a value indicating whether telemetry is on + /// For future use if we add a registry key or some other setting to check if telemetry is turned on. + public bool IsTelemetryOn { get; } + + /// + /// Logs an exception at Measure level. To log at Critical level, the event name needs approval. + /// + /// What we trying to do when the exception occurred. + /// Exception object + /// Optional relatedActivityId which will allow to correlate this telemetry with other telemetry in the same action/activity or thread and corelate them + public void LogException(string action, Exception e, Guid? relatedActivityId = null); + + /// + /// Log the time an action took (ex. time spent on a tool). + /// + /// The measurement we're performing (ex. "DeployTime"). + /// How long the action took in milliseconds. + /// Optional relatedActivityId which will allow to correlate this telemetry with other telemetry in the same action/activity or thread and corelate them + public void LogTimeTaken(string eventName, uint timeTakenMilliseconds, Guid? relatedActivityId = null); + + /// + /// Log an informational event. Typically used for just a single event that's only called one place in the code. + /// If you are logging the same event multiple times, it's best to add a helper method in Logger + /// + /// Name of the error event + /// Determines whether to upload the data to our servers, and on how many machines. + /// Values to send to the telemetry system. + /// Optional relatedActivityId which will allow to correlate this telemetry with other telemetry in the same action/activity or thread and corelate them + /// Anonymous type. + public void Log<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(string eventName, LogLevel level, T data, Guid? relatedActivityId = null); + + /// + /// Log an error event. Typically used for just a single event that's only called one place in the code. + /// If you are logging the same event multiple times, it's best to add a helper method in Logger + /// + /// Name of the error event + /// Determines whether to upload the data to our servers, and on how many machines. + /// Values to send to the telemetry system. + /// Optional Optional relatedActivityId which will allow to correlate this telemetry with other telemetry in the same action/activity or thread and corelate them + /// Anonymous type. + public void LogError<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(string eventName, LogLevel level, T data, Guid? relatedActivityId = null); +} diff --git a/src/Telemetry/LogLevel.cs b/src/Telemetry/LogLevel.cs index 0917717..5fd141f 100644 --- a/src/Telemetry/LogLevel.cs +++ b/src/Telemetry/LogLevel.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension.Telemetry; diff --git a/src/Telemetry/Logger.cs b/src/Telemetry/Logger.cs index fb22374..21af0ee 100644 --- a/src/Telemetry/Logger.cs +++ b/src/Telemetry/Logger.cs @@ -1,266 +1,266 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. - -using System; -using System.Collections.Generic; +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -using System.Diagnostics.Tracing; -using System.IO; -using System.Linq; -using System.Text; -using Microsoft.Diagnostics.Telemetry; - -namespace GitHubExtension.Telemetry; - -internal class Logger : ILogger -{ - private const string ProviderName = "Microsoft.GitHubExtension"; - - /// - /// Time Taken Event Name - /// - private const string TimeTakenEventName = "TimeTaken"; - - /// - /// Exception Thrown Event Name - /// - private const string ExceptionThrownEventName = "ExceptionThrown"; - - private static readonly Guid DefaultRelatedActivityId = Guid.Empty; - - /// - /// Can only have one EventSource alive per process, so just create one statically. - /// - private static readonly EventSource TelemetryEventSourceInstance = new TelemetryEventSource(ProviderName); - - /// - /// 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 }; - - /// - /// Logs error telemetry locally, but shouldn't upload it. Similar to an ETW event. - /// - 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 }; - - /// - /// 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 }; - - /// - /// 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 }; - - /// - /// 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 }; - - /// - /// Logs critical telemetry. - /// This should be sent back on all devices sampled at 100%. - /// - 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 }; - - /// - /// ActivityId so we can correlate all events in the same run - /// - private static Guid activityId = Guid.NewGuid(); - - /// - /// List of strings we should try removing for sensitivity reasons. - /// - private readonly List> sensitiveStrings = new (); - - /// - /// Initializes a new instance of the class. - /// Prevents a default instance of the Logger class from being created. - /// - internal Logger() - { - } - - /// - /// Gets a value indicating whether telemetry is on - /// For future use if we add a registry key or some other setting to check if telemetry is turned on. - public bool IsTelemetryOn => true; - - /// - /// Add a string that we should try stripping out of some of our telemetry for sensitivity reasons (ex. VM name, etc.). - /// We can never be 100% sure we can remove every string, but this should greatly reduce us collecting PII. - /// Note that the order in which AddSensitive is called matters, as later when we call ReplaceSensitiveStrings, it will try - /// finding and replacing the earlier strings first. This can be helpful, since we can target specific - /// strings (like username) first, which should help preserve more information helpful for diagnosis. - /// - /// Sensitive string to add (ex. "c:\xyz") - /// string to replace it with (ex. "-path-") - public void AddSensitiveString(string name, string replaceWith) - { - // Make sure the name isn't blank, hasn't already been added, and is greater than three characters. - // Otherwise they could name their VM "a", and then we would end up replacing every "a" with another string. - if (!string.IsNullOrWhiteSpace(name) && name.Length > 3 && !sensitiveStrings.Exists(item => name.Equals(item.Key, StringComparison.Ordinal))) - { - sensitiveStrings.Add(new KeyValuePair(name, replaceWith ?? string.Empty)); - } - } - - /// - /// Logs an exception at Measure level. To log at Critical level, the event name needs approval. - /// - /// What we trying to do when the exception occurred. - /// Exception object - /// Optional relatedActivityId which will allow to correlate this telemetry with other telemetry in the same action/activity or thread and corelate them - public void LogException(string action, Exception e, Guid? relatedActivityId = null) - { - var innerMessage = ReplaceSensitiveStrings(e.InnerException?.Message); - var innerStackTrace = new StringBuilder(); - var innerException = e.InnerException; - while (innerException != null) - { - innerStackTrace.Append(innerException.StackTrace); - - // Separating by 2 new lines to distinguish between different exceptions. - innerStackTrace.AppendLine(); - innerStackTrace.AppendLine(); - innerException = innerException.InnerException; - } - - LogError( - ExceptionThrownEventName, - LogLevel.Measure, - new - { - action, - name = e.GetType().Name, - stackTrace = e.StackTrace, - innerName = e.InnerException?.GetType().Name, - innerMessage, - innerStackTrace = innerStackTrace.ToString(), - message = ReplaceSensitiveStrings(e.Message), - }, - relatedActivityId ?? DefaultRelatedActivityId); - } - - /// - /// Log the time an action took (ex. deploy time). - /// - /// The measurement we're performing (ex. "DeployTime"). - /// How long the action took in milliseconds. - /// Optional relatedActivityId which will allow to correlate this telemetry with other telemetry in the same action/activity or thread and corelate them - public void LogTimeTaken(string eventName, uint timeTakenMilliseconds, Guid? relatedActivityId = null) - { - Log( - TimeTakenEventName, - LogLevel.Critical, - new - { - eventName, - timeTakenMilliseconds, - }, - relatedActivityId ?? DefaultRelatedActivityId); - } - - /// - /// Log an informational event. Typically used for just a single event that's only called one place in the code. - /// - /// Name of the error event - /// Determines whether to upload the data to our servers, and on how many machines. - /// Values to send to the telemetry system. - /// Optional relatedActivityId which will allow to correlate this telemetry with other telemetry in the same action/activity or thread and corelate them - /// Anonymous type. - public void Log<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(string eventName, LogLevel level, T data, Guid? relatedActivityId = null) - { - WriteTelemetryEvent(eventName, level, relatedActivityId ?? DefaultRelatedActivityId, false, data); - } - - /// - /// Log an error event. Typically used for just a single event that's only called one place in the code. - /// - /// Name of the error event - /// Determines whether to upload the data to our servers, and on how many machines. - /// Values to send to the telemetry system. - /// Optional Optional relatedActivityId which will allow to correlate this telemetry with other telemetry in the same action/activity or thread and corelate them - /// Anonymous type. - public void LogError<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(string eventName, LogLevel level, T data, Guid? relatedActivityId = null) - { - WriteTelemetryEvent(eventName, level, relatedActivityId ?? DefaultRelatedActivityId, true, data); - } - - /// - /// Replaces sensitive strings in a string with non sensitive strings. - /// - /// Before, unstripped string. - /// After, stripped string - private string ReplaceSensitiveStrings(string message) - { - if (message != null) - { - foreach (var pair in sensitiveStrings) - { - // There's no String.Replace() with case insensitivity. - // We could use Regular Expressions here for searching for case-insensitive string matches, - // but it's not easy to specify the RegEx timeout value for .net 4.0. And we were worried - // about rare cases where the user could accidentally lock us up with RegEx, since we're using strings - // provided by the user, so just use a simple non-RegEx replacement algorithm instead. - var sb = new StringBuilder(); - var i = 0; - while (true) - { - // Find the string to strip out. - var foundPosition = message.IndexOf(pair.Key, i, StringComparison.OrdinalIgnoreCase); - if (foundPosition < 0) - { - sb.Append(message, i, message.Length - i); - message = sb.ToString(); - break; - } - - // Replace the string. - sb.Append(message, i, foundPosition - i); - sb.Append(pair.Value); - i = foundPosition + pair.Key.Length; - } - } - } - - return message; +using System.Diagnostics.Tracing; +using System.IO; +using System.Linq; +using System.Text; +using Microsoft.Diagnostics.Telemetry; + +namespace GitHubExtension.Telemetry; + +internal class Logger : ILogger +{ + private const string ProviderName = "Microsoft.GitHubExtension"; + + /// + /// Time Taken Event Name + /// + private const string TimeTakenEventName = "TimeTaken"; + + /// + /// Exception Thrown Event Name + /// + private const string ExceptionThrownEventName = "ExceptionThrown"; + + private static readonly Guid DefaultRelatedActivityId = Guid.Empty; + + /// + /// Can only have one EventSource alive per process, so just create one statically. + /// + private static readonly EventSource TelemetryEventSourceInstance = new TelemetryEventSource(ProviderName); + + /// + /// 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 }; + + /// + /// Logs error telemetry locally, but shouldn't upload it. Similar to an ETW event. + /// + 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 }; + + /// + /// 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 }; + + /// + /// 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 }; + + /// + /// 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 }; + + /// + /// Logs critical telemetry. + /// This should be sent back on all devices sampled at 100%. + /// + 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 }; + + /// + /// ActivityId so we can correlate all events in the same run + /// + private static Guid activityId = Guid.NewGuid(); + + /// + /// List of strings we should try removing for sensitivity reasons. + /// + private readonly List> sensitiveStrings = new (); + + /// + /// Initializes a new instance of the class. + /// Prevents a default instance of the Logger class from being created. + /// + internal Logger() + { } - /// - /// Writes the telemetry event info using the TraceLogging API. - /// - /// Anonymous type. - /// Name of the event. - /// Determines whether to upload the data to our servers, and the sample set of host machines. - /// Set to true if an error condition raised this event. + /// + /// Gets a value indicating whether telemetry is on + /// For future use if we add a registry key or some other setting to check if telemetry is turned on. + public bool IsTelemetryOn => true; + + /// + /// Add a string that we should try stripping out of some of our telemetry for sensitivity reasons (ex. VM name, etc.). + /// We can never be 100% sure we can remove every string, but this should greatly reduce us collecting PII. + /// Note that the order in which AddSensitive is called matters, as later when we call ReplaceSensitiveStrings, it will try + /// finding and replacing the earlier strings first. This can be helpful, since we can target specific + /// strings (like username) first, which should help preserve more information helpful for diagnosis. + /// + /// Sensitive string to add (ex. "c:\xyz") + /// string to replace it with (ex. "-path-") + public void AddSensitiveString(string name, string replaceWith) + { + // Make sure the name isn't blank, hasn't already been added, and is greater than three characters. + // Otherwise they could name their VM "a", and then we would end up replacing every "a" with another string. + if (!string.IsNullOrWhiteSpace(name) && name.Length > 3 && !sensitiveStrings.Exists(item => name.Equals(item.Key, StringComparison.Ordinal))) + { + sensitiveStrings.Add(new KeyValuePair(name, replaceWith ?? string.Empty)); + } + } + + /// + /// Logs an exception at Measure level. To log at Critical level, the event name needs approval. + /// + /// What we trying to do when the exception occurred. + /// Exception object + /// Optional relatedActivityId which will allow to correlate this telemetry with other telemetry in the same action/activity or thread and corelate them + public void LogException(string action, Exception e, Guid? relatedActivityId = null) + { + var innerMessage = ReplaceSensitiveStrings(e.InnerException?.Message); + var innerStackTrace = new StringBuilder(); + var innerException = e.InnerException; + while (innerException != null) + { + innerStackTrace.Append(innerException.StackTrace); + + // Separating by 2 new lines to distinguish between different exceptions. + innerStackTrace.AppendLine(); + innerStackTrace.AppendLine(); + innerException = innerException.InnerException; + } + + LogError( + ExceptionThrownEventName, + LogLevel.Measure, + new + { + action, + name = e.GetType().Name, + stackTrace = e.StackTrace, + innerName = e.InnerException?.GetType().Name, + innerMessage, + innerStackTrace = innerStackTrace.ToString(), + message = ReplaceSensitiveStrings(e.Message), + }, + relatedActivityId ?? DefaultRelatedActivityId); + } + + /// + /// Log the time an action took (ex. deploy time). + /// + /// The measurement we're performing (ex. "DeployTime"). + /// How long the action took in milliseconds. + /// Optional relatedActivityId which will allow to correlate this telemetry with other telemetry in the same action/activity or thread and corelate them + public void LogTimeTaken(string eventName, uint timeTakenMilliseconds, Guid? relatedActivityId = null) + { + Log( + TimeTakenEventName, + LogLevel.Critical, + new + { + eventName, + timeTakenMilliseconds, + }, + relatedActivityId ?? DefaultRelatedActivityId); + } + + /// + /// Log an informational event. Typically used for just a single event that's only called one place in the code. + /// + /// Name of the error event + /// Determines whether to upload the data to our servers, and on how many machines. + /// Values to send to the telemetry system. + /// Optional relatedActivityId which will allow to correlate this telemetry with other telemetry in the same action/activity or thread and corelate them + /// Anonymous type. + public void Log<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(string eventName, LogLevel level, T data, Guid? relatedActivityId = null) + { + WriteTelemetryEvent(eventName, level, relatedActivityId ?? DefaultRelatedActivityId, false, data); + } + + /// + /// Log an error event. Typically used for just a single event that's only called one place in the code. + /// + /// Name of the error event + /// Determines whether to upload the data to our servers, and on how many machines. + /// Values to send to the telemetry system. + /// Optional Optional relatedActivityId which will allow to correlate this telemetry with other telemetry in the same action/activity or thread and corelate them + /// Anonymous type. + public void LogError<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(string eventName, LogLevel level, T data, Guid? relatedActivityId = null) + { + WriteTelemetryEvent(eventName, level, relatedActivityId ?? DefaultRelatedActivityId, true, data); + } + + /// + /// Replaces sensitive strings in a string with non sensitive strings. + /// + /// Before, unstripped string. + /// After, stripped string + private string ReplaceSensitiveStrings(string message) + { + if (message != null) + { + foreach (var pair in sensitiveStrings) + { + // There's no String.Replace() with case insensitivity. + // We could use Regular Expressions here for searching for case-insensitive string matches, + // but it's not easy to specify the RegEx timeout value for .net 4.0. And we were worried + // about rare cases where the user could accidentally lock us up with RegEx, since we're using strings + // provided by the user, so just use a simple non-RegEx replacement algorithm instead. + var sb = new StringBuilder(); + var i = 0; + while (true) + { + // Find the string to strip out. + var foundPosition = message.IndexOf(pair.Key, i, StringComparison.OrdinalIgnoreCase); + if (foundPosition < 0) + { + sb.Append(message, i, message.Length - i); + message = sb.ToString(); + break; + } + + // Replace the string. + sb.Append(message, i, foundPosition - i); + sb.Append(pair.Value); + i = foundPosition + pair.Key.Length; + } + } + } + + return message; + } + + /// + /// Writes the telemetry event info using the TraceLogging API. + /// + /// Anonymous type. + /// Name of the event. + /// Determines whether to upload the data to our servers, and the sample set of host machines. + /// Set to true if an error condition raised this event. /// Values to send to the telemetry system. [UnconditionalSuppressMessage( "ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "The type passed for data is an anonymous type consisting of primitive type properties declared in an assembly that is not marked trimmable.")] - private void WriteTelemetryEvent<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(string eventName, LogLevel level, Guid relatedActivityId, bool isError, T data) - { - EventSourceOptions telemetryOptions; - if (IsTelemetryOn) - { + Justification = "The type passed for data is an anonymous type consisting of primitive type properties declared in an assembly that is not marked trimmable.")] + private void WriteTelemetryEvent<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(string eventName, LogLevel level, Guid relatedActivityId, bool isError, T data) + { + EventSourceOptions telemetryOptions; + if (IsTelemetryOn) + { telemetryOptions = level switch { LogLevel.Critical => isError ? Logger.CriticalDataErrorOption : Logger.CriticalDataOption, @@ -268,34 +268,34 @@ private string ReplaceSensitiveStrings(string message) LogLevel.Info => isError ? Logger.InfoErrorOption : Logger.InfoOption, _ => isError ? Logger.LocalErrorOption : Logger.LocalOption, }; - } - else - { - // The telemetry is not turned on, downgrade to local telemetry - telemetryOptions = isError ? Logger.LocalErrorOption : Logger.LocalOption; - } - - TelemetryEventSourceInstance.Write(eventName, ref telemetryOptions, ref activityId, ref relatedActivityId, ref data); - } - - internal void AddWellKnownSensitiveStrings() - { - try - { - // This should convert "c:\users\johndoe" to "". - var userDirectory = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)).FullName; - AddSensitiveString(Directory.GetParent(userDirectory).ToString(), ""); - - // Include both these names, since they should cover the logged on user, and the user who is running the tools built on top of these API's - // These names should almost always be the same, but technically could be different. - AddSensitiveString(Environment.UserName, ""); - var currentUserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name.Split('\\').Last(); - AddSensitiveString(currentUserName, ""); - } - catch (Exception e) - { - // Catch and log exception - LogException("AddSensitiveStrings", e); - } - } -} + } + else + { + // The telemetry is not turned on, downgrade to local telemetry + telemetryOptions = isError ? Logger.LocalErrorOption : Logger.LocalOption; + } + + TelemetryEventSourceInstance.Write(eventName, ref telemetryOptions, ref activityId, ref relatedActivityId, ref data); + } + + internal void AddWellKnownSensitiveStrings() + { + try + { + // This should convert "c:\users\johndoe" to "". + var userDirectory = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)).FullName; + AddSensitiveString(Directory.GetParent(userDirectory).ToString(), ""); + + // Include both these names, since they should cover the logged on user, and the user who is running the tools built on top of these API's + // These names should almost always be the same, but technically could be different. + AddSensitiveString(Environment.UserName, ""); + var currentUserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name.Split('\\').Last(); + AddSensitiveString(currentUserName, ""); + } + catch (Exception e) + { + // Catch and log exception + LogException("AddSensitiveStrings", e); + } + } +} diff --git a/src/Telemetry/LoggerFactory.cs b/src/Telemetry/LoggerFactory.cs index 28a4abb..600c85a 100644 --- a/src/Telemetry/LoggerFactory.cs +++ b/src/Telemetry/LoggerFactory.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension.Telemetry; diff --git a/test/Console/Program.cs b/test/Console/Program.cs index 6f99f5e..d6d9c0b 100644 --- a/test/Console/Program.cs +++ b/test/Console/Program.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using GitHubExtension; diff --git a/test/GitHubExtension/DataStore/DataManagerTests.cs b/test/GitHubExtension/DataStore/DataManagerTests.cs index ebddafd..fc9313f 100644 --- a/test/GitHubExtension/DataStore/DataManagerTests.cs +++ b/test/GitHubExtension/DataStore/DataManagerTests.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension.Test; diff --git a/test/GitHubExtension/DataStore/DataObjectTests.cs b/test/GitHubExtension/DataStore/DataObjectTests.cs index 0de7acf..8af7574 100644 --- a/test/GitHubExtension/DataStore/DataObjectTests.cs +++ b/test/GitHubExtension/DataStore/DataObjectTests.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Dapper.Contrib.Extensions; using DevHome.Logging; @@ -446,9 +446,9 @@ public void ReadAndWriteCheckRun() } // Verify objects work. - var pullrequest = DataModel.PullRequest.GetById(dataStore, 1); - Assert.IsNotNull(pullrequest); - var checksForPullRequest = pullrequest.Checks; + var pullRequest = DataModel.PullRequest.GetById(dataStore, 1); + Assert.IsNotNull(pullRequest); + var checksForPullRequest = pullRequest.Checks; Assert.IsNotNull(checksForPullRequest); Assert.AreEqual(2, checksForPullRequest.Count()); foreach (var check in checksForPullRequest) @@ -457,12 +457,12 @@ public void ReadAndWriteCheckRun() Assert.IsTrue(check.Completed); } - var failedChecks = pullrequest.FailedChecks; + var failedChecks = pullRequest.FailedChecks; Assert.IsNotNull(failedChecks); Assert.AreEqual(1, failedChecks.Count()); - Assert.AreEqual(CheckStatus.Completed, pullrequest.ChecksStatus); - Assert.AreEqual(CheckConclusion.Failure, pullrequest.ChecksConclusion); + Assert.AreEqual(CheckStatus.Completed, pullRequest.ChecksStatus); + Assert.AreEqual(CheckConclusion.Failure, pullRequest.ChecksConclusion); testListener.PrintEventCounts(); Assert.AreEqual(false, testListener.FoundErrors()); @@ -483,7 +483,7 @@ public void ReadAndWriteStatusAndNotification() dataStore.Create(); Assert.IsNotNull(dataStore.Connection); - // Add checkruns. + // Add CheckRuns. var checks = new List { { new CheckRun { HeadSha = "1234abcd", Name = "Build x86", InternalId = 16, ConclusionId = 1, StatusId = 3, DetailsUrl = "https://link/to/failed/build" } }, @@ -506,9 +506,9 @@ public void ReadAndWriteStatusAndNotification() dataStore.Connection.Insert(new PullRequest { Title = "Fix the things", InternalId = 42, Number = 5, HeadSha = "1234abcd", AuthorId = 1, RepositoryId = 1 }); // Add PullRequestStatus - var pullrequest = DataModel.PullRequest.GetById(dataStore, 1); - Assert.IsNotNull(pullrequest); - var prStatus = PullRequestStatus.Add(dataStore, pullrequest); + var pullRequest = DataModel.PullRequest.GetById(dataStore, 1); + Assert.IsNotNull(pullRequest); + var prStatus = PullRequestStatus.Add(dataStore, pullRequest); TestContext?.WriteLine($" PR: {prStatus.PullRequest.Number} Status: {prStatus.Id}: {prStatus.Conclusion} - {prStatus.DetailsUrl}"); Assert.AreEqual("https://link/to/failed/build", prStatus.DetailsUrl); @@ -580,9 +580,9 @@ public void ReadAndWriteReview() } // Verify objects work. - var pullrequest = PullRequest.GetById(dataStore, 1); - Assert.IsNotNull(pullrequest); - var reviewsForPullRequest = pullrequest.Reviews; + var pullRequest = PullRequest.GetById(dataStore, 1); + Assert.IsNotNull(pullRequest); + var reviewsForPullRequest = pullRequest.Reviews; Assert.IsNotNull(reviewsForPullRequest); Assert.AreEqual(2, reviewsForPullRequest.Count()); foreach (var review in reviewsForPullRequest) diff --git a/test/GitHubExtension/DataStore/DataStoreTestsSetup.cs b/test/GitHubExtension/DataStore/DataStoreTestsSetup.cs index 2f7c055..45e5b77 100644 --- a/test/GitHubExtension/DataStore/DataStoreTestsSetup.cs +++ b/test/GitHubExtension/DataStore/DataStoreTestsSetup.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension.Test; diff --git a/test/GitHubExtension/DataStore/OctokitIngestionTests.cs b/test/GitHubExtension/DataStore/OctokitIngestionTests.cs index 346f7d9..f916d6d 100644 --- a/test/GitHubExtension/DataStore/OctokitIngestionTests.cs +++ b/test/GitHubExtension/DataStore/OctokitIngestionTests.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Dapper.Contrib.Extensions; using GitHubExtension.Client; diff --git a/test/GitHubExtension/DeveloperId/CredentialVaultTests.cs b/test/GitHubExtension/DeveloperId/CredentialVaultTests.cs index 4dc7871..125ea76 100644 --- a/test/GitHubExtension/DeveloperId/CredentialVaultTests.cs +++ b/test/GitHubExtension/DeveloperId/CredentialVaultTests.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Net; using GitHubExtension.DeveloperId; diff --git a/test/GitHubExtension/DeveloperId/DeveloperIdProviderTests.cs b/test/GitHubExtension/DeveloperId/DeveloperIdProviderTests.cs index 838fb0a..9a9889b 100644 --- a/test/GitHubExtension/DeveloperId/DeveloperIdProviderTests.cs +++ b/test/GitHubExtension/DeveloperId/DeveloperIdProviderTests.cs @@ -1,11 +1,12 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Net; using GitHubExtension.DeveloperId; using Microsoft.Windows.DevHome.SDK; namespace GitHubExtension.Test; + public partial class DeveloperIdTests { private CredentialVault SetupCleanCredentialVaultClean() diff --git a/test/GitHubExtension/DeveloperId/DeveloperIdTestsSetup.cs b/test/GitHubExtension/DeveloperId/DeveloperIdTestsSetup.cs index 6a6c000..950d82e 100644 --- a/test/GitHubExtension/DeveloperId/DeveloperIdTestsSetup.cs +++ b/test/GitHubExtension/DeveloperId/DeveloperIdTestsSetup.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using GitHubExtension.DeveloperId; diff --git a/test/GitHubExtension/DeveloperId/FunctionalTests.cs b/test/GitHubExtension/DeveloperId/FunctionalTests.cs index 5f6fa78..5c9dba5 100644 --- a/test/GitHubExtension/DeveloperId/FunctionalTests.cs +++ b/test/GitHubExtension/DeveloperId/FunctionalTests.cs @@ -1,10 +1,11 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using GitHubExtension.DeveloperId; using Microsoft.Windows.DevHome.SDK; namespace GitHubExtension.Test; + public partial class DeveloperIdTests { [TestMethod] diff --git a/test/GitHubExtension/DeveloperId/LoginUITests.cs b/test/GitHubExtension/DeveloperId/LoginUITests.cs index 8ff7e85..618270b 100644 --- a/test/GitHubExtension/DeveloperId/LoginUITests.cs +++ b/test/GitHubExtension/DeveloperId/LoginUITests.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using GitHubExtension.DeveloperId; using GitHubExtension.Test.Mocks; diff --git a/test/GitHubExtension/GitHubProviderTests.cs b/test/GitHubExtension/GitHubProviderTests.cs index 68f5006..e766674 100644 --- a/test/GitHubExtension/GitHubProviderTests.cs +++ b/test/GitHubExtension/GitHubProviderTests.cs @@ -1,9 +1,10 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Microsoft.Windows.DevHome.SDK; namespace GitHubExtension.Test; + [TestClass] public partial class GitHubProviderTests { @@ -112,7 +113,7 @@ public void CanClone() [TestMethod] [TestCategory("Unit")] - [Ignore("Ignoring right now until mock repo is implemeneted")] + [Ignore("Ignoring right now until mock repo is implemented")] public void CloneViaMakingRepoObject() { /* diff --git a/test/GitHubExtension/Helpers/FileHelpers.cs b/test/GitHubExtension/Helpers/FileHelpers.cs index f2e9eeb..f1ade2e 100644 --- a/test/GitHubExtension/Helpers/FileHelpers.cs +++ b/test/GitHubExtension/Helpers/FileHelpers.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension.Test; diff --git a/test/GitHubExtension/Helpers/TestOptions.cs b/test/GitHubExtension/Helpers/TestOptions.cs index 9896b48..a2b8865 100644 --- a/test/GitHubExtension/Helpers/TestOptions.cs +++ b/test/GitHubExtension/Helpers/TestOptions.cs @@ -1,10 +1,11 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using DevHome.Logging; using GitHubExtension.DataModel; namespace GitHubExtension.Test; + public partial class TestOptions { public Options LogOptions { get; set; } diff --git a/test/GitHubExtension/Helpers/TestSetupHelpers.cs b/test/GitHubExtension/Helpers/TestSetupHelpers.cs index 4a7c9c6..c7a4a91 100644 --- a/test/GitHubExtension/Helpers/TestSetupHelpers.cs +++ b/test/GitHubExtension/Helpers/TestSetupHelpers.cs @@ -1,74 +1,74 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. - +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + using DevHome.Logging; using DevHome.Logging.Helpers; using GitHubExtension.DataModel; -namespace GitHubExtension.Test; - -public partial class TestHelpers -{ - private const string DataBaseFileName = "GitHubExtension-Test.db"; - private const string LogFileName = "GitHubExtension-{now}.log"; - - public static void CleanupTempTestOptions(TestOptions options, TestContext context) - { - // We put DataStore and Log into the same path. - var path = options.DataStoreOptions.DataStoreFolderPath; - - // Directory delete will fail if a file has the name of the directory, so to be - // thorough, check for file delete first. - if (File.Exists(path)) - { - context?.WriteLine($"Cleanup: Deleting file {path}"); - File.Delete(path); - } - - if (Directory.Exists(path)) - { - context?.WriteLine($"Cleanup: Deleting folder {path}"); - Directory.Delete(path, true); - } - - // Intentionally not catching IO errors on cleanup, as that indicates a test problem. - } - - public static TestOptions SetupTempTestOptions(TestContext context) - { - // Since all test created locations are ultimately captured in the Options, we will use - // the Options as truth for storing the test location data to keep all of the - // test locations in one data object to simplify test variables we are tracking and - // to be consistent in test setup/cleanup. - var path = GetUniqueFolderPath("GHPT"); +namespace GitHubExtension.Test; + +public partial class TestHelpers +{ + private const string DataBaseFileName = "GitHubExtension-Test.db"; + private const string LogFileName = "GitHubExtension-{now}.log"; + + public static void CleanupTempTestOptions(TestOptions options, TestContext context) + { + // We put DataStore and Log into the same path. + var path = options.DataStoreOptions.DataStoreFolderPath; + + // Directory delete will fail if a file has the name of the directory, so to be + // thorough, check for file delete first. + if (File.Exists(path)) + { + context?.WriteLine($"Cleanup: Deleting file {path}"); + File.Delete(path); + } + + if (Directory.Exists(path)) + { + context?.WriteLine($"Cleanup: Deleting folder {path}"); + Directory.Delete(path, true); + } + + // Intentionally not catching IO errors on cleanup, as that indicates a test problem. + } + + public static TestOptions SetupTempTestOptions(TestContext context) + { + // Since all test created locations are ultimately captured in the Options, we will use + // the Options as truth for storing the test location data to keep all of the + // test locations in one data object to simplify test variables we are tracking and + // to be consistent in test setup/cleanup. + var path = GetUniqueFolderPath("GHPT"); var options = new TestOptions(); options.LogOptions.FailFastSeverity = FailFastSeverityLevel.Ignore; options.LogOptions.LogFileFilter = SeverityLevel.Debug; options.LogOptions.LogFileFolderRoot = path; options.LogOptions.LogFileName = LogFileName; - options.DataStoreOptions.DataStoreFileName = DataBaseFileName; + options.DataStoreOptions.DataStoreFileName = DataBaseFileName; options.DataStoreOptions.DataStoreFolderPath = path; - options.DataStoreOptions.DataStoreSchema = new GitHubDataStoreSchema(); - - context?.WriteLine($"Temp folder for test run is: {GetTempTestFolderPath(options)}"); - context?.WriteLine($"Temp DataStore file path for test run is: {GetDataStoreFilePath(options)}"); - context?.WriteLine($"Temp Log file path for test run is: {GetLogFilePath(options)}"); - return options; - } - - public static string GetTempTestFolderPath(TestOptions options) - { - // For simplicity putting log and datastore in same root folder. - return options.DataStoreOptions.DataStoreFolderPath; - } - - public static string GetDataStoreFilePath(TestOptions options) - { - return Path.Combine(options.DataStoreOptions.DataStoreFolderPath, options.DataStoreOptions.DataStoreFileName); - } - - public static string GetLogFilePath(TestOptions options) + options.DataStoreOptions.DataStoreSchema = new GitHubDataStoreSchema(); + + context?.WriteLine($"Temp folder for test run is: {GetTempTestFolderPath(options)}"); + context?.WriteLine($"Temp DataStore file path for test run is: {GetDataStoreFilePath(options)}"); + context?.WriteLine($"Temp Log file path for test run is: {GetLogFilePath(options)}"); + return options; + } + + public static string GetTempTestFolderPath(TestOptions options) + { + // For simplicity putting log and datastore in same root folder. + return options.DataStoreOptions.DataStoreFolderPath; + } + + public static string GetDataStoreFilePath(TestOptions options) + { + return Path.Combine(options.DataStoreOptions.DataStoreFolderPath, options.DataStoreOptions.DataStoreFileName); + } + + public static string GetLogFilePath(TestOptions options) { - return FileSystem.SubstituteOutputFilename(options.LogOptions.LogFileName, options.LogOptions.LogFileFolderPath); - } -} + return FileSystem.SubstituteOutputFilename(options.LogOptions.LogFileName, options.LogOptions.LogFileFolderPath); + } +} diff --git a/test/GitHubExtension/Initialize.cs b/test/GitHubExtension/Initialize.cs index 46e5962..d6939da 100644 --- a/test/GitHubExtension/Initialize.cs +++ b/test/GitHubExtension/Initialize.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Microsoft.Windows.ApplicationModel.DynamicDependency; diff --git a/test/GitHubExtension/Mocks/DeveloperIdProvider.cs b/test/GitHubExtension/Mocks/DeveloperIdProvider.cs index cdca1a2..4800dfe 100644 --- a/test/GitHubExtension/Mocks/DeveloperIdProvider.cs +++ b/test/GitHubExtension/Mocks/DeveloperIdProvider.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Security; using GitHubExtension.DeveloperId; diff --git a/test/GitHubExtension/Mocks/Repository.cs b/test/GitHubExtension/Mocks/Repository.cs index f389983..0db5416 100644 --- a/test/GitHubExtension/Mocks/Repository.cs +++ b/test/GitHubExtension/Mocks/Repository.cs @@ -1,10 +1,11 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Microsoft.Windows.DevHome.SDK; using Windows.Foundation; namespace GitHubExtension.Test.Mocks; + public class MockRepository : IRepository { public string DisplayName => "Mock Repository"; diff --git a/test/GitHubExtension/TestClass.cs b/test/GitHubExtension/TestClass.cs index d395478..1bb75d5 100644 --- a/test/GitHubExtension/TestClass.cs +++ b/test/GitHubExtension/TestClass.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using System.Diagnostics; using GitHubExtension.DeveloperId; diff --git a/test/GitHubExtension/TestListener.cs b/test/GitHubExtension/TestListener.cs index a21b5a9..c08f48e 100644 --- a/test/GitHubExtension/TestListener.cs +++ b/test/GitHubExtension/TestListener.cs @@ -1,85 +1,85 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. - +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + using System.Globalization; using DevHome.Logging; -using DevHome.Logging.Listeners; - -namespace GitHubExtension.Test; - -public class TestListener : ListenerBase -{ - private TestContext? TestContext - { - get; - set; - } - - public Dictionary EventCounts { get; } = new Dictionary(); - - public TestListener(string name, TestContext testContext) - : base(name) - { - TestContext = testContext; - EventCounts.Add(SeverityLevel.Critical, 0); - EventCounts.Add(SeverityLevel.Error, 0); - EventCounts.Add(SeverityLevel.Warn, 0); - EventCounts.Add(SeverityLevel.Info, 0); - EventCounts.Add(SeverityLevel.Debug, 0); - } - - public void Reset() - { - foreach (var kvp in EventCounts) - { - EventCounts[kvp.Key] = 0; - } - } - - public bool FoundErrors() - { - return EventCounts[SeverityLevel.Critical] > 0 || EventCounts[SeverityLevel.Error] > 0; - } - - public override void HandleLogEvent(LogEvent evt) - { - switch (evt.Severity) - { - case SeverityLevel.Critical: - ++EventCounts[SeverityLevel.Critical]; - PrintEvent(evt); - break; - case SeverityLevel.Error: - ++EventCounts[SeverityLevel.Error]; - PrintEvent(evt); - break; - case SeverityLevel.Warn: - ++EventCounts[SeverityLevel.Warn]; - PrintEvent(evt); - break; - case SeverityLevel.Info: - ++EventCounts[SeverityLevel.Info]; - PrintEvent(evt); - break; - case SeverityLevel.Debug: - ++EventCounts[SeverityLevel.Debug]; - - PrintEvent(evt); - break; - } - } - - private void PrintEvent(LogEvent evt) - { - TestContext?.WriteLine($"[{evt.Source}] {evt.Severity.ToString().ToUpper(CultureInfo.InvariantCulture)}: {evt.Message}"); - if (evt.Exception != null) - { - TestContext?.WriteLine(evt.Exception.ToString()); - } - } - - public void PrintEventCounts() - { - TestContext?.WriteLine($"Critical: {EventCounts[SeverityLevel.Critical]} Error: {EventCounts[SeverityLevel.Error]} Warning: {EventCounts[SeverityLevel.Warn]}"); - } -} +using DevHome.Logging.Listeners; + +namespace GitHubExtension.Test; + +public class TestListener : ListenerBase +{ + private TestContext? TestContext + { + get; + set; + } + + public Dictionary EventCounts { get; } = new Dictionary(); + + public TestListener(string name, TestContext testContext) + : base(name) + { + TestContext = testContext; + EventCounts.Add(SeverityLevel.Critical, 0); + EventCounts.Add(SeverityLevel.Error, 0); + EventCounts.Add(SeverityLevel.Warn, 0); + EventCounts.Add(SeverityLevel.Info, 0); + EventCounts.Add(SeverityLevel.Debug, 0); + } + + public void Reset() + { + foreach (var kvp in EventCounts) + { + EventCounts[kvp.Key] = 0; + } + } + + public bool FoundErrors() + { + return EventCounts[SeverityLevel.Critical] > 0 || EventCounts[SeverityLevel.Error] > 0; + } + + public override void HandleLogEvent(LogEvent evt) + { + switch (evt.Severity) + { + case SeverityLevel.Critical: + ++EventCounts[SeverityLevel.Critical]; + PrintEvent(evt); + break; + case SeverityLevel.Error: + ++EventCounts[SeverityLevel.Error]; + PrintEvent(evt); + break; + case SeverityLevel.Warn: + ++EventCounts[SeverityLevel.Warn]; + PrintEvent(evt); + break; + case SeverityLevel.Info: + ++EventCounts[SeverityLevel.Info]; + PrintEvent(evt); + break; + case SeverityLevel.Debug: + ++EventCounts[SeverityLevel.Debug]; + + PrintEvent(evt); + break; + } + } + + private void PrintEvent(LogEvent evt) + { + TestContext?.WriteLine($"[{evt.Source}] {evt.Severity.ToString().ToUpper(CultureInfo.InvariantCulture)}: {evt.Message}"); + if (evt.Exception != null) + { + TestContext?.WriteLine(evt.Exception.ToString()); + } + } + + public void PrintEventCounts() + { + TestContext?.WriteLine($"Critical: {EventCounts[SeverityLevel.Critical]} Error: {EventCounts[SeverityLevel.Error]} Warning: {EventCounts[SeverityLevel.Warn]}"); + } +} diff --git a/test/GitHubExtension/Usings.cs b/test/GitHubExtension/Usings.cs index 77a0d4c..b5ac66b 100644 --- a/test/GitHubExtension/Usings.cs +++ b/test/GitHubExtension/Usings.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. global using Microsoft.VisualStudio.TestTools.UnitTesting; global using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer; diff --git a/test/GitHubExtension/Widgets/Icons.cs b/test/GitHubExtension/Widgets/Icons.cs index bf69ce7..bc745f1 100644 --- a/test/GitHubExtension/Widgets/Icons.cs +++ b/test/GitHubExtension/Widgets/Icons.cs @@ -1,8 +1,10 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + using DevHome.Logging; namespace GitHubExtension.Test; + public partial class WidgetTests { [TestMethod] diff --git a/test/GitHubExtension/Widgets/Validation.cs b/test/GitHubExtension/Widgets/Validation.cs index cc0c152..4f8cc0d 100644 --- a/test/GitHubExtension/Widgets/Validation.cs +++ b/test/GitHubExtension/Widgets/Validation.cs @@ -1,8 +1,10 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + using DevHome.Logging; namespace GitHubExtension.Test; + public partial class WidgetTests { [TestMethod] diff --git a/test/GitHubExtension/Widgets/WidgetTestsSetup.cs b/test/GitHubExtension/Widgets/WidgetTestsSetup.cs index a515381..a6eb4c8 100644 --- a/test/GitHubExtension/Widgets/WidgetTestsSetup.cs +++ b/test/GitHubExtension/Widgets/WidgetTestsSetup.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. namespace GitHubExtension.Test; diff --git a/test/UITest/GitHubExtensionScenarioStandard.cs b/test/UITest/GitHubExtensionScenarioStandard.cs index e45e70f..3f26704 100644 --- a/test/UITest/GitHubExtensionScenarioStandard.cs +++ b/test/UITest/GitHubExtensionScenarioStandard.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Microsoft.VisualStudio.TestTools.UnitTesting; diff --git a/test/UITest/GitHubExtensionSession.cs b/test/UITest/GitHubExtensionSession.cs index 6205732..c3f8334 100644 --- a/test/UITest/GitHubExtensionSession.cs +++ b/test/UITest/GitHubExtensionSession.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors -// Licensed under the MIT license. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. using Microsoft.VisualStudio.TestTools.UnitTesting; using OpenQA.Selenium.Appium;