From 774e1aaeb039b4aee23bf9f287d9f57c05873d1e Mon Sep 17 00:00:00 2001 From: Alexandre Zollinger Chohfi Date: Tue, 12 Nov 2024 17:01:27 -0800 Subject: [PATCH] Updated to .Net 9. --- .editorconfig | 13 ++- .github/workflows/build.yml | 18 ++-- .pipelines/build.yml | 6 +- .pipelines/code-inspector.yaml | 2 +- .pipelines/release.yml | 16 +-- .pipelines/templates/build-nuget.yaml | 10 +- .pipelines/templates/pack-nuget.yaml | 2 +- Directory.Build.props | 3 - MSStore.API/MSStore.API.csproj | 11 +- MSStore.API/MSStoreHttpException.cs | 9 +- MSStore.API/MSStoreWrappedErrorException.cs | 4 +- MSStore.API/Models/ResponseWrapper.cs | 13 +-- MSStore.API/Models/ResponseWrapper{T}.cs | 20 ++++ .../Models/DevCenterSubmissionExtensions.cs | 2 +- MSStore.API/Packaged/StorePackagedAPI.cs | 30 +++++- MSStore.API/StoreAPI.cs | 11 ++ MSStore.API/SubmissionClient.cs | 45 ++++---- MSStore.CLI.UnitTests/AppsCommandUnitTests.cs | 20 ++-- MSStore.CLI.UnitTests/BaseCommandLineTest.cs | 81 ++++++-------- .../CredentialManagerWindowsTests.cs | 7 +- .../EmptyCommandUnitTests.cs | 8 +- .../FlightsCommandUnitTests.cs | 20 ++-- .../FlightsSubmissionCommandUnitTests.cs | 35 +++--- ...ightsSubmissionRolloutCommandsUnitTests.cs | 25 ++--- MSStore.CLI.UnitTests/GraphClientTests.cs | 2 +- MSStore.CLI.UnitTests/InitCommandUnitTests.cs | 10 +- .../MSStore.CLI.UnitTests.csproj | 20 ++-- .../PackageCommandUnitTests.cs | 69 +++++------- .../ProjectConfiguratorTests.cs | 102 ++++++++---------- .../PublishCommandUnitTests.cs | 50 ++++----- .../ReconfigureCommandUnitTests.cs | 30 +++--- ...SetPublisherDisplayNameCommandUnitTests.cs | 10 +- .../SettingsCommandUnitTests.cs | 15 ++- .../SubmissionCommandPackagedUnitTests.cs | 45 ++++---- .../SubmissionCommandUnpackagedUnitTests.cs | 58 +++++----- MSStore.CLI.UnitTests/TelemetryUnitTests.cs | 4 +- .../MauiProject/MauiApp.csproj.template | 4 +- MSStore.CLI/Commands/Apps/GetCommand.cs | 15 +-- MSStore.CLI/Commands/Apps/ListCommand.cs | 15 +-- MSStore.CLI/Commands/Flights/CreateCommand.cs | 23 ++-- MSStore.CLI/Commands/Flights/DeleteCommand.cs | 15 +-- MSStore.CLI/Commands/Flights/GetCommand.cs | 15 +-- MSStore.CLI/Commands/Flights/ListCommand.cs | 17 +-- .../Flights/Submission/DeleteCommand.cs | 21 ++-- .../Commands/Flights/Submission/GetCommand.cs | 15 +-- .../Flights/Submission/PollCommand.cs | 18 +--- .../Flights/Submission/PublishCommand.cs | 15 +-- .../Submission/Rollout/FinalizeCommand.cs | 15 +-- .../Flights/Submission/Rollout/GetCommand.cs | 15 +-- .../Flights/Submission/Rollout/HaltCommand.cs | 15 +-- .../Submission/Rollout/UpdateCommand.cs | 15 +-- .../Flights/Submission/StatusCommand.cs | 15 +-- .../Flights/Submission/UpdateCommand.cs | 15 +-- MSStore.CLI/Commands/InfoCommand.cs | 21 ++-- MSStore.CLI/Commands/InitCommand.cs | 92 +++++++--------- MSStore.CLI/Commands/PackageCommand.cs | 31 ++---- MSStore.CLI/Commands/PublishCommand.cs | 48 ++++----- MSStore.CLI/Commands/ReconfigureCommand.cs | 28 ++--- .../SetPublisherDisplayNameCommand.cs | 16 +-- MSStore.CLI/Commands/SettingsCommand.cs | 18 +--- .../Commands/Submission/DeleteCommand.cs | 21 ++-- MSStore.CLI/Commands/Submission/GetCommand.cs | 17 +-- .../Submission/GetListingAssetsCommand.cs | 15 +-- .../Commands/Submission/PollCommand.cs | 18 +--- .../Commands/Submission/PublishCommand.cs | 15 +-- .../Submission/Rollout/FinalizeCommand.cs | 15 +-- .../Commands/Submission/Rollout/GetCommand.cs | 17 +-- .../Submission/Rollout/HaltCommand.cs | 15 +-- .../Submission/Rollout/UpdateCommand.cs | 15 +-- .../Commands/Submission/StatusCommand.cs | 15 +-- .../Commands/Submission/UpdateCommand.cs | 15 +-- .../Submission/UpdateMetadataCommand.cs | 15 +-- MSStore.CLI/Commands/SubmissionCommand.cs | 4 +- .../Helpers/CustomSpectreConsoleFormatter.cs | 16 +-- .../Helpers/CustomSpectreConsoleLogger.cs | 16 +-- .../Helpers/IStorePackagedAPIExtensions.cs | 10 +- MSStore.CLI/Helpers/NativeMethods.cs | 4 +- MSStore.CLI/Helpers/ProjectImagesHelper.cs | 6 +- MSStore.CLI/MSStore.CLI.csproj | 42 ++++---- MSStore.CLI/MicrosoftStoreCLI.cs | 17 +-- MSStore.CLI/Program.cs | 6 +- .../ElectronProjectConfigurator.cs | 35 +++--- .../FileProjectConfigurator.cs | 27 ++--- .../FlutterProjectConfigurator.cs | 35 +++--- .../MSIXProjectPublisher.cs | 44 +++----- .../MauiProjectConfigurator.cs | 30 ++---- .../NodeBaseProjectConfigurator.cs | 20 ++-- .../PWAProjectConfigurator.cs | 80 ++++++-------- .../ProjectConfiguratorFactory.cs | 9 +- .../ReactNativeProjectConfigurator.cs | 20 ++-- .../ProjectConfigurators/SubmissionImage.cs | 12 +-- .../UWPProjectConfigurator.cs | 32 +++--- .../WinUIProjectConfigurator.cs | 15 +-- .../PublishProfiles/linux-arm64.pubxml | 4 +- .../PublishProfiles/linux-x64.pubxml | 4 +- .../PublishProfiles/osx-arm64.pubxml | 4 +- .../Properties/PublishProfiles/osx-x64.pubxml | 4 +- .../PublishProfiles/win-arm64.pubxml | 4 +- .../Properties/PublishProfiles/win-x64.pubxml | 4 +- MSStore.CLI/Services/AppXManifestManager.cs | 2 +- MSStore.CLI/Services/AzureBlobManager.cs | 20 +--- MSStore.CLI/Services/BrowserLauncher.cs | 19 +--- MSStore.CLI/Services/CLIConfigurator.cs | 54 ++++------ MSStore.CLI/Services/ConfigurationManager.cs | 15 +-- .../Unix/CredentialManagerUnix.cs | 6 +- .../CredentialManager/Unix/NativeMethods.cs | 35 ++---- .../Services/ExternalCommandExecutor.cs | 11 +- MSStore.CLI/Services/FileDownloader.cs | 9 +- MSStore.CLI/Services/Graph/GraphClient.cs | 14 +-- MSStore.CLI/Services/ImageConverter.cs | 9 +- MSStore.CLI/Services/NuGetPackageManager.cs | 9 +- .../Services/PWABuilder/IconExtensions.cs | 2 +- .../Services/PWABuilder/PWABuilderClient.cs | 9 +- .../PartnerCenter/PartnerCenterManager.cs | 14 +-- MSStore.CLI/Services/StoreAPIFactory.cs | 20 ++-- .../Services/TokenManager/MSALTokenManager.cs | 13 +-- MSStore.CLI/StatusContextExtensions.cs | 2 +- 117 files changed, 881 insertions(+), 1422 deletions(-) create mode 100644 MSStore.API/Models/ResponseWrapper{T}.cs diff --git a/.editorconfig b/.editorconfig index ba40f0c..b0c6cc9 100644 --- a/.editorconfig +++ b/.editorconfig @@ -418,7 +418,7 @@ dotnet_diagnostic.IDE0046.severity = suggestion dotnet_diagnostic.IDE0052.severity = warning # IDE0058: Expression value is never used -dotnet_diagnostic.IDE0058.severity = suggestion +dotnet_diagnostic.IDE0058.severity = none # IDE0060: Remove unused parameter dotnet_diagnostic.IDE0060.severity = warning @@ -434,4 +434,13 @@ dotnet_diagnostic.IDE0005.severity = warning # IDE0073: File header dotnet_diagnostic.IDE0073.severity = warning -file_header_template = Copyright (c) Microsoft Corporation. All rights reserved.\nLicensed under the MIT License. \ No newline at end of file +file_header_template = Copyright (c) Microsoft Corporation. All rights reserved.\nLicensed under the MIT License. + +# IDE1006: Naming Styles +dotnet_diagnostic.IDE1006.severity = suggestion + +# SA1513: Closing brace should be followed by blank line +dotnet_diagnostic.SA1513.severity = none + +# SA1010: Opening square brackets should be spaced correctly +dotnet_diagnostic.SA1010.severity = none diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d175a21..865ad3b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,7 +26,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: 8.0.x + dotnet-version: 9.0.x - name: Install and Configure Keyring if: ${{ matrix.os == 'ubuntu-latest' }} run: | @@ -42,11 +42,11 @@ jobs: run: dotnet restore MSStore.CLI.sln /p:Configuration=Release - name: Build run: dotnet build MSStore.CLI.sln --no-restore /p:Configuration=Release - - name: Test net8.0 - run: dotnet run --project MSStore.CLI.UnitTests -f net8.0 --no-build -c Release --coverage --coverage-output-format cobertura --report-trx --results-directory ./TestResults - - name: Test net8.0-windows10.0.17763.0 + - name: Test net9.0 + run: dotnet run --project MSStore.CLI.UnitTests -f net9.0 --no-build -c Release --coverage --coverage-output-format cobertura --report-trx --results-directory ./TestResults + - name: Test net9.0-windows10.0.17763.0 if: ${{ matrix.os == 'windows-latest' }} - run: dotnet run --project MSStore.CLI.UnitTests -f net8.0-windows10.0.17763.0 --no-build -c Release --coverage --coverage-output-format cobertura --report-trx --results-directory ./TestResults + run: dotnet run --project MSStore.CLI.UnitTests -f net9.0-windows10.0.17763.0 --no-build -c Release --coverage --coverage-output-format cobertura --report-trx --results-directory ./TestResults - name: Publish test results if: ${{ !cancelled() }} uses: actions/upload-artifact@v4 @@ -83,13 +83,13 @@ jobs: include: - os: windows-latest dotnet-os: win - dotnet-framework: net8.0-windows10.0.17763.0 + dotnet-framework: net9.0-windows10.0.17763.0 - os: ubuntu-latest dotnet-os: linux - dotnet-framework: net8.0 + dotnet-framework: net9.0 - os: macos-latest dotnet-os: osx - dotnet-framework: net8.0 + dotnet-framework: net9.0 runs-on: ${{ matrix.os }} name: Build CLI - ${{ matrix.dotnet-os }}-${{ matrix.dotnet-arch }} @@ -101,7 +101,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: 8.0.x + dotnet-version: 9.0.x - name: Add msbuild to PATH if: ${{ matrix.os == 'windows-latest' }} uses: microsoft/setup-msbuild@v2 diff --git a/.pipelines/build.yml b/.pipelines/build.yml index 1ce281a..ff72e14 100644 --- a/.pipelines/build.yml +++ b/.pipelines/build.yml @@ -49,7 +49,7 @@ extends: credscan: suppressionsFile: '$(System.DefaultWorkingDirectory)/.pipelines/CredScanSuppressions.json' binSkim: - AnalyzeTargetGlob: '$(System.DefaultWorkingDirectory)\MSStore.API\bin\**\net8.0\MSStore.API.dll' + AnalyzeTargetGlob: '$(System.DefaultWorkingDirectory)\MSStore.API\bin\**\net9.0\MSStore.API.dll' stages: - stage: Build_And_Run_CodeQL jobs: @@ -63,9 +63,9 @@ extends: steps: - checkout: self - task: UseDotNet@2 - displayName: Setup .NET 8 + displayName: Setup .NET 9 inputs: - version: 8.0.x + version: 9.0.x - script: mv -f $(Build.SourcesDirectory)/.pipelines/release-nuget.config ./nuget.config displayName: Add release package source - task: NuGetAuthenticate@1 diff --git a/.pipelines/code-inspector.yaml b/.pipelines/code-inspector.yaml index 3ed2f94..fd07ede 100644 --- a/.pipelines/code-inspector.yaml +++ b/.pipelines/code-inspector.yaml @@ -35,7 +35,7 @@ extends: credscan: suppressionsFile: '$(System.DefaultWorkingDirectory)/.pipelines/CredScanSuppressions.json' binSkim: - AnalyzeTargetGlob: '$(System.DefaultWorkingDirectory)\MSStore.API\bin\**\net8.0\MSStore.API.dll' + AnalyzeTargetGlob: '$(System.DefaultWorkingDirectory)\MSStore.API\bin\**\net9.0\MSStore.API.dll' stages: - stage: codeInspector displayName: Code Inspector diff --git a/.pipelines/release.yml b/.pipelines/release.yml index f6de7f1..7b3fd36 100644 --- a/.pipelines/release.yml +++ b/.pipelines/release.yml @@ -40,17 +40,17 @@ parameters: image: windows-latest os: windows dotnet_runtime: win - dotnet_framework: net8.0-windows10.0.17763.0 + dotnet_framework: net9.0-windows10.0.17763.0 - name: Azure-Pipelines-1ESPT-ExDShared image: ubuntu-latest os: linux dotnet_runtime: linux - dotnet_framework: net8.0 + dotnet_framework: net9.0 - name: Azure Pipelines image: macos-latest os: macOS dotnet_runtime: osx - dotnet_framework: net8.0 + dotnet_framework: net9.0 name: 0.0.$(Date:yyMM).$(Date:dd)$(Rev:rr) @@ -69,7 +69,7 @@ extends: credscan: suppressionsFile: '$(System.DefaultWorkingDirectory)/.pipelines/CredScanSuppressions.json' binSkim: - AnalyzeTargetGlob: '$(System.DefaultWorkingDirectory)\MSStore.API\bin\**\net8.0\MSStore.API.dll' + AnalyzeTargetGlob: '$(System.DefaultWorkingDirectory)\MSStore.API\bin\**\net9.0\MSStore.API.dll' stages: - stage: NuGet jobs: @@ -84,9 +84,9 @@ extends: steps: - checkout: self - task: UseDotNet@2 - displayName: Setup .NET 8 + displayName: Setup .NET 9 inputs: - version: 8.0.x + version: 9.0.x - ${{ if eq(parameters.DoEsrp, 'true') }}: - task: UseDotNet@2 displayName: Setup .NET 6.0 (For ESRP Task) @@ -128,9 +128,9 @@ extends: - checkout: self persistCredentials: true - task: UseDotNet@2 - displayName: Setup .NET 8 + displayName: Setup .NET 9 inputs: - version: 8.0.x + version: 9.0.x - ${{ if eq(parameters.DoEsrp, 'true') }}: - task: UseDotNet@2 displayName: Setup .NET 6.0 (For ESRP Task) diff --git a/.pipelines/templates/build-nuget.yaml b/.pipelines/templates/build-nuget.yaml index 8596387..dc5ae90 100644 --- a/.pipelines/templates/build-nuget.yaml +++ b/.pipelines/templates/build-nuget.yaml @@ -41,22 +41,22 @@ steps: - script: dotnet build MSStore.CLI.sln --no-restore /p:Configuration=${{ parameters.dotnet_configuration }} displayName: Build - task: DotNetCoreCLI@2 - displayName: 'Tests net8.0' + displayName: 'Tests net9.0' env: DISPLAY: :0.0 inputs: command: 'run' projects: '**/*[Tt]est*/*.csproj' - arguments: '-f net8.0 --no-build -c ${{ parameters.dotnet_configuration }} --coverage --coverage-output-format cobertura --report-trx' + arguments: '-f net9.0 --no-build -c ${{ parameters.dotnet_configuration }} --coverage --coverage-output-format cobertura --report-trx' - task: DotNetCoreCLI@2 - displayName: 'Tests net8.0-windows10.0.17763.0' + displayName: 'Tests net9.0-windows10.0.17763.0' condition: startsWith(variables.AgentOS, 'Windows_NT') env: DISPLAY: :0.0 inputs: command: 'run' projects: '**/*[Tt]est*/*.csproj' - arguments: '-f net8.0-windows10.0.17763.0 --no-build -c ${{ parameters.dotnet_configuration }} --coverage --coverage-output-format cobertura --report-trx' + arguments: '-f net9.0-windows10.0.17763.0 --no-build -c ${{ parameters.dotnet_configuration }} --coverage --coverage-output-format cobertura --report-trx' - task: PublishTestResults@2 inputs: testResultsFormat: 'VSTest' @@ -85,7 +85,7 @@ steps: AuthAKVName: ${{ parameters.signingIdentity.akvName }} AuthCertName: ${{ parameters.signingIdentity.authCertName }} AuthSignCertName: ${{ parameters.signingIdentity.signCertName }} - FolderPath: '$(System.DefaultWorkingDirectory)/MSStore.API/bin/${{ parameters.dotnet_configuration }}/net8.0' + FolderPath: '$(System.DefaultWorkingDirectory)/MSStore.API/bin/${{ parameters.dotnet_configuration }}/net9.0' Pattern: 'MSStore.API.dll' signConfigType: inlineSignParams inlineOperation: | diff --git a/.pipelines/templates/pack-nuget.yaml b/.pipelines/templates/pack-nuget.yaml index e3d09e4..28bee82 100644 --- a/.pipelines/templates/pack-nuget.yaml +++ b/.pipelines/templates/pack-nuget.yaml @@ -58,7 +58,7 @@ steps: displayName: 'Copy Artifacts - NuGet DLLs' condition: startsWith(variables.AgentOS, 'Linux') inputs: - contents: '$(System.DefaultWorkingDirectory)/MSStore.API/bin/${{ parameters.dotnet_configuration }}/net8.0/*' + contents: '$(System.DefaultWorkingDirectory)/MSStore.API/bin/${{ parameters.dotnet_configuration }}/net9.0/*' flattenFolders: true targetFolder: '$(Build.ArtifactStagingDirectory)/NuGetDLLs' - task: 1ES.PublishPipelineArtifact@1 diff --git a/Directory.Build.props b/Directory.Build.props index fd208ea..9e56bbe 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -22,9 +22,6 @@ $(MSBuildThisFileDirectory)\.runsettings enable true - $(NoWarn);SA0001 - - $(NoWarn);IL2077;IL2080;IL2075 diff --git a/MSStore.API/MSStore.API.csproj b/MSStore.API/MSStore.API.csproj index 713258d..dbd54f4 100644 --- a/MSStore.API/MSStore.API.csproj +++ b/MSStore.API/MSStore.API.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 $(NoWarn);CS1591 MIT @@ -11,8 +11,7 @@ Microsoft Store;MSStoreAPI;MSStore;API true $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb - - true + true @@ -22,9 +21,9 @@ - - - + + + diff --git a/MSStore.API/MSStoreHttpException.cs b/MSStore.API/MSStoreHttpException.cs index 97e90ee..98cb75b 100644 --- a/MSStore.API/MSStoreHttpException.cs +++ b/MSStore.API/MSStoreHttpException.cs @@ -5,13 +5,8 @@ namespace MSStore.API { - public class MSStoreHttpException : MSStoreException + public class MSStoreHttpException(HttpResponseMessage response) : MSStoreException { - public HttpResponseMessage Response { get; private set; } - - public MSStoreHttpException(HttpResponseMessage response) - { - Response = response; - } + public HttpResponseMessage Response { get; private set; } = response; } } diff --git a/MSStore.API/MSStoreWrappedErrorException.cs b/MSStore.API/MSStoreWrappedErrorException.cs index d5bb2b5..024a85f 100644 --- a/MSStore.API/MSStoreWrappedErrorException.cs +++ b/MSStore.API/MSStoreWrappedErrorException.cs @@ -14,13 +14,13 @@ public class MSStoreWrappedErrorException : MSStoreException public MSStoreWrappedErrorException(string? message, List? responseErrors) : base(message) { - ResponseErrors = responseErrors ?? new List(); + ResponseErrors = responseErrors ?? []; } public MSStoreWrappedErrorException(string? message, List? responseErrors, Exception? innerException) : base(message, innerException) { - ResponseErrors = responseErrors ?? new List(); + ResponseErrors = responseErrors ?? []; } } } diff --git a/MSStore.API/Models/ResponseWrapper.cs b/MSStore.API/Models/ResponseWrapper.cs index 41d6f70..4aa541e 100644 --- a/MSStore.API/Models/ResponseWrapper.cs +++ b/MSStore.API/Models/ResponseWrapper.cs @@ -5,20 +5,9 @@ namespace MSStore.API.Models { - public class ResponseWrapper + public class ResponseWrapper { - public T? ResponseData { get; set; } public bool IsSuccess { get; set; } public List? Errors { get; set; } - - public static implicit operator ResponseWrapper(ResponseWrapper v) - { - return new() - { - Errors = v.Errors, - IsSuccess = v.IsSuccess, - ResponseData = v.ResponseData - }; - } } } diff --git a/MSStore.API/Models/ResponseWrapper{T}.cs b/MSStore.API/Models/ResponseWrapper{T}.cs new file mode 100644 index 0000000..3f6e90a --- /dev/null +++ b/MSStore.API/Models/ResponseWrapper{T}.cs @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace MSStore.API.Models +{ + public class ResponseWrapper : ResponseWrapper + { + public T? ResponseData { get; set; } + + public static implicit operator ResponseWrapper(ResponseWrapper v) + { + return new() + { + Errors = v.Errors, + IsSuccess = v.IsSuccess, + ResponseData = v.ResponseData + }; + } + } +} diff --git a/MSStore.API/Packaged/Models/DevCenterSubmissionExtensions.cs b/MSStore.API/Packaged/Models/DevCenterSubmissionExtensions.cs index b243a28..af83fa0 100644 --- a/MSStore.API/Packaged/Models/DevCenterSubmissionExtensions.cs +++ b/MSStore.API/Packaged/Models/DevCenterSubmissionExtensions.cs @@ -12,7 +12,7 @@ public static List FilterUnsupported(this List(); + return []; } return applicationPackages.Where(p => diff --git a/MSStore.API/Packaged/StorePackagedAPI.cs b/MSStore.API/Packaged/StorePackagedAPI.cs index 521946e..fb1f290 100644 --- a/MSStore.API/Packaged/StorePackagedAPI.cs +++ b/MSStore.API/Packaged/StorePackagedAPI.cs @@ -186,7 +186,7 @@ public async Task> GetApplicationsAsync(CancellationT try { var devCenterApplicationsResponse = await GetDevCenterApplicationsAsync(0, 100, ct); // TODO: pagination - return devCenterApplicationsResponse.Value ?? new(); + return devCenterApplicationsResponse.Value ?? []; } catch (Exception error) { @@ -216,6 +216,7 @@ private async Task> GetDevCenterApplications skip, top), null, + SourceGenerationContext.GetCustom().PagedResponseDevCenterApplication, ct); } @@ -232,6 +233,7 @@ private async Task> GetDevCenterApplications productId, submissionId), null, + SourceGenerationContext.GetCustom().String, ct); if (string.IsNullOrEmpty(ret)) @@ -239,7 +241,7 @@ private async Task> GetDevCenterApplications return null; } - return JsonSerializer.Deserialize(ret, typeof(DevCenterError), SourceGenerationContext.GetCustom()) as DevCenterError; + return JsonSerializer.Deserialize(ret, SourceGenerationContext.GetCustom().DevCenterError); } public async Task GetApplicationAsync(string productId, CancellationToken ct = default) @@ -254,6 +256,7 @@ public async Task GetApplicationAsync(string productId, Ca DevCenterVersion, productId), null, + SourceGenerationContext.GetCustom().DevCenterApplication, ct); } @@ -269,6 +272,7 @@ public async Task CreateSubmissionAsync(string productId, C DevCenterVersion, productId), null, + SourceGenerationContext.GetCustom().DevCenterSubmission, ct); } @@ -285,6 +289,7 @@ public async Task GetSubmissionAsync(string productId, stri productId, submissionId), null, + SourceGenerationContext.GetCustom().DevCenterSubmission, ct); } @@ -301,6 +306,7 @@ public async Task UpdateSubmissionAsync(string productId, s productId, submissionId), updatedSubmission, + SourceGenerationContext.GetCustom().DevCenterSubmission, ct); } @@ -317,9 +323,10 @@ public async Task UpdateSubmissionAsync(string productId, s productId, submissionId), null, + SourceGenerationContext.GetCustom().String, ct); - return JsonSerializer.Deserialize(ret, typeof(DevCenterCommitResponse), SourceGenerationContext.GetCustom()) as DevCenterCommitResponse; + return JsonSerializer.Deserialize(ret, SourceGenerationContext.GetCustom().DevCenterCommitResponse); } public async Task GetSubmissionStatusAsync(string productId, string submissionId, CancellationToken ct = default) @@ -335,6 +342,7 @@ public async Task GetSubmissionStatusAsync(st productId, submissionId), null, + SourceGenerationContext.GetCustom().DevCenterSubmissionStatusResponse, ct); } @@ -343,7 +351,7 @@ public async Task> GetFlightsAsync(string productId, Cance try { var devCenterFlightsResponse = await GetFlightsAsync(productId, 0, 100, ct); // TODO: pagination - return devCenterFlightsResponse.Value ?? new(); + return devCenterFlightsResponse.Value ?? []; } catch (Exception error) { @@ -365,6 +373,7 @@ private async Task> GetFlightsAsync(string produc skip, top), null, + SourceGenerationContext.GetCustom().PagedResponseDevCenterFlight, ct); } @@ -381,6 +390,7 @@ public async Task GetFlightAsync(string productId, string fligh productId, flightId), null, + SourceGenerationContext.GetCustom().DevCenterFlight, ct); } @@ -397,6 +407,7 @@ public async Task GetFlightAsync(string productId, string fligh productId, flightId), null, + SourceGenerationContext.GetCustom().String, ct); if (string.IsNullOrEmpty(ret)) @@ -426,6 +437,7 @@ public async Task CreateFlightAsync(string productId, string fr DevCenterVersion, productId), flight, + SourceGenerationContext.GetCustom().DevCenterFlight, ct); } @@ -443,6 +455,7 @@ public async Task GetFlightSubmissionAsync(string pro flightId, submissionId), null, + SourceGenerationContext.GetCustom().DevCenterFlightSubmission, ct); } @@ -460,6 +473,7 @@ public async Task GetFlightSubmissionAsync(string pro flightId, submissionId), null, + SourceGenerationContext.GetCustom().String, ct); if (string.IsNullOrEmpty(ret)) @@ -483,6 +497,7 @@ public async Task CreateFlightSubmissionAsync(string productId, flightId), null, + SourceGenerationContext.GetCustom().DevCenterFlightSubmission, ct); } @@ -500,6 +515,7 @@ public async Task UpdateFlightSubmissionAsync(string flightId, submissionId), updatedFlightSubmission, + SourceGenerationContext.GetCustom().DevCenterFlightSubmission, ct); } @@ -517,6 +533,7 @@ public async Task UpdateFlightSubmissionAsync(string flightId, submissionId), null, + SourceGenerationContext.GetCustom().String, ct); return JsonSerializer.Deserialize(ret, typeof(DevCenterCommitResponse), SourceGenerationContext.GetCustom()) as DevCenterCommitResponse; @@ -536,6 +553,7 @@ public async Task GetFlightSubmissionStatusAs flightId, submissionId), null, + SourceGenerationContext.GetCustom().DevCenterSubmissionStatusResponse, ct); } @@ -553,6 +571,7 @@ public async Task GetPackageRolloutAsync(string productId, strin flightId == null ? string.Empty : $"/flights/{flightId}", submissionId), null, + SourceGenerationContext.GetCustom().PackageRollout, ct); } @@ -571,6 +590,7 @@ public async Task UpdatePackageRolloutPercentageAsync(string pro submissionId, percentage), null, + SourceGenerationContext.GetCustom().PackageRollout, ct); } @@ -588,6 +608,7 @@ public async Task HaltPackageRolloutAsync(string productId, stri flightId == null ? string.Empty : $"/flights/{flightId}", submissionId), null, + SourceGenerationContext.GetCustom().PackageRollout, ct); } @@ -605,6 +626,7 @@ public async Task FinalizePackageRolloutAsync(string productId, flightId == null ? string.Empty : $"/flights/{flightId}", submissionId), null, + SourceGenerationContext.GetCustom().PackageRollout, ct); } } diff --git a/MSStore.API/StoreAPI.cs b/MSStore.API/StoreAPI.cs index 5a6c206..f0e4e80 100644 --- a/MSStore.API/StoreAPI.cs +++ b/MSStore.API/StoreAPI.cs @@ -343,6 +343,7 @@ private async Task> GetDraftSubmissi "properties", languages), null, + SourceGenerationContext.GetCustom().ResponseWrapperPropertiesMetadataResponse, ct); } @@ -360,6 +361,7 @@ private async Task> GetDraftSubmis "availability", languages), null, + SourceGenerationContext.GetCustom().ResponseWrapperAvailabilityMetadataResponse, ct); } @@ -377,6 +379,7 @@ private async Task> GetDraftSubmission "listings", languages), null, + SourceGenerationContext.GetCustom().ResponseWrapperListingsMetadataResponse, ct); } @@ -392,6 +395,7 @@ private async Task> GetDraftSubmission Version, productId), null, + SourceGenerationContext.GetCustom().ResponseWrapperPackagesMetadataResponse, ct); } @@ -407,6 +411,7 @@ private async Task> UpdateDraftSubmissio Version, productId), submissionMetadata, + SourceGenerationContext.GetCustom().ResponseWrapperUpdateMetadataResponse, ct); } @@ -422,6 +427,7 @@ private async Task> UpdateStoreSubmissio Version, productId), submission, + SourceGenerationContext.GetCustom().ResponseWrapperUpdateMetadataResponse, ct); } @@ -437,6 +443,7 @@ private async Task> CommitUpdateStoreSub Version, productId), null, + SourceGenerationContext.GetCustom().ResponseWrapperUpdateMetadataResponse, ct); } @@ -452,6 +459,7 @@ public async Task> GetModuleStatusAsync(string pro Version, productId), null, + SourceGenerationContext.GetCustom().ResponseWrapperModuleStatus, ct); } @@ -468,6 +476,7 @@ public async Task> GetSubmissionStatusPollingA productId, submissionId), null, + SourceGenerationContext.GetCustom().ResponseWrapperSubmissionStatus, ct); } @@ -483,6 +492,7 @@ private async Task> SubmitSubmissionAs Version, productId), null, + SourceGenerationContext.GetCustom().ResponseWrapperCreateSubmissionResponse, ct); } @@ -499,6 +509,7 @@ private async Task> InternalGetDraftListi productId, languages), null, + SourceGenerationContext.GetCustom().ResponseWrapperListingAssetsResponse, ct); } diff --git a/MSStore.API/SubmissionClient.cs b/MSStore.API/SubmissionClient.cs index d959285..87f6013 100644 --- a/MSStore.API/SubmissionClient.cs +++ b/MSStore.API/SubmissionClient.cs @@ -9,6 +9,7 @@ using System.Security.Cryptography.X509Certificates; using System.Text; using System.Text.Json; +using System.Text.Json.Serialization.Metadata; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Logging; @@ -41,8 +42,8 @@ public class SubmissionClient : IDisposable private static readonly string LinuxKeyRingSchema = "com.microsoft.store.tokencache"; private static readonly string LinuxKeyRingCollection = MsalCacheHelper.LinuxKeyRingDefaultCollection; private static readonly string LinuxKeyRingLabel = "MSAL token cache for all Microsoft Store Apps."; - private static readonly KeyValuePair LinuxKeyRingAttr1 = new KeyValuePair("Version", "1"); - private static readonly KeyValuePair LinuxKeyRingAttr2 = new KeyValuePair("ProductGroup", "msstore-api"); + private static readonly KeyValuePair LinuxKeyRingAttr1 = new("Version", "1"); + private static readonly KeyValuePair LinuxKeyRingAttr2 = new("ProductGroup", "msstore-api"); /// /// Initializes a new instance of the class. @@ -83,7 +84,7 @@ public SubmissionClient(AuthenticationResult accessToken, string serviceUrl, Htt this.httpClient.BaseAddress = new Uri(serviceUrl); - DefaultHeaders = new Dictionary(); + DefaultHeaders = []; } /// @@ -178,7 +179,7 @@ private static async Task GetClientCredentialAccessTokenAs try { - authenticationResult = await app.AcquireTokenForClient(new[] { scope }) + authenticationResult = await app.AcquireTokenForClient([scope]) .WithTenantId(tenantId) .ExecuteAsync(ct); } @@ -227,12 +228,14 @@ private static async Task CreateAppAsync(string /// The HTTP method. /// The relative URL. /// Content of the request. + /// The type information for JSON serialization. /// Cancelation token. /// instance of the type T public async Task InvokeAsync( HttpMethod httpMethod, string relativeUrl, object? requestContent, + JsonTypeInfo jsonTypeInfo, CancellationToken ct = default) where T : class { @@ -247,13 +250,13 @@ public async Task InvokeAsync( return (T)(object)await response.Content.ReadAsStringAsync(ct); } - object? resource = null; + T? resource = null; if (!response.IsSuccessStatusCode) { try { - resource = JsonSerializer.Deserialize(await response.Content.ReadAsStringAsync(ct), typeof(T), SourceGenerationContext.GetCustom()); + resource = await JsonSerializer.DeserializeAsync(await response.Content.ReadAsStreamAsync(ct), jsonTypeInfo, ct); } catch { @@ -263,25 +266,19 @@ public async Task InvokeAsync( { } - if (resource?.GetType()?.IsGenericType == true && - resource?.GetType()?.GetGenericTypeDefinition() == typeof(ResponseWrapper<>)) + if (typeof(T).IsGenericType && + typeof(T).GetGenericTypeDefinition() == typeof(ResponseWrapper<>)) { - var errorsProp = resource.GetType().GetProperty(nameof(ResponseWrapper.Errors)); - var isSuccessProp = resource.GetType().GetProperty(nameof(ResponseWrapper.IsSuccess)); - if (errorsProp != null && isSuccessProp != null) + if (resource is ResponseWrapper responseWrapper && + responseWrapper.Errors?.Count > 0 && + !responseWrapper.IsSuccess) { - var errors = (List?)errorsProp.GetValue(resource); - var isSuccess = (bool?)isSuccessProp.GetValue(resource); - if (errors?.Count > 0 - && isSuccess == false) + if (resource is T t) { - if (resource is T t) - { - return t; - } - - throw new MSStoreWrappedErrorException("REST error", errors); + return t; } + + throw new MSStoreWrappedErrorException("REST error", responseWrapper.Errors); } } @@ -295,10 +292,10 @@ public async Task InvokeAsync( } } - resource = JsonSerializer.Deserialize(await response.Content.ReadAsStringAsync(ct), typeof(T), SourceGenerationContext.GetCustom()); - if (resource is T result) + resource = await JsonSerializer.DeserializeAsync(await response.Content.ReadAsStreamAsync(ct), jsonTypeInfo, ct); + if (resource != null) { - return result; + return resource; } else { diff --git a/MSStore.CLI.UnitTests/AppsCommandUnitTests.cs b/MSStore.CLI.UnitTests/AppsCommandUnitTests.cs index d0a7f21..dcc4d92 100644 --- a/MSStore.CLI.UnitTests/AppsCommandUnitTests.cs +++ b/MSStore.CLI.UnitTests/AppsCommandUnitTests.cs @@ -18,11 +18,10 @@ public void Init() public async Task AppsListCommandShouldReturnZero() { var result = await ParseAndInvokeAsync( - new string[] - { + [ "apps", "list" - }); + ]); result.Should().ContainAll(FakeApps.Select(a => a.Id)); result.Should().ContainAll(FakeApps.Select(a => a.PrimaryName)); @@ -33,12 +32,11 @@ public async Task AppsGetCommandShouldReturnZeroIfExistingApp() { var appId = FakeApps[2].Id!; var result = await ParseAndInvokeAsync( - new string[] - { + [ "apps", "get", appId - }); + ]); result.Should().Contain($"\"Id\": \"{appId}\","); } @@ -47,12 +45,11 @@ public async Task AppsGetCommandShouldReturnZeroIfExistingApp() public async Task AppsGetCommandIsNotSupportedForUnpackagedApps() { var result = await ParseAndInvokeAsync( - new[] - { + [ "apps", "get", Guid.Empty.ToString() - }, -1); + ], -1); result.Should().Contain("This command is not supported for unpackaged applications."); } @@ -61,12 +58,11 @@ public async Task AppsGetCommandIsNotSupportedForUnpackagedApps() public async Task AppsGetCommandShouldReturnErrorIfNonExistingApp() { var result = await ParseAndInvokeAsync( - new string[] - { + [ "apps", "get", "9PN3ABCDEFGD" - }, + ], -1); result.Should().Contain("Error!"); diff --git a/MSStore.CLI.UnitTests/BaseCommandLineTest.cs b/MSStore.CLI.UnitTests/BaseCommandLineTest.cs index 2aa725a..f7c5b5f 100644 --- a/MSStore.CLI.UnitTests/BaseCommandLineTest.cs +++ b/MSStore.CLI.UnitTests/BaseCommandLineTest.cs @@ -51,16 +51,16 @@ public class BaseCommandLineTest internal Mock NuGetPackageManager { get; private set; } = null!; internal Mock ZipFileManager { get; private set; } = null!; internal Mock EnvironmentInformationService { get; private set; } = null!; - internal List UserNames { get; } = new List(); - internal List Secrets { get; } = new List(); + internal List UserNames { get; } = []; + internal List Secrets { get; } = []; internal Mock ExternalCommandExecutor { get; private set; } = null!; internal Mock FakeStoreAPIFactory { get; private set; } = null!; internal Mock FakeStoreAPI { get; private set; } = null!; internal Mock FakeStorePackagedAPI { get; private set; } = null!; - protected List FakeApps { get; } = new List - { + protected List FakeApps { get; } = + [ new DevCenterApplication { Id = "9PN3ABCDEFGA", @@ -76,10 +76,10 @@ public class BaseCommandLineTest Id = "9PN3ABCDEFGC", PrimaryName = "Fake App 3" } - }; + ]; - protected List FakeFlights { get; } = new List - { + protected List FakeFlights { get; } = + [ new DevCenterFlight { FlightId = "632B6A77-0E18-4B41-9033-3614D2174F2C", @@ -90,7 +90,7 @@ public class BaseCommandLineTest FlightId = "632B6A77-0E18-4B41-9033-3614D2174F2D", FriendlyName = "FakeFlight2" } - }; + ]; internal static Organization DefaultOrganization { get; } = new Organization { @@ -140,9 +140,7 @@ public void Initialize() .Setup(x => x.GetEnrollmentAccountsAsync(It.IsAny())) .ReturnsAsync(new AccountEnrollments { - Items = new List - { - } + Items = [] }); PartnerCenterManager .Setup(x => x.Enabled) @@ -205,7 +203,7 @@ public void Initialize() .Setup(fac => fac.CreatePackagedAsync(It.IsAny(), It.IsAny())) .ReturnsAsync(FakeStorePackagedAPI.Object); - Cli = new MicrosoftStoreCLI(); + Cli = []; StorePackagedAPI.DefaultSubmissionPollDelay = TimeSpan.Zero; @@ -419,24 +417,24 @@ protected void AddDefaultFakeSubmission() Id = "123456789", ApplicationCategory = DevCenterApplicationCategory.NotSet, FileUploadUrl = "https://azureblob.com/fileupload", - ApplicationPackages = new List - { + ApplicationPackages = + [ new ApplicationPackage { Id = "123456789", Version = "1.0.0", } - }, + ], StatusDetails = new StatusDetails { - Warnings = new List - { + Warnings = + [ new CodeAndDetail { Code = "Code1", Details = "Detail1" } - } + ] }, Listings = new Dictionary { @@ -470,24 +468,24 @@ protected void AddDefaultFakeFlightSubmission() { Id = "123456789", FileUploadUrl = "https://azureblob.com/fileupload", - FlightPackages = new List - { + FlightPackages = + [ new ApplicationPackage { Id = "123456789", Version = "1.0.0", } - }, + ], StatusDetails = new StatusDetails { - Warnings = new List - { + Warnings = + [ new CodeAndDetail { Code = "Code1", Details = "Detail1" } - } + ] } }; @@ -531,7 +529,7 @@ protected void AddFakeFlights() { FlightId = "632B6A77-0E18-4B41-9033-3614D2174F2E", FriendlyName = "NewFlight", - GroupIds = new List { "1" } + GroupIds = ["1"] }; FakeStorePackagedAPI @@ -796,7 +794,7 @@ protected Task RunTestAsync(Func? testCallback) { _testCallback = testCallback; - return ParseAndInvokeAsync(new[] { "test" }); + return ParseAndInvokeAsync(["test"]); } protected async Task ParseAndInvokeAsync(string[] args, int? expectedResult = 0) @@ -854,7 +852,7 @@ private async Task TestAsync(InvocationContext invocationContext) private sealed class TestCommand : Command { - private BaseCommandLineTest _baseCommandLineTest; + private readonly BaseCommandLineTest _baseCommandLineTest; public TestCommand(BaseCommandLineTest baseCommandLineTest) : base("test") @@ -866,13 +864,13 @@ public TestCommand(BaseCommandLineTest baseCommandLineTest) internal sealed class OutputCapture : TextWriter, IStandardStreamWriter, IDisposable { - private TextWriter stdOutWriter; + private readonly TextWriter _stdOutWriter; public TextWriter Captured { get; private set; } public override Encoding Encoding => Encoding.ASCII; public OutputCapture() { - stdOutWriter = Console.Out; + _stdOutWriter = Console.Out; Console.SetOut(this); Captured = new StringWriter(); } @@ -880,43 +878,32 @@ public OutputCapture() public override void Write(string? value) { Captured.Write(value); - stdOutWriter.Write(value); + _stdOutWriter.Write(value); } public override void WriteLine(string? value) { Captured.WriteLine(value); - stdOutWriter.WriteLine(value); + _stdOutWriter.WriteLine(value); } } - internal sealed class TestConsole : IConsole + internal sealed class TestConsole(BaseCommandLineTest.OutputCapture outputCapture) : IConsole { - public TestConsole(OutputCapture outputCapture) - { - Out = outputCapture; - Error = outputCapture; - } - - public IStandardStreamWriter Error { get; set; } - public IStandardStreamWriter Out { get; set; } + public IStandardStreamWriter Error { get; set; } = outputCapture; + public IStandardStreamWriter Out { get; set; } = outputCapture; public bool IsOutputRedirected { get; set; } public bool IsErrorRedirected { get; set; } public bool IsInputRedirected { get; set; } } - internal sealed class CustomAnsiConsoleOutput : IAnsiConsoleOutput + internal sealed class CustomAnsiConsoleOutput(TextWriter writer) : IAnsiConsoleOutput { - public TextWriter Writer { get; } + public TextWriter Writer { get; } = writer ?? throw new ArgumentNullException(nameof(writer)); public bool IsTerminal => false; public int Width => 260; public int Height => 80; - public CustomAnsiConsoleOutput(TextWriter writer) - { - Writer = writer ?? throw new ArgumentNullException(nameof(writer)); - } - public void SetEncoding(Encoding encoding) { } diff --git a/MSStore.CLI.UnitTests/CredentialManagerWindowsTests.cs b/MSStore.CLI.UnitTests/CredentialManagerWindowsTests.cs index 08a7367..523dc46 100644 --- a/MSStore.CLI.UnitTests/CredentialManagerWindowsTests.cs +++ b/MSStore.CLI.UnitTests/CredentialManagerWindowsTests.cs @@ -15,9 +15,10 @@ public class CredentialManagerWindowsTests [TestInitialize] public void Initialize() { - _credentialManagerWindows = new CredentialManagerWindows(); - - _credentialManagerWindows.ApplicationName = TestApplicationName; + _credentialManagerWindows = new CredentialManagerWindows + { + ApplicationName = TestApplicationName + }; _credentialManagerWindows.ClearCredentials("testUserName"); } diff --git a/MSStore.CLI.UnitTests/EmptyCommandUnitTests.cs b/MSStore.CLI.UnitTests/EmptyCommandUnitTests.cs index a03ecef..5f016a0 100644 --- a/MSStore.CLI.UnitTests/EmptyCommandUnitTests.cs +++ b/MSStore.CLI.UnitTests/EmptyCommandUnitTests.cs @@ -11,7 +11,7 @@ public async Task EmptyCommandShouldReturnZeroIfLoggedIn() { FakeLogin(); - var result = await ParseAndInvokeAsync(Array.Empty()); + var result = await ParseAndInvokeAsync([]); result.Should().Contain("CLI tool to automate Microsoft Store Developer tasks."); } @@ -35,7 +35,7 @@ public async Task EmptyCommandShouldReturnZeroIfNotSignedIn() AddDefaultGraphOrg(); - var result = await ParseAndInvokeAsync(Array.Empty()); + var result = await ParseAndInvokeAsync([]); result.Should().Contain("Awesome! It seems to be working!"); } @@ -45,7 +45,7 @@ public async Task InfoCommandShouldReturnZero() { FakeLogin(); - var result = await ParseAndInvokeAsync(new[] { "info" }); + var result = await ParseAndInvokeAsync(["info"]); result.Should().Contain("Current Config"); } @@ -55,7 +55,7 @@ public async Task InfoCommandShouldReturnZeroWithCert() { FakeLoginWithCert(); - var result = await ParseAndInvokeAsync(new[] { "info" }); + var result = await ParseAndInvokeAsync(["info"]); result.Should().Contain("Current Config"); } diff --git a/MSStore.CLI.UnitTests/FlightsCommandUnitTests.cs b/MSStore.CLI.UnitTests/FlightsCommandUnitTests.cs index c26ec54..ec97fb3 100644 --- a/MSStore.CLI.UnitTests/FlightsCommandUnitTests.cs +++ b/MSStore.CLI.UnitTests/FlightsCommandUnitTests.cs @@ -19,12 +19,11 @@ public void Init() public async Task FlightsListCommandShouldReturnZero() { var result = await ParseAndInvokeAsync( - new string[] - { + [ "flights", "list", FakeApps[0].Id! - }); + ]); result.Should().ContainAll(FakeFlights.Select(a => a.FlightId)); result.Should().ContainAll(FakeFlights.Select(a => a.FriendlyName)); @@ -34,13 +33,12 @@ public async Task FlightsListCommandShouldReturnZero() public async Task FlightsGetCommandShouldReturnFlight() { var result = await ParseAndInvokeAsync( - new string[] - { + [ "flights", "get", FakeApps[0].Id!, FakeFlights[0].FlightId! - }); + ]); result.Should().Contain(FakeFlights[0].FlightId); result.Should().Contain(FakeFlights[0].FriendlyName); @@ -50,13 +48,12 @@ public async Task FlightsGetCommandShouldReturnFlight() public async Task FlightsDeleteCommandShouldDeleteFlight() { var result = await ParseAndInvokeAsync( - new string[] - { + [ "flights", "delete", FakeApps[0].Id!, FakeFlights[0].FlightId! - }); + ]); result.Should().Contain("Deleted Flight"); } @@ -65,15 +62,14 @@ public async Task FlightsDeleteCommandShouldDeleteFlight() public async Task FlightsCreateCommandShouldCreateFlight() { var result = await ParseAndInvokeAsync( - new string[] - { + [ "flights", "create", FakeApps[0].Id!, "NewFlight", "--group-ids", "1", - }); + ]); result.Should().Contain("Created Flight"); result.Should().Contain("NewFlight"); diff --git a/MSStore.CLI.UnitTests/FlightsSubmissionCommandUnitTests.cs b/MSStore.CLI.UnitTests/FlightsSubmissionCommandUnitTests.cs index d04b354..9d94a11 100644 --- a/MSStore.CLI.UnitTests/FlightsSubmissionCommandUnitTests.cs +++ b/MSStore.CLI.UnitTests/FlightsSubmissionCommandUnitTests.cs @@ -22,11 +22,10 @@ public void Init() public async Task FlightSubmissionCommandWithNoParameter() { var result = await ParseAndInvokeAsync( - new[] - { + [ "flights", "submission" - }); + ]); result.Should().Contain("Execute flight submissions related tasks."); } @@ -42,14 +41,13 @@ public async Task PackagedFlightSubmissionStatusCommand() InitDefaultFlightSubmissionStatusResponseQueue(); var result = await ParseAndInvokeAsync( - new[] - { + [ "flights", "submission", "status", FakeApps[0].Id!, FakeFlights[0].FlightId! - }); + ]); result.Should().Contain("Code1"); result.Should().Contain("Detail1"); @@ -64,14 +62,13 @@ public async Task PackagedFlightSubmissionGetCommand() }; var result = await ParseAndInvokeAsync( - new[] - { + [ "flights", "submission", "get", FakeApps[0].Id!, FakeFlights[0].FlightId! - }); + ]); result.Should().Contain("\"Id\": \"123456789\""); result.Should().Contain("\"FileUploadUrl\": \"https://azureblob.com/fileupload\""); @@ -81,8 +78,7 @@ public async Task PackagedFlightSubmissionGetCommand() public async Task PackagedFlightSubmissionUpdateCommand() { var result = await ParseAndInvokeAsync( - new[] - { + [ "flights", "submission", "update", @@ -97,7 +93,7 @@ public async Task PackagedFlightSubmissionUpdateCommand() } ] }" - }); + ]); result.Should().Contain("Updating flight submission product"); result.Should().Contain("\"FileUploadUrl\": \"https://azureblob.com/fileupload\""); @@ -119,14 +115,13 @@ public async Task PackagedFlightSubmissionPublishCommand() }); var result = await ParseAndInvokeAsync( - new[] - { + [ "flights", "submission", "publish", FakeApps[0].Id!, FakeFlights[0].FlightId! - }); + ]); result.Should().Contain("Flight Submission Commited with status"); } @@ -142,14 +137,13 @@ public async Task PackagedFlightSubmissionPollCommand() InitDefaultFlightSubmissionStatusResponseQueue(); var result = await ParseAndInvokeAsync( - new[] - { + [ "flights", "submission", "poll", FakeApps[0].Id!, FakeFlights[0].FlightId! - }); + ]); result.Should().Contain("Submission commit success!"); } @@ -167,14 +161,13 @@ public async Task PackagedFlightSubmissionDeleteCommand() .ReturnsAsync(true); var result = await ParseAndInvokeAsync( - new[] - { + [ "flights", "submission", "delete", FakeApps[0].Id!, FakeFlights[0].FlightId! - }); + ]); FakeConsole.Verify(x => x.YesNoConfirmationAsync(It.IsAny(), It.IsAny()), Times.Once); diff --git a/MSStore.CLI.UnitTests/FlightsSubmissionRolloutCommandsUnitTests.cs b/MSStore.CLI.UnitTests/FlightsSubmissionRolloutCommandsUnitTests.cs index 4ad0634..929f881 100644 --- a/MSStore.CLI.UnitTests/FlightsSubmissionRolloutCommandsUnitTests.cs +++ b/MSStore.CLI.UnitTests/FlightsSubmissionRolloutCommandsUnitTests.cs @@ -22,15 +22,14 @@ public void Init() public async Task FlightSubmissionRolloutGetCommandDoesntWorkIfNoSubmission() { var result = await ParseAndInvokeAsync( - new[] - { + [ "flights", "submission", "rollout", "get", FakeApps[0].Id!, FakeFlights[0].FlightId! - }, -1); + ], -1); result.Should().Contain("Could not find the flight submission. Please check the ProductId/FlightId"); } @@ -54,15 +53,14 @@ public async Task FlightSubmissionRolloutGetCommand() }); var result = await ParseAndInvokeAsync( - new[] - { + [ "flights", "submission", "rollout", "get", FakeApps[0].Id!, FakeFlights[0].FlightId! - }); + ]); result.Should().Contain("\"PackageRolloutStatus\": \"PackageRolloutNotStarted\""); } @@ -86,8 +84,7 @@ public async Task FlightSubmissionRolloutUpdateCommand() }); var result = await ParseAndInvokeAsync( - new[] - { + [ "flights", "submission", "rollout", @@ -95,7 +92,7 @@ public async Task FlightSubmissionRolloutUpdateCommand() FakeApps[0].Id!, FakeFlights[0].FlightId!, "100" - }); + ]); result.Should().Contain("\"PackageRolloutPercentage\": 100"); } @@ -119,15 +116,14 @@ public async Task FlightSubmissionRolloutHaltCommand() }); var result = await ParseAndInvokeAsync( - new[] - { + [ "flights", "submission", "rollout", "halt", FakeApps[0].Id!, FakeFlights[0].FlightId! - }); + ]); result.Should().Contain("\"PackageRolloutStatus\": \"PackageRolloutStopped\""); } @@ -151,15 +147,14 @@ public async Task FlightSubmissionRolloutFinalizeCommand() }); var result = await ParseAndInvokeAsync( - new[] - { + [ "flights", "submission", "rollout", "finalize", FakeApps[0].Id!, FakeFlights[0].FlightId! - }); + ]); result.Should().Contain("\"PackageRolloutStatus\": \"PackageRolloutComplete\""); } diff --git a/MSStore.CLI.UnitTests/GraphClientTests.cs b/MSStore.CLI.UnitTests/GraphClientTests.cs index 1bbabde..908526e 100644 --- a/MSStore.CLI.UnitTests/GraphClientTests.cs +++ b/MSStore.CLI.UnitTests/GraphClientTests.cs @@ -54,7 +54,7 @@ public void Init() } private static AuthenticationResult CreateAuthenticationResult(string accessToken) => - new AuthenticationResult(accessToken, true, null, DateTimeOffset.Now, DateTimeOffset.Now, string.Empty, null, null, null, Guid.Empty); + new(accessToken, true, null, DateTimeOffset.Now, DateTimeOffset.Now, string.Empty, null, null, null, Guid.Empty); private void SetupReturn(HttpResponseMessage httpResponseMessage) { diff --git a/MSStore.CLI.UnitTests/InitCommandUnitTests.cs b/MSStore.CLI.UnitTests/InitCommandUnitTests.cs index 5d545e6..c097ff2 100644 --- a/MSStore.CLI.UnitTests/InitCommandUnitTests.cs +++ b/MSStore.CLI.UnitTests/InitCommandUnitTests.cs @@ -16,10 +16,9 @@ public void Init() public async Task InitCommandShouldUseDefaultDirectoryIfNoArgument() { var result = await ParseAndInvokeAsync( - new string[] - { + [ "init" - }, -1); + ], -1); result.Should().Contain($"We could not find a project configurator for the project at '{Directory.GetCurrentDirectory()}'."); } @@ -30,13 +29,12 @@ public async Task InitCommandShouldOpenBrowserIfNotRegistered() AddFakeAccount(null); var result = await ParseAndInvokeAsync( - new string[] - { + [ "init", "https://www.microsoft.com/", "--publish", "--verbose" - }, -2); + ], -2); result.Should().Contain("I'll redirect you to the Microsoft Store Sign-up page."); diff --git a/MSStore.CLI.UnitTests/MSStore.CLI.UnitTests.csproj b/MSStore.CLI.UnitTests/MSStore.CLI.UnitTests.csproj index 5129c59..3df4b2d 100644 --- a/MSStore.CLI.UnitTests/MSStore.CLI.UnitTests.csproj +++ b/MSStore.CLI.UnitTests/MSStore.CLI.UnitTests.csproj @@ -1,8 +1,8 @@ - + - net8.0;net8.0-windows10.0.17763.0 - net8.0 + net9.0;net9.0-windows10.0.17763.0 + net9.0 enable enable @@ -10,14 +10,14 @@ - + - + - + @@ -43,22 +43,22 @@ - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + - + diff --git a/MSStore.CLI.UnitTests/PackageCommandUnitTests.cs b/MSStore.CLI.UnitTests/PackageCommandUnitTests.cs index 6fd8dce..2c73d92 100644 --- a/MSStore.CLI.UnitTests/PackageCommandUnitTests.cs +++ b/MSStore.CLI.UnitTests/PackageCommandUnitTests.cs @@ -19,10 +19,9 @@ public void Init() public async Task PackageCommandShouldUseDefaultDirectoryIfNoArgument() { var result = await ParseAndInvokeAsync( - new string[] - { + [ "package" - }, -1); + ], -1); result.Should().Contain($"We could not find a project configurator for the project at '{Directory.GetCurrentDirectory()}'."); } @@ -58,12 +57,11 @@ public async Task PackageCommandForUWPAppsShouldCallMSBuildIfWindows() }); var result = await ParseAndInvokeAsync( - new string[] - { + [ "package", path, "--verbose" - }); + ]); ExternalCommandExecutor.VerifyAll(); } @@ -102,14 +100,13 @@ public async Task PackageCommandForUWPAppsShouldCallMSBuildWithOutputParameterIf }); var result = await ParseAndInvokeAsync( - new string[] - { + [ "package", path, "--output", customPath, "--verbose" - }); + ]); result.Should().Contain("The packaged app is here:"); result.Should().Contain(customPath); @@ -165,12 +162,11 @@ public async Task PackageCommandForWinUIAppsShouldCallMSBuildIfWindows() }); var result = await ParseAndInvokeAsync( - new string[] - { + [ "package", path, "--verbose" - }); + ]); ExternalCommandExecutor.VerifyAll(); } @@ -229,14 +225,13 @@ public async Task PackageCommandForWinUIAppsShouldCallMSBuildWithOutputParameter }); var result = await ParseAndInvokeAsync( - new string[] - { + [ "package", path, "--output", customPath, "--verbose" - }); + ]); result.Should().Contain("The packaged app is here:"); result.Should().Contain(customPath); @@ -263,7 +258,7 @@ public async Task PackageCommandForMauiAppsShouldCallMSBuildIfWindows() ExternalCommandExecutor .Setup(x => x.RunAsync( It.Is(s => s == "dotnet"), - It.Is(s => s.Contains("publish -f net8.0-windows10.0.19041.0 -p:RuntimeIdentifierOverride=win10-x64 --self-contained -c Release")), + It.Is(s => s.Contains("publish -f net9.0-windows10.0.19041.0 -p:RuntimeIdentifierOverride=win10-x64 --self-contained -c Release")), It.Is(s => s == dirInfo.FullName), It.IsAny())) .ReturnsAsync(new Services.ExternalCommandExecutionResult @@ -274,12 +269,11 @@ public async Task PackageCommandForMauiAppsShouldCallMSBuildIfWindows() }); var result = await ParseAndInvokeAsync( - new string[] - { + [ "package", path, "--verbose" - }); + ]); ExternalCommandExecutor.VerifyAll(); } @@ -305,7 +299,7 @@ public async Task PackageCommandForMauiAppsShouldCallMSBuildWithOutputParameterI ExternalCommandExecutor .Setup(x => x.RunAsync( It.Is(s => s == "dotnet"), - It.Is(s => s.Contains("publish -f net8.0-windows10.0.19041.0 -p:RuntimeIdentifierOverride=win10-x64 --self-contained -c Release") + It.Is(s => s.Contains("publish -f net9.0-windows10.0.19041.0 -p:RuntimeIdentifierOverride=win10-x64 --self-contained -c Release") && s.Contains($"AppxPackageDir={customPath}\\") && s.EndsWith($"AppxPackageTestDir={customPath}\\MauiProject_1.0.0.0_X64_Test\\")), It.Is(s => s == dirInfo.FullName), @@ -318,14 +312,13 @@ public async Task PackageCommandForMauiAppsShouldCallMSBuildWithOutputParameterI }); var result = await ParseAndInvokeAsync( - new string[] - { + [ "package", path, "--output", customPath, "--verbose" - }); + ]); result.Should().Contain("The packaged app is here:"); result.Should().Contain(customPath); @@ -356,12 +349,11 @@ public async Task PackageCommandShouldNotWorkIfNotWindowsOnSpecificPlatforms(int SetupBasedOnTestDataProjectSubPath(dirInfo, testDataProjectSubPath); var result = await ParseAndInvokeAsync( - new string[] - { + [ "package", path, "--verbose" - }, expectedResult); + ], expectedResult); if (expectedResult == -6) { @@ -410,12 +402,11 @@ public async Task PackageCommandForFlutterAppsShouldCallFlutter() }); var result = await ParseAndInvokeAsync( - new string[] - { + [ "package", path, "--verbose" - }); + ]); result.Should().Contain("The packaged app is here:"); result.Should().Contain(path); @@ -464,14 +455,13 @@ public async Task PackageCommandForFlutterAppsShouldCallFlutterWithOutputParamet }); var result = await ParseAndInvokeAsync( - new string[] - { + [ "package", path, "--output", customPath, "--verbose" - }); + ]); result.Should().Contain("The packaged app is here:"); result.Should().Contain(customPath); @@ -523,12 +513,11 @@ public async Task PackageCommandForElectronNpmAppsShouldCallElectronNpm() }); var result = await ParseAndInvokeAsync( - new string[] - { + [ "package", path, "--verbose" - }); + ]); result.Should().Contain("The packaged app is here:"); result.Should().Contain(path); @@ -564,12 +553,11 @@ public async Task PackageCommandForElectronYarnAppsShouldCallElectronYarn() }); var result = await ParseAndInvokeAsync( - new string[] - { + [ "package", path, "--verbose" - }); + ]); result.Should().Contain("The packaged app is here:"); result.Should().Contain(path); @@ -621,12 +609,11 @@ public async Task PackageCommandForReactNativeNpmAppsShouldCallMSBuild(string ma }); var result = await ParseAndInvokeAsync( - new string[] - { + [ "package", path, "--verbose" - }); + ]); result.Should().Contain("The packaged app is here:"); result.Should().Contain(path); diff --git a/MSStore.CLI.UnitTests/ProjectConfiguratorTests.cs b/MSStore.CLI.UnitTests/ProjectConfiguratorTests.cs index 9f23fb7..6bd6aa3 100644 --- a/MSStore.CLI.UnitTests/ProjectConfiguratorTests.cs +++ b/MSStore.CLI.UnitTests/ProjectConfiguratorTests.cs @@ -58,12 +58,11 @@ public async Task ProjectConfiguratorParsesFlutterProject() }); var result = await ParseAndInvokeAsync( - new string[] - { + [ "init", path, "--verbose" - }); + ]); result = CleanResult(result); @@ -124,12 +123,11 @@ public async Task ProjectConfiguratorParsesAlreadyConfiguredFlutterProject() }); var result = await ParseAndInvokeAsync( - new string[] - { + [ "init", path, "--verbose" - }); + ]); result = CleanResult(result); @@ -181,12 +179,11 @@ public async Task ProjectConfiguratorParsesElectronNpmProject() }); var result = await ParseAndInvokeAsync( - new string[] - { + [ "init", path, "--verbose" - }); + ]); result = CleanResult(result); @@ -225,12 +222,11 @@ public async Task ProjectConfiguratorParsesAlreadyConfiguredElectronNpmProject() }); var result = await ParseAndInvokeAsync( - new string[] - { + [ "init", path, "--verbose" - }); + ]); result = CleanResult(result); @@ -282,12 +278,11 @@ public async Task ProjectConfiguratorParsesElectronYarnProject() }); var result = await ParseAndInvokeAsync( - new string[] - { + [ "init", path, "--verbose" - }); + ]); result = CleanResult(result); @@ -326,12 +321,11 @@ public async Task ProjectConfiguratorParsesAlreadyConfiguredElectronYarnProject( }); var result = await ParseAndInvokeAsync( - new string[] - { + [ "init", path, "--verbose" - }); + ]); result = CleanResult(result); @@ -357,12 +351,11 @@ public async Task ProjectConfiguratorParsesReactNativeNpmProject() SetupNpmInstall(dirInfo); var result = await ParseAndInvokeAsync( - new string[] - { + [ "init", path, "--verbose" - }); + ]); result = CleanResult(result); @@ -386,12 +379,11 @@ public async Task ProjectConfiguratorParsesAlreadyConfiguredReactNativeNpmProjec SetupNpmInstall(dirInfo); var result = await ParseAndInvokeAsync( - new string[] - { + [ "init", path, "--verbose" - }); + ]); result = CleanResult(result); @@ -415,12 +407,11 @@ public async Task ProjectConfiguratorParsesReactNativeYarnProject() SetupYarnInstall(dirInfo); var result = await ParseAndInvokeAsync( - new string[] - { + [ "init", path, "--verbose" - }); + ]); result = CleanResult(result); @@ -444,12 +435,11 @@ public async Task ProjectConfiguratorParsesAlreadyConfiguredReactNativeYarnProje SetupYarnInstall(dirInfo); var result = await ParseAndInvokeAsync( - new string[] - { + [ "init", path, "--verbose" - }); + ]); result = CleanResult(result); @@ -485,12 +475,11 @@ public async Task ProjectConfiguratorParsesUWPProject() DefaultMSBuildExecution(new DirectoryInfo(path)); var result = await ParseAndInvokeAsync( - new string[] - { + [ "init", path, "--verbose" - }); + ]); result = CleanResult(result); @@ -518,12 +507,11 @@ public async Task ProjectConfiguratorParsesWinUIProject() SetupWinUI(dirInfo); var result = await ParseAndInvokeAsync( - new string[] - { + [ "init", path, "--verbose" - }); + ]); result = CleanResult(result); @@ -547,12 +535,11 @@ public async Task ProjectConfiguratorParsesMauiProject() SetupMaui(dirInfo.GetFiles("*.csproj").First()); var result = await ParseAndInvokeAsync( - new string[] - { + [ "init", path, "--verbose" - }); + ]); result = CleanResult(result); @@ -601,15 +588,15 @@ private void SetupSuccessfullPWA(bool isRunningOnCI = false) Json = new WebManifestJson { Description = "Test description", - Screenshots = new List - { + Screenshots = + [ new ScreenShot { Src = "https://www.microsoft.com/image1.png" } - }, - Icons = new List - { + ], + Icons = + [ new Icon { Src = "https://www.microsoft.com/image2.png", @@ -620,7 +607,7 @@ private void SetupSuccessfullPWA(bool isRunningOnCI = false) Src = "https://www.microsoft.com/image3.png", Sizes = "6x5" } - } + ] } }, }); @@ -652,13 +639,12 @@ public async Task ProjectConfiguratorParsesPWASuccessfullyIfPublish() SetupSuccessfullPWA(); var result = await ParseAndInvokeAsync( - new string[] - { + [ "init", "https://microsoft.com", "--publish", "--verbose" - }); + ]); TokenManager .Verify(x => x.SelectAccountAsync(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); @@ -674,13 +660,12 @@ public async Task ProjectConfiguratorParsesPWASuccessfullyIfOnCIIfPublish() SetupSuccessfullPWA(true); var result = await ParseAndInvokeAsync( - new string[] - { + [ "init", "https://microsoft.com", "--publish", "--verbose" - }); + ]); TokenManager .Verify(x => x.SelectAccountAsync(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); @@ -697,13 +682,12 @@ public async Task ProjectConfiguratorParsesPWASuccessfullyIfOutput() SetupSuccessfullPWA(); var result = await ParseAndInvokeAsync( - new string[] - { + [ "init", "https://microsoft.com", "-o", Path.GetTempPath() - }); + ]); result.Should().Contain("You've provided a URL, so we'll use"); result.Should().NotContain("Submission commit success!"); @@ -715,11 +699,10 @@ public async Task ProjectConfiguratorFailsToParsePWAIfNotPublishAndNotOutput() SetupSuccessfullPWA(); var result = await ParseAndInvokeAsync( - new string[] - { + [ "init", "https://microsoft.com" - }, -2); + ], -2); result.Should().Contain("For PWAs the init command should output to a specific directory (using the '--output' option), or publish directly to the store using the '--publish' option."); } @@ -730,15 +713,14 @@ public async Task ProjectConfiguratorParserPWAShouldNotCallPartnerCenterAPIIfPub SetupSuccessfullPWA(); var result = await ParseAndInvokeAsync( - new string[] - { + [ "init", "https://microsoft.com", "--publisherDisplayName", "FAKE_PUBLISHER_DISPLAY_NAME", "--publish", "--verbose" - }); + ]); TokenManager .Verify(x => x.SelectAccountAsync(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); diff --git a/MSStore.CLI.UnitTests/PublishCommandUnitTests.cs b/MSStore.CLI.UnitTests/PublishCommandUnitTests.cs index a439af2..fc6f9aa 100644 --- a/MSStore.CLI.UnitTests/PublishCommandUnitTests.cs +++ b/MSStore.CLI.UnitTests/PublishCommandUnitTests.cs @@ -21,10 +21,9 @@ public void Init() public async Task PublishCommandShouldUseDefaultDirectoryIfNoArgument() { var result = await ParseAndInvokeAsync( - new string[] - { + [ "publish" - }, -1); + ], -1); result.Should().Contain($"We could not find a project publisher for the project at '{Directory.GetCurrentDirectory()}'."); } @@ -48,12 +47,11 @@ public async Task PublishCommandForUWPAppsShouldCallMSBuildIfWindows() AddDefaultFakeSuccessfulSubmission(); var result = await ParseAndInvokeAsync( - new string[] - { + [ "publish", path, "--verbose" - }); + ]); result.Should().Contain("Submission commit success! Here is some data:"); result.Should().Contain("test.msixupload"); @@ -83,12 +81,11 @@ public async Task PublishCommandForWinUIAppsShouldCallMSBuildIfWindows() AddDefaultFakeSuccessfulSubmission(); var result = await ParseAndInvokeAsync( - new string[] - { + [ "publish", path, "--verbose" - }); + ]); result.Should().Contain("Submission commit success! Here is some data:"); result.Should().Contain("test_x64.msix"); @@ -121,12 +118,11 @@ public async Task PublishCommandForMauiAppsShouldCallMSBuildIfWindows() AddDefaultFakeSuccessfulSubmission(); var result = await ParseAndInvokeAsync( - new string[] - { + [ "publish", path, "--verbose" - }); + ]); result.Should().Contain("Submission commit success! Here is some data:"); result.Should().Contain("test_x64.msix"); @@ -153,12 +149,11 @@ await FlutterProjectConfigurator.UpdateManifestAsync( AddDefaultFakeSuccessfulSubmission(); var result = await ParseAndInvokeAsync( - new string[] - { + [ "publish", path, "--verbose" - }); + ]); result.Should().Contain("Submission commit success! Here is some data:"); result.Should().Contain("test.msix"); @@ -195,12 +190,11 @@ await ElectronProjectConfigurator.UpdateManifestAsync( } var result = await ParseAndInvokeAsync( - new string[] - { + [ "publish", path, "--verbose" - }); + ]); result.Should().Contain("Submission commit success! Here is some data:"); result.Should().Contain("test.appx"); @@ -234,12 +228,11 @@ public async Task PublishCommandForReactNativeAppsShouldUploadAppxUpload(string } var result = await ParseAndInvokeAsync( - new string[] - { + [ "publish", path, "--verbose" - }); + ]); result.Should().Contain("Submission commit success! Here is some data:"); result.Should().Contain("test.appxupload"); @@ -255,14 +248,13 @@ public async Task PublishCommandForMSIXAppsShouldSucceed() AddDefaultFakeSuccessfulSubmission(); var result = await ParseAndInvokeAsync( - new string[] - { + [ "publish", msixPath, "--appId", FakeApps[0].Id!, "--verbose" - }); + ]); ZipFileManager .Verify(x => x.ExtractZip(It.IsAny(), It.IsAny()), Times.Never); @@ -281,15 +273,14 @@ public async Task PublishCommandForMSIXAppsWithNoCommitShouldNotCommit() AddDefaultFakeSuccessfulSubmission(); var result = await ParseAndInvokeAsync( - new string[] - { + [ "publish", msixPath, "--appId", FakeApps[0].Id!, "--verbose", "--noCommit" - }); + ]); ZipFileManager .Verify(x => x.ExtractZip(It.IsAny(), It.IsAny()), Times.Never); @@ -308,8 +299,7 @@ public async Task PublishCommandShouldSucceedForFlights() AddDefaultFakeSuccessfulFlightSubmission(); var result = await ParseAndInvokeAsync( - new string[] - { + [ "publish", msixPath, "--appId", @@ -317,7 +307,7 @@ public async Task PublishCommandShouldSucceedForFlights() "--flightId", FakeFlights[0].FlightId!, "--verbose" - }); + ]); ZipFileManager .Verify(x => x.ExtractZip(It.IsAny(), It.IsAny()), Times.Never); diff --git a/MSStore.CLI.UnitTests/ReconfigureCommandUnitTests.cs b/MSStore.CLI.UnitTests/ReconfigureCommandUnitTests.cs index 3f5390a..48c0251 100644 --- a/MSStore.CLI.UnitTests/ReconfigureCommandUnitTests.cs +++ b/MSStore.CLI.UnitTests/ReconfigureCommandUnitTests.cs @@ -28,10 +28,9 @@ public async Task ReconfigureCommandWithCredentialsShouldReturnZero() AddDefaultFakeAccount(); var result = await ParseAndInvokeAsync( - new string[] - { + [ "reconfigure" - }); + ]); result.Should().Contain("Awesome! It seems to be working!"); } @@ -83,10 +82,9 @@ public async Task ReconfigureCommandShouldReturnZero() }); var result = await ParseAndInvokeAsync( - new string[] - { + [ "reconfigure" - }); + ]); result.Should().Contain("Awesome! It seems to be working!"); } @@ -106,14 +104,13 @@ private Task ParseSetupSuccessWithCredentialsAndTenantAsync() .ReturnsAsync("ClientSecret"); return ParseAndInvokeAsync( - new string[] - { + [ "reconfigure", "--tenantId", DefaultOrganization.Id!.Value.ToString(), "--sellerId", "12345" - }); + ]); } [TestMethod] @@ -153,8 +150,7 @@ public async Task ReconfigureCommandWithCredentialsAndTenantShouldNotCallTokenMa public async Task ReconfigureCommandWithAllInfoShouldReturnZero() { var result = await ParseAndInvokeAsync( - new string[] - { + [ "reconfigure", "--tenantId", DefaultOrganization.Id!.Value.ToString(), @@ -164,7 +160,7 @@ public async Task ReconfigureCommandWithAllInfoShouldReturnZero() "3F0BCAEF-6334-48CF-837F-81CB0F1F2C45", "--clientSecret", "ClientSecret", - }); + ]); TokenManager .Verify(x => x.SelectAccountAsync(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); @@ -178,8 +174,7 @@ public async Task ReconfigureCommandWithAllInfoShouldReturnZero() public async Task ReconfigureCommandWithAllInfoAndCertPathShouldReturnZero() { var result = await ParseAndInvokeAsync( - new string[] - { + [ "reconfigure", "--tenantId", DefaultOrganization.Id!.Value.ToString(), @@ -189,7 +184,7 @@ public async Task ReconfigureCommandWithAllInfoAndCertPathShouldReturnZero() "3F0BCAEF-6334-48CF-837F-81CB0F1F2C45", "--certificateFilePath", "C:\\x.pfx" - }); + ]); TokenManager .Verify(x => x.SelectAccountAsync(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); @@ -203,8 +198,7 @@ public async Task ReconfigureCommandWithAllInfoAndCertPathShouldReturnZero() public async Task ReconfigureCommandWithAllInfoAndCertThumbprintShouldReturnZero() { var result = await ParseAndInvokeAsync( - new string[] - { + [ "reconfigure", "--tenantId", DefaultOrganization.Id!.Value.ToString(), @@ -214,7 +208,7 @@ public async Task ReconfigureCommandWithAllInfoAndCertThumbprintShouldReturnZero "3F0BCAEF-6334-48CF-837F-81CB0F1F2C45", "--certificateThumbprint", "abc" - }); + ]); TokenManager .Verify(x => x.SelectAccountAsync(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); diff --git a/MSStore.CLI.UnitTests/SetPublisherDisplayNameCommandUnitTests.cs b/MSStore.CLI.UnitTests/SetPublisherDisplayNameCommandUnitTests.cs index dc8ae8f..c26c86b 100644 --- a/MSStore.CLI.UnitTests/SetPublisherDisplayNameCommandUnitTests.cs +++ b/MSStore.CLI.UnitTests/SetPublisherDisplayNameCommandUnitTests.cs @@ -35,13 +35,12 @@ public async Task InitCommandUsesPublisherDisplayNameFromSettings() var publisherDisplayName = "Test Publisher Display Name"; var initResult = await ParseAndInvokeAsync( - new string[] - { + [ "init", "https://microsoft.com", "--publish", "--verbose" - }, -1); + ], -1); initResult.Should().Contain($"Using PublisherDisplayName: {publisherDisplayName}"); } @@ -52,12 +51,11 @@ public async Task SetPublisherDisplayNameCommandShouldSaveSettings() var publisherDisplayName = "New Test Publisher Display Name"; await ParseAndInvokeAsync( - new string[] - { + [ "settings", "setpdn", publisherDisplayName - }); + ]); FakeConfigurationManager .Verify(x => x.SaveAsync(It.Is(c => c.PublisherDisplayName == publisherDisplayName), It.IsAny())); diff --git a/MSStore.CLI.UnitTests/SettingsCommandUnitTests.cs b/MSStore.CLI.UnitTests/SettingsCommandUnitTests.cs index 78cc992..00f418a 100644 --- a/MSStore.CLI.UnitTests/SettingsCommandUnitTests.cs +++ b/MSStore.CLI.UnitTests/SettingsCommandUnitTests.cs @@ -20,10 +20,9 @@ public async Task SettingsCommandWithNoParametersShouldReturnZeroAndShowHelp() AddDefaultFakeAccount(); var result = await ParseAndInvokeAsync( - new string[] - { + [ "settings" - }); + ]); result.Should().Contain("Usage:"); result.Should().Contain("settings [command] [options]"); @@ -35,11 +34,10 @@ public async Task SettingsCommandShouldSetTelemetrySettingToTrue() AddDefaultFakeAccount(); var result = await ParseAndInvokeAsync( - new string[] - { + [ "settings", "-t" - }); + ]); FakeTelemetryConfigurationManager .Verify(x => x.SaveAsync(It.Is(tc => tc.TelemetryEnabled == true), It.IsAny())); @@ -51,12 +49,11 @@ public async Task SettingsCommandShouldSetTelemetrySettingToFalse() AddDefaultFakeAccount(); var result = await ParseAndInvokeAsync( - new string[] - { + [ "settings", "-t", "false" - }); + ]); FakeTelemetryConfigurationManager .Verify(x => x.SaveAsync(It.Is(tc => tc.TelemetryEnabled == false), It.IsAny())); diff --git a/MSStore.CLI.UnitTests/SubmissionCommandPackagedUnitTests.cs b/MSStore.CLI.UnitTests/SubmissionCommandPackagedUnitTests.cs index a37f526..3ea95d4 100644 --- a/MSStore.CLI.UnitTests/SubmissionCommandPackagedUnitTests.cs +++ b/MSStore.CLI.UnitTests/SubmissionCommandPackagedUnitTests.cs @@ -21,10 +21,9 @@ public void Init() public async Task SubmissionCommandWithNoParameter() { var result = await ParseAndInvokeAsync( - new[] - { + [ "submission" - }); + ]); result.Should().Contain("Executes commands to a store submission."); } @@ -40,12 +39,11 @@ public async Task PackagedSubmissionStatusCommand() InitDefaultSubmissionStatusResponseQueue(); var result = await ParseAndInvokeAsync( - new[] - { + [ "submission", "status", FakeApps[0].Id! - }); + ]); result.Should().Contain("Code1"); result.Should().Contain("Detail1"); @@ -60,12 +58,11 @@ public async Task PackagedSubmissionGetCommand() }; var result = await ParseAndInvokeAsync( - new[] - { + [ "submission", "get", FakeApps[0].Id! - }); + ]); result.Should().Contain("\"Id\": \"123456789\""); result.Should().Contain("\"FileUploadUrl\": \"https://azureblob.com/fileupload\""); @@ -80,12 +77,11 @@ public async Task PackagedSubmissionGetListingAssetsCommand() }; var result = await ParseAndInvokeAsync( - new[] - { + [ "submission", "getListingAssets", FakeApps[0].Id! - }); + ]); result.Should().Contain("\"Description\": \"BaseListingDescription\""); } @@ -94,8 +90,7 @@ public async Task PackagedSubmissionGetListingAssetsCommand() public async Task PackagedSubmissionUpdateCommand() { var result = await ParseAndInvokeAsync( - new[] - { + [ "submission", "update", FakeApps[0].Id!, @@ -108,7 +103,7 @@ public async Task PackagedSubmissionUpdateCommand() } ] }" - }); + ]); result.Should().Contain("Updating submission product"); result.Should().Contain("\"FileUploadUrl\": \"https://azureblob.com/fileupload\""); @@ -118,8 +113,7 @@ public async Task PackagedSubmissionUpdateCommand() public async Task PackagedSubmissionUpdateMetadataCommand() { var result = await ParseAndInvokeAsync( - new[] - { + [ "submission", "updateMetadata", FakeApps[0].Id!, @@ -136,7 +130,7 @@ public async Task PackagedSubmissionUpdateMetadataCommand() } } }" - }); + ]); result.Should().Contain("Updating submission product"); result.Should().Contain("\"FileUploadUrl\": \"https://azureblob.com/fileupload\""); @@ -158,12 +152,11 @@ public async Task PackagedSubmissionPublishCommand() }); var result = await ParseAndInvokeAsync( - new[] - { + [ "submission", "publish", FakeApps[0].Id! - }); + ]); result.Should().Contain("Submission Commited with status"); } @@ -179,12 +172,11 @@ public async Task PackagedSubmissionPollCommand() InitDefaultSubmissionStatusResponseQueue(); var result = await ParseAndInvokeAsync( - new[] - { + [ "submission", "poll", FakeApps[0].Id! - }); + ]); result.Should().Contain("Submission commit success!"); } @@ -202,12 +194,11 @@ public async Task PackagedSubmissionDeleteCommand() .ReturnsAsync(true); var result = await ParseAndInvokeAsync( - new[] - { + [ "submission", "delete", FakeApps[0].Id! - }); + ]); FakeConsole.Verify(x => x.YesNoConfirmationAsync(It.IsAny(), It.IsAny()), Times.Once); diff --git a/MSStore.CLI.UnitTests/SubmissionCommandUnpackagedUnitTests.cs b/MSStore.CLI.UnitTests/SubmissionCommandUnpackagedUnitTests.cs index ffed96c..8892b8d 100644 --- a/MSStore.CLI.UnitTests/SubmissionCommandUnpackagedUnitTests.cs +++ b/MSStore.CLI.UnitTests/SubmissionCommandUnpackagedUnitTests.cs @@ -29,12 +29,11 @@ public async Task UnpackagedSubmissionStatusCommand() }); var result = await ParseAndInvokeAsync( - new[] - { + [ "submission", "status", Guid.Empty.ToString() - }); + ]); result.Should().Contain("\"IsReady\": true,"); } @@ -49,23 +48,22 @@ public async Task UnpackagedSubmissionGetCommand() IsSuccess = true, ResponseData = new PackagesMetadataResponse { - Packages = new List - { + Packages = + [ new Package { PackageId = "12345" } - } + ] } }); var result = await ParseAndInvokeAsync( - new[] - { + [ "submission", "get", Guid.Empty.ToString() - }); + ]); result.Should().Contain("\"PackageId\": \"12345\""); } @@ -78,13 +76,13 @@ public async Task UnpackagedSubmissionGetListingAssetsCommand() .ReturnsAsync( new ListingAssetsResponse { - ListingAssets = new List - { + ListingAssets = + [ new ListingAsset { Language = "en-us", - Screenshots = new List - { + Screenshots = + [ new Screenshot { AssetUrl = "https://www.example.com/screenshot.png", @@ -95,18 +93,17 @@ public async Task UnpackagedSubmissionGetListingAssetsCommand() Width = 100 } } - } + ] } - } + ] }); var result = await ParseAndInvokeAsync( - new[] - { + [ "submission", "getListingAssets", Guid.Empty.ToString() - }); + ]); result.Should().Contain("\"AssetUrl\": \"https://www.example.com/screenshot.png\","); } @@ -123,8 +120,7 @@ public async Task UnpackagedSubmissionUpdateCommand() }); var result = await ParseAndInvokeAsync( - new[] - { + [ "submission", "update", Guid.Empty.ToString(), @@ -137,7 +133,7 @@ public async Task UnpackagedSubmissionUpdateCommand() } ] }" - }); + ]); result.Should().Contain("Updating submission product"); result.Should().Contain("\"PollingUrl\": \"https://www.example.com/polling\""); @@ -156,8 +152,7 @@ public async Task UnpackagedSubmissionUpdateMetadataCommand() }); var result = await ParseAndInvokeAsync( - new[] - { + [ "submission", "updateMetadata", Guid.Empty.ToString(), @@ -168,7 +163,7 @@ public async Task UnpackagedSubmissionUpdateMetadataCommand() ""Pricing"":""1"" } }" - }); + ]); result.Should().Contain("Updating submission metadata"); result.Should().Contain("\"PollingUrl\": \"https://www.example.com/polling\""); @@ -183,12 +178,11 @@ public async Task UnpackagedSubmissionPublishCommand() .ReturnsAsync("12345"); var result = await ParseAndInvokeAsync( - new[] - { + [ "submission", "publish", Guid.Empty.ToString() - }); + ]); result.Should().Contain("Published with Id"); } @@ -238,12 +232,11 @@ public async Task UnpackagedSubmissionPollCommand() }); var result = await ParseAndInvokeAsync( - new[] - { + [ "submission", "poll", Guid.Empty.ToString() - }); + ]); result.Should().Contain("INPROGRESS"); result.Should().Contain("PUBLISHED"); @@ -253,12 +246,11 @@ public async Task UnpackagedSubmissionPollCommand() public async Task UnpackagedSubmissionDeleteCommand() { var result = await ParseAndInvokeAsync( - new[] - { + [ "submission", "delete", Guid.Empty.ToString() - }, -1); + ], -1); result.Should().Contain("This command is not supported for unpackaged applications."); } diff --git a/MSStore.CLI.UnitTests/TelemetryUnitTests.cs b/MSStore.CLI.UnitTests/TelemetryUnitTests.cs index 5532523..bd32273 100644 --- a/MSStore.CLI.UnitTests/TelemetryUnitTests.cs +++ b/MSStore.CLI.UnitTests/TelemetryUnitTests.cs @@ -27,7 +27,7 @@ public async Task EmptyCommandFirstRunShouldHavePrivacyLinkIfNotSignedIn() .Setup(x => x.YesNoConfirmationAsync(It.IsAny(), It.IsAny())) .ReturnsAsync(true); - var result = await ParseAndInvokeAsync(Array.Empty(), null); + var result = await ParseAndInvokeAsync([], null); result.Should().Contain("https://aka.ms/privacy"); } @@ -37,7 +37,7 @@ public async Task EmptyCommandFirstRunShouldHavePrivacyLinkIfSignedIn() { FakeLogin(); - var result = await ParseAndInvokeAsync(Array.Empty(), null); + var result = await ParseAndInvokeAsync([], null); result.Should().Contain("https://aka.ms/privacy"); } diff --git a/MSStore.CLI.UnitTests/TestData/MauiProject/MauiApp.csproj.template b/MSStore.CLI.UnitTests/TestData/MauiProject/MauiApp.csproj.template index 1367bb7..0e3c783 100644 --- a/MSStore.CLI.UnitTests/TestData/MauiProject/MauiApp.csproj.template +++ b/MSStore.CLI.UnitTests/TestData/MauiProject/MauiApp.csproj.template @@ -1,7 +1,7 @@ - net8.0-android;net8.0-ios;net8.0-maccatalyst - $(TargetFrameworks);net8.0-windows10.0.19041.0 + net9.0-android;net9.0-ios;net9.0-maccatalyst + $(TargetFrameworks);net9.0-windows10.0.19041.0 00000000-0000-0000-0000-000000000000 AppTitle true diff --git a/MSStore.CLI/Commands/Apps/GetCommand.cs b/MSStore.CLI/Commands/Apps/GetCommand.cs index 81ff80f..427bd23 100644 --- a/MSStore.CLI/Commands/Apps/GetCommand.cs +++ b/MSStore.CLI/Commands/Apps/GetCommand.cs @@ -25,21 +25,14 @@ public GetCommand() AddArgument(SubmissionCommand.ProductIdArgument); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string ProductId { get; set; } = null!; - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/Apps/ListCommand.cs b/MSStore.CLI/Commands/Apps/ListCommand.cs index cf84c25..d36c649 100644 --- a/MSStore.CLI/Commands/Apps/ListCommand.cs +++ b/MSStore.CLI/Commands/Apps/ListCommand.cs @@ -21,18 +21,11 @@ public ListCommand() { } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; - - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public int Invoke(InvocationContext context) { diff --git a/MSStore.CLI/Commands/Flights/CreateCommand.cs b/MSStore.CLI/Commands/Flights/CreateCommand.cs index 1628849..f7a4973 100644 --- a/MSStore.CLI/Commands/Flights/CreateCommand.cs +++ b/MSStore.CLI/Commands/Flights/CreateCommand.cs @@ -27,11 +27,11 @@ public CreateCommand() AddArgument(new Argument("friendlyName", "The friendly name of the flight.")); var groupIdsOption = new Option>( - aliases: new string[] - { + aliases: + [ "--group-ids", "-g" - }, + ], getDefaultValue: Array.Empty, description: "The group IDs to associate with the flight.") { @@ -48,27 +48,20 @@ public CreateCommand() AddOption(groupIdsOption); - AddOption(new Option(new[] { "--rank-higher-than", "-r" }, "The flight ID to rank higher than.")); + AddOption(new Option(["--rank-higher-than", "-r"], "The flight ID to rank higher than.")); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string ProductId { get; set; } = null!; public string FriendlyName { get; set; } = null!; public IEnumerable GroupIds { get; set; } = null!; public string? RankHigherThan { get; set; } - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/Flights/DeleteCommand.cs b/MSStore.CLI/Commands/Flights/DeleteCommand.cs index 0cb65e5..ec0c70e 100644 --- a/MSStore.CLI/Commands/Flights/DeleteCommand.cs +++ b/MSStore.CLI/Commands/Flights/DeleteCommand.cs @@ -24,22 +24,15 @@ public DeleteCommand() AddArgument(GetCommand.FlightIdArgument); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string ProductId { get; set; } = null!; public string FlightId { get; set; } = null!; - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/Flights/GetCommand.cs b/MSStore.CLI/Commands/Flights/GetCommand.cs index 4ba9231..84f7a9a 100644 --- a/MSStore.CLI/Commands/Flights/GetCommand.cs +++ b/MSStore.CLI/Commands/Flights/GetCommand.cs @@ -31,22 +31,15 @@ public GetCommand() AddArgument(FlightIdArgument); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string ProductId { get; set; } = null!; public string FlightId { get; set; } = null!; - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/Flights/ListCommand.cs b/MSStore.CLI/Commands/Flights/ListCommand.cs index 3229f10..efd5dfa 100644 --- a/MSStore.CLI/Commands/Flights/ListCommand.cs +++ b/MSStore.CLI/Commands/Flights/ListCommand.cs @@ -22,21 +22,14 @@ public ListCommand() AddArgument(SubmissionCommand.ProductIdArgument); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string ProductId { get; set; } = null!; - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; @@ -77,7 +70,7 @@ await AnsiConsole.Status().StartAsync("Retrieving Flights", async ctx => $"[bold u]{f.FriendlyName}[/]", $"[bold u]{f.LastPublishedFlightSubmission?.Id}[/]", $"[bold u]{f.PendingFlightSubmission?.Id}[/]", - $"[bold u]{string.Join(", ", f.GroupIds ?? new())}[/]", + $"[bold u]{string.Join(", ", f.GroupIds ?? [])}[/]", $"[bold u]{f.RankHigherThan}[/]"); i++; } diff --git a/MSStore.CLI/Commands/Flights/Submission/DeleteCommand.cs b/MSStore.CLI/Commands/Flights/Submission/DeleteCommand.cs index 816e292..22e19f6 100644 --- a/MSStore.CLI/Commands/Flights/Submission/DeleteCommand.cs +++ b/MSStore.CLI/Commands/Flights/Submission/DeleteCommand.cs @@ -25,27 +25,18 @@ public DeleteCommand() AddOption(Commands.Submission.DeleteCommand.NoConfirmOption); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, IConsoleReader consoleReader, IBrowserLauncher browserLauncher, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly IConsoleReader _consoleReader; - private readonly IBrowserLauncher _browserLauncher; - private readonly TelemetryClient _telemetryClient; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly IConsoleReader _consoleReader = consoleReader ?? throw new ArgumentNullException(nameof(consoleReader)); + private readonly IBrowserLauncher _browserLauncher = browserLauncher ?? throw new ArgumentNullException(nameof(browserLauncher)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string ProductId { get; set; } = null!; public string FlightId { get; set; } = null!; public bool? NoConfirm { get; set; } - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, IConsoleReader consoleReader, IBrowserLauncher browserLauncher, TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _consoleReader = consoleReader ?? throw new ArgumentNullException(nameof(consoleReader)); - _browserLauncher = browserLauncher ?? throw new ArgumentNullException(nameof(browserLauncher)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/Flights/Submission/GetCommand.cs b/MSStore.CLI/Commands/Flights/Submission/GetCommand.cs index 26eb355..f9eff38 100644 --- a/MSStore.CLI/Commands/Flights/Submission/GetCommand.cs +++ b/MSStore.CLI/Commands/Flights/Submission/GetCommand.cs @@ -25,22 +25,15 @@ public GetCommand() AddArgument(Flights.GetCommand.FlightIdArgument); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string ProductId { get; set; } = null!; public string FlightId { get; set; } = null!; - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/Flights/Submission/PollCommand.cs b/MSStore.CLI/Commands/Flights/Submission/PollCommand.cs index a862bcd..bb6d9fa 100644 --- a/MSStore.CLI/Commands/Flights/Submission/PollCommand.cs +++ b/MSStore.CLI/Commands/Flights/Submission/PollCommand.cs @@ -24,24 +24,16 @@ public PollCommand() AddArgument(Flights.GetCommand.FlightIdArgument); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient, IBrowserLauncher browserLauncher) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; - private readonly IBrowserLauncher _browserLauncher; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); + private readonly IBrowserLauncher _browserLauncher = browserLauncher ?? throw new ArgumentNullException(nameof(browserLauncher)); public string ProductId { get; set; } = null!; public string FlightId { get; set; } = null!; - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient, IBrowserLauncher browserLauncher) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - _browserLauncher = browserLauncher ?? throw new ArgumentNullException(nameof(browserLauncher)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/Flights/Submission/PublishCommand.cs b/MSStore.CLI/Commands/Flights/Submission/PublishCommand.cs index 4f63bd4..95f1416 100644 --- a/MSStore.CLI/Commands/Flights/Submission/PublishCommand.cs +++ b/MSStore.CLI/Commands/Flights/Submission/PublishCommand.cs @@ -23,22 +23,15 @@ public PublishCommand() AddArgument(Flights.GetCommand.FlightIdArgument); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string ProductId { get; set; } = null!; public string FlightId { get; set; } = null!; - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/Flights/Submission/Rollout/FinalizeCommand.cs b/MSStore.CLI/Commands/Flights/Submission/Rollout/FinalizeCommand.cs index bd47da8..d4494b7 100644 --- a/MSStore.CLI/Commands/Flights/Submission/Rollout/FinalizeCommand.cs +++ b/MSStore.CLI/Commands/Flights/Submission/Rollout/FinalizeCommand.cs @@ -26,23 +26,16 @@ public FinalizeCommand() AddOption(Commands.Submission.Rollout.GetCommand.SubmissionIdOption); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string ProductId { get; set; } = null!; public string FlightId { get; set; } = null!; public string? SubmissionId { get; set; } - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/Flights/Submission/Rollout/GetCommand.cs b/MSStore.CLI/Commands/Flights/Submission/Rollout/GetCommand.cs index 44cbefc..a679254 100644 --- a/MSStore.CLI/Commands/Flights/Submission/Rollout/GetCommand.cs +++ b/MSStore.CLI/Commands/Flights/Submission/Rollout/GetCommand.cs @@ -26,23 +26,16 @@ public GetCommand() AddOption(Commands.Submission.Rollout.GetCommand.SubmissionIdOption); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string ProductId { get; set; } = null!; public string FlightId { get; set; } = null!; public string? SubmissionId { get; set; } - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/Flights/Submission/Rollout/HaltCommand.cs b/MSStore.CLI/Commands/Flights/Submission/Rollout/HaltCommand.cs index d89944f..d97e5e8 100644 --- a/MSStore.CLI/Commands/Flights/Submission/Rollout/HaltCommand.cs +++ b/MSStore.CLI/Commands/Flights/Submission/Rollout/HaltCommand.cs @@ -26,23 +26,16 @@ public HaltCommand() AddOption(Commands.Submission.Rollout.GetCommand.SubmissionIdOption); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string ProductId { get; set; } = null!; public string FlightId { get; set; } = null!; public string? SubmissionId { get; set; } - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/Flights/Submission/Rollout/UpdateCommand.cs b/MSStore.CLI/Commands/Flights/Submission/Rollout/UpdateCommand.cs index 764a954..0ba50b2 100644 --- a/MSStore.CLI/Commands/Flights/Submission/Rollout/UpdateCommand.cs +++ b/MSStore.CLI/Commands/Flights/Submission/Rollout/UpdateCommand.cs @@ -31,24 +31,17 @@ public UpdateCommand() AddArgument(percentage); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string ProductId { get; set; } = null!; public string FlightId { get; set; } = null!; public string? SubmissionId { get; set; } public float Percentage { get; set; } - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/Flights/Submission/StatusCommand.cs b/MSStore.CLI/Commands/Flights/Submission/StatusCommand.cs index 918f7a7..8bf99d1 100644 --- a/MSStore.CLI/Commands/Flights/Submission/StatusCommand.cs +++ b/MSStore.CLI/Commands/Flights/Submission/StatusCommand.cs @@ -23,22 +23,15 @@ public StatusCommand() AddArgument(Flights.GetCommand.FlightIdArgument); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string ProductId { get; set; } = null!; public string FlightId { get; set; } = null!; - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/Flights/Submission/UpdateCommand.cs b/MSStore.CLI/Commands/Flights/Submission/UpdateCommand.cs index 276baa2..4782027 100644 --- a/MSStore.CLI/Commands/Flights/Submission/UpdateCommand.cs +++ b/MSStore.CLI/Commands/Flights/Submission/UpdateCommand.cs @@ -32,24 +32,17 @@ public UpdateCommand() AddOption(SubmissionCommand.SkipInitialPolling); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string Product { get; set; } = null!; public bool SkipInitialPolling { get; set; } public string ProductId { get; set; } = null!; public string FlightId { get; set; } = null!; - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/InfoCommand.cs b/MSStore.CLI/Commands/InfoCommand.cs index cb1cb75..3eee5c0 100644 --- a/MSStore.CLI/Commands/InfoCommand.cs +++ b/MSStore.CLI/Commands/InfoCommand.cs @@ -20,18 +20,11 @@ public InfoCommand() { } - public new class Handler : ICommandHandler + public new class Handler(IConfigurationManager configurationManager, TelemetryClient telemetryClient, ILogger logger) : ICommandHandler { - private readonly IConfigurationManager _configurationManager; - private readonly TelemetryClient _telemetryClient; - private readonly ILogger _logger; - - public Handler(IConfigurationManager configurationManager, TelemetryClient telemetryClient, ILogger logger) - { - _configurationManager = configurationManager ?? throw new ArgumentNullException(nameof(configurationManager)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - } + private readonly IConfigurationManager _configurationManager = configurationManager ?? throw new ArgumentNullException(nameof(configurationManager)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); public int Invoke(InvocationContext context) { @@ -44,8 +37,10 @@ public async Task InvokeAsync(InvocationContext context) var config = await _configurationManager.LoadAsync(ct: ct); - var table = new Table(); - table.Title = new TableTitle($"[b]Current Config[/]"); + var table = new Table + { + Title = new TableTitle($"[b]Current Config[/]") + }; table.AddColumns("Config", "Value"); diff --git a/MSStore.CLI/Commands/InitCommand.cs b/MSStore.CLI/Commands/InitCommand.cs index 720951d..bbd9c61 100644 --- a/MSStore.CLI/Commands/InitCommand.cs +++ b/MSStore.CLI/Commands/InitCommand.cs @@ -67,30 +67,30 @@ bool IsUri() }); Output = new Option( - aliases: new string[] - { + aliases: + [ "--output", "-o" - }, + ], description: "The output directory where the packaged app will be stored. If not provided, the default directory for each different type of app will be used."); Arch = new Option>( - aliases: new string[] - { + aliases: + [ "--arch", "-a" - }, + ], description: "The architecture(s) to build for. If not provided, the default architecture for the current OS, and project type, will be used.") { AllowMultipleArgumentsPerToken = true, }; Version = new Option( - aliases: new string[] - { + aliases: + [ "--version", "-ver" - }, + ], parseArgument: result => { var version = result.Tokens.Single().Value; @@ -111,29 +111,29 @@ public InitCommand() AddArgument(PathOrUrl); var publisherDisplayName = new Option( - aliases: new string[] - { + aliases: + [ "--publisherDisplayName", "-n" - }, + ], description: "The Publisher Display Name used to configure the application. If provided, avoids an extra APIs call."); AddOption(publisherDisplayName); var package = new Option( - aliases: new string[] - { + aliases: + [ "--package" - }, + ], description: "If supported by the app type, automatically packs the project."); AddOption(package); var publish = new Option( - aliases: new string[] - { + aliases: + [ "--publish" - }, + ], description: "If supported by the app type, automatically publishes the project. Implies '--package true'"); AddOption(publish); @@ -149,18 +149,28 @@ public InitCommand() AddOption(PublishCommand.PackageRolloutPercentageOption); } - public new class Handler : ICommandHandler + public new class Handler( + ILogger logger, + IBrowserLauncher browserLauncher, + IConsoleReader consoleReader, + IProjectConfiguratorFactory projectConfiguratorFactory, + IStoreAPIFactory storeAPIFactory, + ITokenManager tokenManager, + IPartnerCenterManager partnerCenterManager, + IImageConverter imageConverter, + IConfigurationManager configurationManager, + TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IBrowserLauncher _browserLauncher; - private readonly IConsoleReader _consoleReader; - private readonly IProjectConfiguratorFactory _projectConfiguratorFactory; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly ITokenManager _tokenManager; - private readonly IPartnerCenterManager _partnerCenterManager; - private readonly IImageConverter _imageConverter; - private readonly IConfigurationManager _configurationManager; - private readonly TelemetryClient _telemetryClient; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IBrowserLauncher _browserLauncher = browserLauncher ?? throw new ArgumentNullException(nameof(browserLauncher)); + private readonly IConsoleReader _consoleReader = consoleReader ?? throw new ArgumentNullException(nameof(consoleReader)); + private readonly IProjectConfiguratorFactory _projectConfiguratorFactory = projectConfiguratorFactory ?? throw new ArgumentNullException(nameof(projectConfiguratorFactory)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly ITokenManager _tokenManager = tokenManager ?? throw new ArgumentNullException(nameof(tokenManager)); + private readonly IPartnerCenterManager _partnerCenterManager = partnerCenterManager ?? throw new ArgumentNullException(nameof(partnerCenterManager)); + private readonly IImageConverter _imageConverter = imageConverter ?? throw new ArgumentNullException(nameof(imageConverter)); + private readonly IConfigurationManager _configurationManager = configurationManager ?? throw new ArgumentNullException(nameof(configurationManager)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string PathOrUrl { get; set; } = null!; @@ -180,30 +190,6 @@ public InitCommand() public IEnumerable? Arch { get; set; } = null!; - public Handler( - ILogger logger, - IBrowserLauncher browserLauncher, - IConsoleReader consoleReader, - IProjectConfiguratorFactory projectConfiguratorFactory, - IStoreAPIFactory storeAPIFactory, - ITokenManager tokenManager, - IPartnerCenterManager partnerCenterManager, - IImageConverter imageConverter, - IConfigurationManager configurationManager, - TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _browserLauncher = browserLauncher ?? throw new ArgumentNullException(nameof(browserLauncher)); - _consoleReader = consoleReader ?? throw new ArgumentNullException(nameof(consoleReader)); - _projectConfiguratorFactory = projectConfiguratorFactory ?? throw new ArgumentNullException(nameof(projectConfiguratorFactory)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _tokenManager = tokenManager ?? throw new ArgumentNullException(nameof(tokenManager)); - _partnerCenterManager = partnerCenterManager ?? throw new ArgumentNullException(nameof(partnerCenterManager)); - _imageConverter = imageConverter ?? throw new ArgumentNullException(nameof(imageConverter)); - _configurationManager = configurationManager ?? throw new ArgumentNullException(nameof(configurationManager)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/PackageCommand.cs b/MSStore.CLI/Commands/PackageCommand.cs index da3d08e..3814180 100644 --- a/MSStore.CLI/Commands/PackageCommand.cs +++ b/MSStore.CLI/Commands/PackageCommand.cs @@ -30,13 +30,18 @@ public PackageCommand() AddOption(InitCommand.Arch); } - public new class Handler : ICommandHandler + public new class Handler( + IProjectConfiguratorFactory projectConfiguratorFactory, + IStoreAPIFactory storeAPIFactory, + IImageConverter imageConverter, + ILogger logger, + TelemetryClient telemetryClient) : ICommandHandler { - private readonly IProjectConfiguratorFactory _projectConfiguratorFactory; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly IImageConverter _imageConverter; - private readonly ILogger _logger; - private readonly TelemetryClient _telemetryClient; + private readonly IProjectConfiguratorFactory _projectConfiguratorFactory = projectConfiguratorFactory ?? throw new ArgumentNullException(nameof(projectConfiguratorFactory)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly IImageConverter _imageConverter = imageConverter ?? throw new ArgumentNullException(nameof(imageConverter)); + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string PathOrUrl { get; set; } = null!; @@ -46,20 +51,6 @@ public PackageCommand() public IEnumerable? Arch { get; set; } = null!; - public Handler( - IProjectConfiguratorFactory projectConfiguratorFactory, - IStoreAPIFactory storeAPIFactory, - IImageConverter imageConverter, - ILogger logger, - TelemetryClient telemetryClient) - { - _projectConfiguratorFactory = projectConfiguratorFactory ?? throw new ArgumentNullException(nameof(projectConfiguratorFactory)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _imageConverter = imageConverter ?? throw new ArgumentNullException(nameof(imageConverter)); - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/PublishCommand.cs b/MSStore.CLI/Commands/PublishCommand.cs index 47270ca..de4010b 100644 --- a/MSStore.CLI/Commands/PublishCommand.cs +++ b/MSStore.CLI/Commands/PublishCommand.cs @@ -26,10 +26,10 @@ internal class PublishCommand : Command static PublishCommand() { FlightIdOption = new Option( - aliases: new string[] { "--flightId", "-f" }, + aliases: ["--flightId", "-f"], description: "Specifies the Flight Id where the package will be published."); PackageRolloutPercentageOption = new Option( - aliases: new string[] { "--packageRolloutPercentage", "-prp" }, + aliases: ["--packageRolloutPercentage", "-prp"], description: "Specifies the rollout percentage of the package. The value must be between 0 and 100.", isDefault: false, parseArgument: result => @@ -63,11 +63,11 @@ public PublishCommand() AddArgument(InitCommand.PathOrUrl); var inputDirectory = new Option( - aliases: new string[] - { + aliases: + [ "--inputDirectory", "-i" - }, + ], description: "The directory where the '.msix' or '.msixupload' file to be used for the publishing command. If not provided, the cli will try to find the best candidate based on the 'pathOrUrl' argument.", parseArgument: result => { @@ -91,21 +91,21 @@ public PublishCommand() AddOption(inputDirectory); var appIdOption = new Option( - aliases: new string[] - { + aliases: + [ "--appId", "-id" - }, + ], description: "Specifies the Application Id. Only needed if the project has not been initialized before with the 'init' command."); AddOption(appIdOption); var noCommitOption = new Option( - aliases: new string[] - { + aliases: + [ "--noCommit", "-nc" - }, + ], description: "Disables committing the submission, keeping it in draft state.", getDefaultValue: () => false); @@ -116,12 +116,16 @@ public PublishCommand() AddOption(PackageRolloutPercentageOption); } - public new class Handler : ICommandHandler + public new class Handler( + IProjectConfiguratorFactory projectConfiguratorFactory, + IStoreAPIFactory storeAPIFactory, + TelemetryClient telemetryClient, + ILogger logger) : ICommandHandler { - private readonly IProjectConfiguratorFactory _projectConfiguratorFactory; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; - private readonly ILogger _logger; + private readonly IProjectConfiguratorFactory _projectConfiguratorFactory = projectConfiguratorFactory ?? throw new ArgumentNullException(nameof(projectConfiguratorFactory)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); public string PathOrUrl { get; set; } = null!; @@ -134,18 +138,6 @@ public PublishCommand() public bool NoCommit { get; set; } - public Handler( - IProjectConfiguratorFactory projectConfiguratorFactory, - IStoreAPIFactory storeAPIFactory, - TelemetryClient telemetryClient, - ILogger logger) - { - _projectConfiguratorFactory = projectConfiguratorFactory ?? throw new ArgumentNullException(nameof(projectConfiguratorFactory)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/ReconfigureCommand.cs b/MSStore.CLI/Commands/ReconfigureCommand.cs index 7d1bc33..26dff58 100644 --- a/MSStore.CLI/Commands/ReconfigureCommand.cs +++ b/MSStore.CLI/Commands/ReconfigureCommand.cs @@ -19,35 +19,35 @@ public ReconfigureCommand() : base("reconfigure", "Re-configure the Microsoft Store Developer CLI.") { var tenantId = new Option( - aliases: new string[] { "--tenantId", "-t" }, + aliases: ["--tenantId", "-t"], description: "Specify the tenant Id that should be used."); var sellerId = new Option( - aliases: new string[] { "--sellerId", "-s" }, + aliases: ["--sellerId", "-s"], description: "Specify the seller Id that should be used."); var clientId = new Option( - aliases: new string[] { "--clientId", "-c" }, + aliases: ["--clientId", "-c"], description: "Specify the client Id that should be used."); var clientSecret = new Option( - aliases: new string[] { "--clientSecret", "-cs" }, + aliases: ["--clientSecret", "-cs"], description: "Specify the client Secret that should be used."); var certificateThumbprint = new Option( - aliases: new string[] { "--certificateThumbprint", "-ct" }, + aliases: ["--certificateThumbprint", "-ct"], description: "Specify the certificate Thumbprint that should be used."); var certificateFilePath = new Option( - aliases: new string[] { "--certificateFilePath", "-cfp" }, + aliases: ["--certificateFilePath", "-cfp"], description: "Specify the certificate file path that should be used."); var certificatePassword = new Option( - aliases: new string[] { "--certificatePassword", "-cp" }, + aliases: ["--certificatePassword", "-cp"], description: "Specify the certificate password that should be used."); var reset = new Option( - aliases: new string[] { "--reset" }, + aliases: ["--reset"], description: "Only reset the credentials, without starting over."); AddOption(tenantId); @@ -60,10 +60,10 @@ public ReconfigureCommand() AddOption(reset); } - public new class Handler : ICommandHandler + public new class Handler(ICLIConfigurator cliConfigurator, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ICLIConfigurator _cliConfigurator; - private readonly TelemetryClient _telemetryClient; + private readonly ICLIConfigurator _cliConfigurator = cliConfigurator; + private readonly TelemetryClient _telemetryClient = telemetryClient; public Guid? TenantId { get; set; } public string? SellerId { get; set; } @@ -74,12 +74,6 @@ public ReconfigureCommand() public string? CertificatePassword { get; set; } public bool? Reset { get; set; } - public Handler(ICLIConfigurator cliConfigurator, TelemetryClient telemetryClient) - { - _cliConfigurator = cliConfigurator; - _telemetryClient = telemetryClient; - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/Settings/SetPublisherDisplayNameCommand.cs b/MSStore.CLI/Commands/Settings/SetPublisherDisplayNameCommand.cs index a4e445d..ec46103 100644 --- a/MSStore.CLI/Commands/Settings/SetPublisherDisplayNameCommand.cs +++ b/MSStore.CLI/Commands/Settings/SetPublisherDisplayNameCommand.cs @@ -21,21 +21,15 @@ public SetPublisherDisplayNameCommand() AddArgument(publisherDisplayName); } - public new class Handler : ICommandHandler + public new class Handler( + IConfigurationManager configurationManager, + TelemetryClient telemetryClient) : ICommandHandler { - private readonly IConfigurationManager _configurationManager; - private readonly TelemetryClient _telemetryClient; + private readonly IConfigurationManager _configurationManager = configurationManager ?? throw new ArgumentNullException(nameof(configurationManager)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string? PublisherDisplayName { get; set; } - public Handler( - IConfigurationManager configurationManager, - TelemetryClient telemetryClient) - { - _configurationManager = configurationManager ?? throw new ArgumentNullException(nameof(configurationManager)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/SettingsCommand.cs b/MSStore.CLI/Commands/SettingsCommand.cs index 50e6248..e6091ff 100644 --- a/MSStore.CLI/Commands/SettingsCommand.cs +++ b/MSStore.CLI/Commands/SettingsCommand.cs @@ -34,23 +34,15 @@ public SettingsCommand() }); } - public new class Handler : ICommandHandler + public new class Handler(TelemetryClient telemetryClient, IConfigurationManager telemetryConfigurationManager, IConfigurationManager configurationManager, ILogger logger) : ICommandHandler { - private readonly TelemetryClient _telemetryClient; - private readonly IConfigurationManager _telemetryConfigurationManager; - private readonly IConfigurationManager _configurationManager; - private readonly ILogger _logger; + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); + private readonly IConfigurationManager _telemetryConfigurationManager = telemetryConfigurationManager ?? throw new ArgumentNullException(nameof(telemetryConfigurationManager)); + private readonly IConfigurationManager _configurationManager = configurationManager ?? throw new ArgumentNullException(nameof(configurationManager)); + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); public bool? EnableTelemetry { get; set; } - public Handler(TelemetryClient telemetryClient, IConfigurationManager telemetryConfigurationManager, IConfigurationManager configurationManager, ILogger logger) - { - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - _telemetryConfigurationManager = telemetryConfigurationManager ?? throw new ArgumentNullException(nameof(telemetryConfigurationManager)); - _configurationManager = configurationManager ?? throw new ArgumentNullException(nameof(configurationManager)); - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/Submission/DeleteCommand.cs b/MSStore.CLI/Commands/Submission/DeleteCommand.cs index 059c5a2..bb52fff 100644 --- a/MSStore.CLI/Commands/Submission/DeleteCommand.cs +++ b/MSStore.CLI/Commands/Submission/DeleteCommand.cs @@ -34,27 +34,18 @@ public DeleteCommand() AddOption(NoConfirmOption); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, IConsoleReader consoleReader, IBrowserLauncher browserLauncher, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly IConsoleReader _consoleReader; - private readonly IBrowserLauncher _browserLauncher; - private readonly TelemetryClient _telemetryClient; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly IConsoleReader _consoleReader = consoleReader ?? throw new ArgumentNullException(nameof(consoleReader)); + private readonly IBrowserLauncher _browserLauncher = browserLauncher ?? throw new ArgumentNullException(nameof(browserLauncher)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string ProductId { get; set; } = null!; public bool? NoConfirm { get; set; } - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, IConsoleReader consoleReader, IBrowserLauncher browserLauncher, TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _consoleReader = consoleReader ?? throw new ArgumentNullException(nameof(consoleReader)); - _browserLauncher = browserLauncher ?? throw new ArgumentNullException(nameof(browserLauncher)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/Submission/GetCommand.cs b/MSStore.CLI/Commands/Submission/GetCommand.cs index 864e220..0e2df51 100644 --- a/MSStore.CLI/Commands/Submission/GetCommand.cs +++ b/MSStore.CLI/Commands/Submission/GetCommand.cs @@ -22,7 +22,7 @@ public GetCommand() : base("get", "Retrieves the existing draft from the store submission.") { var module = new Option( - aliases: new string[] { "--module", "-m" }, + aliases: ["--module", "-m"], description: "Select which module you want to retrieve ('availability', 'listings' or 'properties')."); AddArgument(SubmissionCommand.ProductIdArgument); @@ -30,23 +30,16 @@ public GetCommand() AddOption(SubmissionCommand.LanguageOption); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string Module { get; set; } = null!; public string Language { get; set; } = null!; public string ProductId { get; set; } = null!; - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/Submission/GetListingAssetsCommand.cs b/MSStore.CLI/Commands/Submission/GetListingAssetsCommand.cs index b6164cf..bc6bb29 100644 --- a/MSStore.CLI/Commands/Submission/GetListingAssetsCommand.cs +++ b/MSStore.CLI/Commands/Submission/GetListingAssetsCommand.cs @@ -25,22 +25,15 @@ public GetListingAssetsCommand() AddOption(SubmissionCommand.LanguageOption); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string Language { get; set; } = null!; public string ProductId { get; set; } = null!; - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/Submission/PollCommand.cs b/MSStore.CLI/Commands/Submission/PollCommand.cs index 934c97b..b0d4a23 100644 --- a/MSStore.CLI/Commands/Submission/PollCommand.cs +++ b/MSStore.CLI/Commands/Submission/PollCommand.cs @@ -25,23 +25,15 @@ public PollCommand() AddArgument(SubmissionCommand.ProductIdArgument); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient, IBrowserLauncher browserLauncher) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; - private readonly IBrowserLauncher _browserLauncher; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); + private readonly IBrowserLauncher _browserLauncher = browserLauncher ?? throw new ArgumentNullException(nameof(browserLauncher)); public string ProductId { get; set; } = null!; - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient, IBrowserLauncher browserLauncher) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - _browserLauncher = browserLauncher ?? throw new ArgumentNullException(nameof(browserLauncher)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/Submission/PublishCommand.cs b/MSStore.CLI/Commands/Submission/PublishCommand.cs index b0ba9d9..42102e7 100644 --- a/MSStore.CLI/Commands/Submission/PublishCommand.cs +++ b/MSStore.CLI/Commands/Submission/PublishCommand.cs @@ -22,21 +22,14 @@ public PublishCommand() AddArgument(SubmissionCommand.ProductIdArgument); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string ProductId { get; set; } = null!; - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/Submission/Rollout/FinalizeCommand.cs b/MSStore.CLI/Commands/Submission/Rollout/FinalizeCommand.cs index 34e9f65..3311705 100644 --- a/MSStore.CLI/Commands/Submission/Rollout/FinalizeCommand.cs +++ b/MSStore.CLI/Commands/Submission/Rollout/FinalizeCommand.cs @@ -25,22 +25,15 @@ public FinalizeCommand() AddOption(GetCommand.SubmissionIdOption); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string ProductId { get; set; } = null!; public string? SubmissionId { get; set; } - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/Submission/Rollout/GetCommand.cs b/MSStore.CLI/Commands/Submission/Rollout/GetCommand.cs index 95aa967..420c85b 100644 --- a/MSStore.CLI/Commands/Submission/Rollout/GetCommand.cs +++ b/MSStore.CLI/Commands/Submission/Rollout/GetCommand.cs @@ -23,7 +23,7 @@ internal class GetCommand : Command static GetCommand() { SubmissionIdOption = new Option( - aliases: new string[] { "--submissionId", "-s" }, + aliases: ["--submissionId", "-s"], description: "The submission ID."); } @@ -34,22 +34,15 @@ public GetCommand() AddOption(SubmissionIdOption); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string ProductId { get; set; } = null!; public string? SubmissionId { get; set; } - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/Submission/Rollout/HaltCommand.cs b/MSStore.CLI/Commands/Submission/Rollout/HaltCommand.cs index 8486752..dbc3796 100644 --- a/MSStore.CLI/Commands/Submission/Rollout/HaltCommand.cs +++ b/MSStore.CLI/Commands/Submission/Rollout/HaltCommand.cs @@ -25,22 +25,15 @@ public HaltCommand() AddOption(GetCommand.SubmissionIdOption); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string ProductId { get; set; } = null!; public string? SubmissionId { get; set; } - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/Submission/Rollout/UpdateCommand.cs b/MSStore.CLI/Commands/Submission/Rollout/UpdateCommand.cs index adc8a65..e64f7da 100644 --- a/MSStore.CLI/Commands/Submission/Rollout/UpdateCommand.cs +++ b/MSStore.CLI/Commands/Submission/Rollout/UpdateCommand.cs @@ -30,23 +30,16 @@ public UpdateCommand() AddArgument(percentage); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string ProductId { get; set; } = null!; public string? SubmissionId { get; set; } public float Percentage { get; set; } - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/Submission/StatusCommand.cs b/MSStore.CLI/Commands/Submission/StatusCommand.cs index 3d4f744..46b290d 100644 --- a/MSStore.CLI/Commands/Submission/StatusCommand.cs +++ b/MSStore.CLI/Commands/Submission/StatusCommand.cs @@ -24,21 +24,14 @@ public StatusCommand() AddArgument(SubmissionCommand.ProductIdArgument); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string ProductId { get; set; } = null!; - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/Submission/UpdateCommand.cs b/MSStore.CLI/Commands/Submission/UpdateCommand.cs index 8bced47..15f9eb8 100644 --- a/MSStore.CLI/Commands/Submission/UpdateCommand.cs +++ b/MSStore.CLI/Commands/Submission/UpdateCommand.cs @@ -32,11 +32,11 @@ public UpdateCommand() AddOption(SubmissionCommand.SkipInitialPolling); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string Product { get; set; } = null!; public bool SkipInitialPolling { get; set; } @@ -111,13 +111,6 @@ public UpdateCommand() }); } - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/Submission/UpdateMetadataCommand.cs b/MSStore.CLI/Commands/Submission/UpdateMetadataCommand.cs index fdb9de4..0114c56 100644 --- a/MSStore.CLI/Commands/Submission/UpdateMetadataCommand.cs +++ b/MSStore.CLI/Commands/Submission/UpdateMetadataCommand.cs @@ -30,23 +30,16 @@ public UpdateMetadataCommand() AddOption(SubmissionCommand.SkipInitialPolling); } - public new class Handler : ICommandHandler + public new class Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) : ICommandHandler { - private readonly ILogger _logger; - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly TelemetryClient _telemetryClient; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public string Metadata { get; set; } = null!; public bool SkipInitialPolling { get; set; } public string ProductId { get; set; } = null!; - public Handler(ILogger logger, IStoreAPIFactory storeAPIFactory, TelemetryClient telemetryClient) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } - public int Invoke(InvocationContext context) { return -1001; diff --git a/MSStore.CLI/Commands/SubmissionCommand.cs b/MSStore.CLI/Commands/SubmissionCommand.cs index e7fd71f..ef84520 100644 --- a/MSStore.CLI/Commands/SubmissionCommand.cs +++ b/MSStore.CLI/Commands/SubmissionCommand.cs @@ -15,11 +15,11 @@ internal class SubmissionCommand : Command static SubmissionCommand() { LanguageOption = new Option( - aliases: new string[] { "--language", "-l" }, + aliases: ["--language", "-l"], getDefaultValue: () => "en", description: "Select which language you want to retrieve."); SkipInitialPolling = new Option( - aliases: new string[] { "--skipInitialPolling", "-s" }, + aliases: ["--skipInitialPolling", "-s"], getDefaultValue: () => false, description: "Skip the initial polling before executing the action."); ProductIdArgument = new Argument( diff --git a/MSStore.CLI/Helpers/CustomSpectreConsoleFormatter.cs b/MSStore.CLI/Helpers/CustomSpectreConsoleFormatter.cs index d1d8444..3e10b59 100644 --- a/MSStore.CLI/Helpers/CustomSpectreConsoleFormatter.cs +++ b/MSStore.CLI/Helpers/CustomSpectreConsoleFormatter.cs @@ -15,7 +15,7 @@ namespace MSStore.CLI.Helpers internal sealed class CustomSpectreConsoleFormatter : ConsoleFormatter { private const string LoglevelPadding = ": "; - private static readonly string _messagePadding = new string(' ', GetLogLevelString(LogLevel.Information).Length + LoglevelPadding.Length); + private static readonly string _messagePadding = new(' ', GetLogLevelString(LogLevel.Information).Length + LoglevelPadding.Length); private static readonly string _newLineWithMessagePadding = Environment.NewLine + _messagePadding; internal SimpleConsoleFormatterOptions? FormatterOptions { get; set; } @@ -93,7 +93,7 @@ public override void Write(in LogEntry logEntry, IExternalScopeP textWriter.Write(timestamp); } - void WriteColoredMessage(TextWriter textWriter, string message, ConsoleColor? background, ConsoleColor? foreground) + static void WriteColoredMessage(TextWriter textWriter, string message, ConsoleColor? background, ConsoleColor? foreground) { if (background.HasValue || foreground.HasValue) { @@ -238,17 +238,11 @@ private void WriteScopeInformation(TextWriter textWriter, IExternalScopeProvider } } - private readonly struct ConsoleColors + private readonly struct ConsoleColors(ConsoleColor? foreground, ConsoleColor? background) { - public ConsoleColors(ConsoleColor? foreground, ConsoleColor? background) - { - Foreground = foreground; - Background = background; - } - - public ConsoleColor? Foreground { get; } + public ConsoleColor? Foreground { get; } = foreground; - public ConsoleColor? Background { get; } + public ConsoleColor? Background { get; } = background; } } } diff --git a/MSStore.CLI/Helpers/CustomSpectreConsoleLogger.cs b/MSStore.CLI/Helpers/CustomSpectreConsoleLogger.cs index 205cb39..eb30f9b 100644 --- a/MSStore.CLI/Helpers/CustomSpectreConsoleLogger.cs +++ b/MSStore.CLI/Helpers/CustomSpectreConsoleLogger.cs @@ -10,22 +10,14 @@ namespace MSStore.CLI.Helpers { - internal class CustomSpectreConsoleLogger : ILogger + internal class CustomSpectreConsoleLogger(string name, ConsoleFormatter formatter, IExternalScopeProvider? scopeProvider) : ILogger { - private readonly string _name; - internal ConsoleFormatter Formatter { get; set; } - internal IExternalScopeProvider? ScopeProvider { get; set; } + internal ConsoleFormatter Formatter { get; set; } = formatter; + internal IExternalScopeProvider? ScopeProvider { get; set; } = scopeProvider; [ThreadStatic] private static StringWriter? _stringWriter; - public CustomSpectreConsoleLogger(string name, ConsoleFormatter formatter, IExternalScopeProvider? scopeProvider) - { - _name = name; - Formatter = formatter; - ScopeProvider = scopeProvider; - } - public IDisposable? BeginScope(TState state) where TState : notnull { @@ -45,7 +37,7 @@ public void Log(LogLevel logLevel, EventId eventId, TState state, Except } _stringWriter ??= new StringWriter(); - LogEntry logEntry = new LogEntry(logLevel, _name, eventId, state, exception, formatter); + LogEntry logEntry = new LogEntry(logLevel, name, eventId, state, exception, formatter); Formatter.Write(in logEntry, ScopeProvider, _stringWriter); var sb = _stringWriter.GetStringBuilder(); diff --git a/MSStore.CLI/Helpers/IStorePackagedAPIExtensions.cs b/MSStore.CLI/Helpers/IStorePackagedAPIExtensions.cs index ac29031..8171201 100644 --- a/MSStore.CLI/Helpers/IStorePackagedAPIExtensions.cs +++ b/MSStore.CLI/Helpers/IStorePackagedAPIExtensions.cs @@ -788,7 +788,7 @@ private static async Task FulfillApplicationAsync(DevCenterApplication app, DevC } else { - var categories = Enum.GetNames(typeof(DevCenterApplicationCategory)) + var categories = Enum.GetNames() .Where(c => c != nameof(DevCenterApplicationCategory.NotSet)) .ToArray(); @@ -798,13 +798,13 @@ private static async Task FulfillApplicationAsync(DevCenterApplication app, DevC 20, ct: ct); - submission.ApplicationCategory = (DevCenterApplicationCategory)Enum.Parse(typeof(DevCenterApplicationCategory), categoryString); + submission.ApplicationCategory = Enum.Parse(categoryString); } } if (submission.Listings.IsNullOrEmpty()) { - submission.Listings = new Dictionary(); + submission.Listings = []; int listingCount; if (environmentInformationService.IsRunningOnCI) @@ -863,7 +863,7 @@ private static async Task FulfillApplicationAsync(DevCenterApplication app, DevC if (listing.BaseListing.Images.IsNullOrEmpty()) { - listing.BaseListing.Images = new List(); + listing.BaseListing.Images = []; foreach (var image in submissionData.Images) { @@ -882,7 +882,7 @@ private static async Task FulfillApplicationAsync(DevCenterApplication app, DevC if (submission.AllowTargetFutureDeviceFamilies == null) { - submission.AllowTargetFutureDeviceFamilies = new Dictionary(); + submission.AllowTargetFutureDeviceFamilies = []; } void UpdateKeyIfNotSet(string key, bool value) diff --git a/MSStore.CLI/Helpers/NativeMethods.cs b/MSStore.CLI/Helpers/NativeMethods.cs index 985c854..4c58e83 100644 --- a/MSStore.CLI/Helpers/NativeMethods.cs +++ b/MSStore.CLI/Helpers/NativeMethods.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#if WINDOWS using System; using System.Runtime.InteropServices; @@ -30,5 +29,4 @@ internal static IntPtr GetConsoleOrTerminalWindow() return handle; } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/MSStore.CLI/Helpers/ProjectImagesHelper.cs b/MSStore.CLI/Helpers/ProjectImagesHelper.cs index e24f7fa..f2479f7 100644 --- a/MSStore.CLI/Helpers/ProjectImagesHelper.cs +++ b/MSStore.CLI/Helpers/ProjectImagesHelper.cs @@ -24,7 +24,7 @@ internal static List GetDefaultImagesUsedByApp(List appImagesFil defaultImagesFileList.AddRange(projectSpecificDefaultImagesFileList); } - List failedImages = new List(); + List failedImages = []; List defaultImages = GetHashesForImageFiles(defaultImagesFileList, imageConverter); List appImages = GetHashesForImageFiles(appImagesFileList, imageConverter); @@ -71,12 +71,12 @@ private static string[] GetWindowsSdkDefaultImages(ILogger logger) "This may be because the Windows SDK is not installed. " + "We won't be able to check for default images.", defaultImagesDir); - return Array.Empty(); + return []; } private static List GetHashesForImageFiles(List imageFiles, IImageConverter imageConverter) { - List hashes = new List(); + List hashes = []; foreach (string image in imageFiles) { diff --git a/MSStore.CLI/MSStore.CLI.csproj b/MSStore.CLI/MSStore.CLI.csproj index 93c2d18..48e3ae5 100644 --- a/MSStore.CLI/MSStore.CLI.csproj +++ b/MSStore.CLI/MSStore.CLI.csproj @@ -2,13 +2,14 @@ Exe - net8.0;net8.0-windows10.0.17763.0 - net8.0 + net9.0;net9.0-windows10.0.17763.0 + net9.0 false msstore true - - true + true + + $(NoWarn);CA2101 @@ -17,10 +18,11 @@ true - + + - + @@ -29,28 +31,28 @@ - + - - - - - - - - + + + + + + + + - - + + - - - + + + diff --git a/MSStore.CLI/MicrosoftStoreCLI.cs b/MSStore.CLI/MicrosoftStoreCLI.cs index b05c5f7..1eff826 100644 --- a/MSStore.CLI/MicrosoftStoreCLI.cs +++ b/MSStore.CLI/MicrosoftStoreCLI.cs @@ -34,7 +34,7 @@ public MicrosoftStoreCLI() : base(description: "CLI tool to automate Microsoft Store Developer tasks.") { VerboseOption = new Option( - aliases: new string[] { "--verbose", "-v" }, + aliases: ["--verbose", "-v"], getDefaultValue: () => false, description: "Verbose output"); AddGlobalOption(VerboseOption); @@ -54,18 +54,11 @@ public MicrosoftStoreCLI() }); } - public new class Handler : ICommandHandler + public new class Handler(IConfigurationManager configurationManager, ICLIConfigurator cliConfigurator, TelemetryClient telemetryClient) : ICommandHandler { - private readonly IConfigurationManager _configurationManager; - private readonly ICLIConfigurator _cliConfigurator; - private readonly TelemetryClient _telemetryClient; - - public Handler(IConfigurationManager configurationManager, ICLIConfigurator cliConfigurator, TelemetryClient telemetryClient) - { - _configurationManager = configurationManager ?? throw new ArgumentNullException(nameof(configurationManager)); - _cliConfigurator = cliConfigurator ?? throw new ArgumentNullException(nameof(cliConfigurator)); - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } + private readonly IConfigurationManager _configurationManager = configurationManager ?? throw new ArgumentNullException(nameof(configurationManager)); + private readonly ICLIConfigurator _cliConfigurator = cliConfigurator ?? throw new ArgumentNullException(nameof(cliConfigurator)); + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public int Invoke(InvocationContext context) { diff --git a/MSStore.CLI/Program.cs b/MSStore.CLI/Program.cs index 385f2b5..58cc39b 100644 --- a/MSStore.CLI/Program.cs +++ b/MSStore.CLI/Program.cs @@ -266,7 +266,7 @@ void AddMSCorrelationId(HttpRequestHeaders defaultRequestHeaders) } } - args = argList.ToArray(); + args = [.. argList]; var result = await parser.InvokeAsync(args); @@ -278,14 +278,14 @@ void AddMSCorrelationId(HttpRequestHeaders defaultRequestHeaders) private static async Task CreateTelemetryClientAsync(ConfigurationManager telemetryConfigurationManager, TelemetryConfigurations telemetryConfigurations) { var changed = false; - if (telemetryConfigurations.TelemetryEnabled.HasValue == false) + if (!telemetryConfigurations.TelemetryEnabled.HasValue) { telemetryConfigurations.TelemetryEnabled = true; changed = true; } if (string.IsNullOrEmpty(telemetryConfigurations.TelemetryGuid) - || telemetryConfigurations.TelemetryGuidDateTime.HasValue == false + || !telemetryConfigurations.TelemetryGuidDateTime.HasValue || (DateTime.Now - telemetryConfigurations.TelemetryGuidDateTime) >= TimeSpan.FromHours(24)) { telemetryConfigurations.TelemetryGuid = Guid.NewGuid().ToString(); diff --git a/MSStore.CLI/ProjectConfigurators/ElectronProjectConfigurator.cs b/MSStore.CLI/ProjectConfigurators/ElectronProjectConfigurator.cs index c0fe769..e55e05a 100644 --- a/MSStore.CLI/ProjectConfigurators/ElectronProjectConfigurator.cs +++ b/MSStore.CLI/ProjectConfigurators/ElectronProjectConfigurator.cs @@ -19,23 +19,17 @@ namespace MSStore.CLI.ProjectConfigurators { - internal class ElectronProjectConfigurator : NodeBaseProjectConfigurator + internal class ElectronProjectConfigurator(IExternalCommandExecutor externalCommandExecutor, IElectronManifestManager electronManifestManager, IBrowserLauncher browserLauncher, IConsoleReader consoleReader, IZipFileManager zipFileManager, IFileDownloader fileDownloader, IAzureBlobManager azureBlobManager, IEnvironmentInformationService environmentInformationService, ILogger logger) : NodeBaseProjectConfigurator(externalCommandExecutor, browserLauncher, consoleReader, zipFileManager, fileDownloader, azureBlobManager, environmentInformationService, logger) { - private readonly IElectronManifestManager _electronManifestManager; + private readonly IElectronManifestManager _electronManifestManager = electronManifestManager ?? throw new ArgumentNullException(nameof(electronManifestManager)); private ElectronManifest? _electronManifest; - public ElectronProjectConfigurator(IExternalCommandExecutor externalCommandExecutor, IElectronManifestManager electronManifestManager, IBrowserLauncher browserLauncher, IConsoleReader consoleReader, IZipFileManager zipFileManager, IFileDownloader fileDownloader, IAzureBlobManager azureBlobManager, IEnvironmentInformationService environmentInformationService, ILogger logger) - : base(externalCommandExecutor, browserLauncher, consoleReader, zipFileManager, fileDownloader, azureBlobManager, environmentInformationService, logger) - { - _electronManifestManager = electronManifestManager ?? throw new ArgumentNullException(nameof(electronManifestManager)); - } - public override string ToString() => "Electron"; - public override string[] PackageFilesExtensionInclude => new[] - { + public override string[] PackageFilesExtensionInclude => + [ ".appx" - }; + ]; public override string[]? PackageFilesExtensionExclude { get; } public override SearchOption PackageFilesSearchOption { get; } = SearchOption.TopDirectoryOnly; public override PublishFileSearchFilterStrategy PublishFileSearchFilterStrategy { get; } = PublishFileSearchFilterStrategy.All; @@ -56,18 +50,18 @@ public string DefaultBuildResources } } - public override IEnumerable? DefaultBuildArchs => new[] - { + public override IEnumerable? DefaultBuildArchs => + [ BuildArch.X64, BuildArch.Arm64 - }; + ]; public override bool PackageOnlyOnWindows => true; - public override AllowTargetFutureDeviceFamily[] AllowTargetFutureDeviceFamilies { get; } = new[] - { + public override AllowTargetFutureDeviceFamily[] AllowTargetFutureDeviceFamilies { get; } = + [ AllowTargetFutureDeviceFamily.Desktop - }; + ]; public override async Task CanConfigureAsync(string pathOrUrl, CancellationToken ct) { @@ -359,11 +353,10 @@ internal static async Task UpdateManifestAsync(FileInfo electr var cleanedStdOut = System.Text.RegularExpressions.Regex.Replace(result.StdOut, @"\e([^\[\]]|\[.*?[a-zA-Z]|\].*?\a)", string.Empty); var msixLine = cleanedStdOut.Split( - new string[] - { + [ "\n", Environment.NewLine - }, StringSplitOptions.None).LastOrDefault(line => line.Contains("target=AppX")); + ], StringSplitOptions.None).LastOrDefault(line => line.Contains("target=AppX")); int index; var search = "file="; if (msixLine == null || (index = msixLine.IndexOf(search, StringComparison.OrdinalIgnoreCase)) == -1) @@ -371,7 +364,7 @@ internal static async Task UpdateManifestAsync(FileInfo electr throw new MSStoreException("Failed to find the path to the packaged msix file."); } - var msixPath = msixLine.Substring(index + search.Length).Trim(); + var msixPath = msixLine[(index + search.Length)..].Trim(); FileInfo? msixFile = null; if (msixPath != null) diff --git a/MSStore.CLI/ProjectConfigurators/FileProjectConfigurator.cs b/MSStore.CLI/ProjectConfigurators/FileProjectConfigurator.cs index 52c4c12..99b54ac 100644 --- a/MSStore.CLI/ProjectConfigurators/FileProjectConfigurator.cs +++ b/MSStore.CLI/ProjectConfigurators/FileProjectConfigurator.cs @@ -16,30 +16,19 @@ namespace MSStore.CLI.ProjectConfigurators { - internal abstract class FileProjectConfigurator : IProjectConfigurator, IProjectPackager, IProjectPublisher + internal abstract class FileProjectConfigurator(IBrowserLauncher browserLauncher, IConsoleReader consoleReader, IZipFileManager zipFileManager, IFileDownloader fileDownloader, IAzureBlobManager azureBlobManager, IEnvironmentInformationService environmentInformationService, ILogger logger) : IProjectConfigurator, IProjectPackager, IProjectPublisher { - private readonly IBrowserLauncher _browserLauncher; - private readonly IConsoleReader _consoleReader; - private readonly IZipFileManager _zipFileManager; - private readonly IFileDownloader _fileDownloader; - private readonly IAzureBlobManager _azureBlobManager; - private readonly IEnvironmentInformationService _environmentInformationService; + private readonly IBrowserLauncher _browserLauncher = browserLauncher ?? throw new ArgumentNullException(nameof(browserLauncher)); + private readonly IConsoleReader _consoleReader = consoleReader ?? throw new ArgumentNullException(nameof(consoleReader)); + private readonly IZipFileManager _zipFileManager = zipFileManager ?? throw new ArgumentNullException(nameof(zipFileManager)); + private readonly IFileDownloader _fileDownloader = fileDownloader ?? throw new ArgumentNullException(nameof(fileDownloader)); + private readonly IAzureBlobManager _azureBlobManager = azureBlobManager ?? throw new ArgumentNullException(nameof(azureBlobManager)); + private readonly IEnvironmentInformationService _environmentInformationService = environmentInformationService ?? throw new ArgumentNullException(nameof(environmentInformationService)); - private readonly ILogger _logger; + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); protected ILogger Logger => _logger; - public FileProjectConfigurator(IBrowserLauncher browserLauncher, IConsoleReader consoleReader, IZipFileManager zipFileManager, IFileDownloader fileDownloader, IAzureBlobManager azureBlobManager, IEnvironmentInformationService environmentInformationService, ILogger logger) - { - _browserLauncher = browserLauncher ?? throw new ArgumentNullException(nameof(browserLauncher)); - _consoleReader = consoleReader ?? throw new ArgumentNullException(nameof(consoleReader)); - _zipFileManager = zipFileManager ?? throw new ArgumentNullException(nameof(zipFileManager)); - _fileDownloader = fileDownloader ?? throw new ArgumentNullException(nameof(fileDownloader)); - _azureBlobManager = azureBlobManager ?? throw new ArgumentNullException(nameof(azureBlobManager)); - _environmentInformationService = environmentInformationService ?? throw new ArgumentNullException(nameof(environmentInformationService)); - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - } - public abstract string[] SupportedProjectPattern { get; } public abstract string[] PackageFilesExtensionInclude { get; } diff --git a/MSStore.CLI/ProjectConfigurators/FlutterProjectConfigurator.cs b/MSStore.CLI/ProjectConfigurators/FlutterProjectConfigurator.cs index e7f11ad..86ae099 100644 --- a/MSStore.CLI/ProjectConfigurators/FlutterProjectConfigurator.cs +++ b/MSStore.CLI/ProjectConfigurators/FlutterProjectConfigurator.cs @@ -18,36 +18,29 @@ namespace MSStore.CLI.ProjectConfigurators { - internal class FlutterProjectConfigurator : FileProjectConfigurator + internal class FlutterProjectConfigurator(IExternalCommandExecutor externalCommandExecutor, IImageConverter imageConverter, IBrowserLauncher browserLauncher, IConsoleReader consoleReader, IZipFileManager zipFileManager, IFileDownloader fileDownloader, IAzureBlobManager azureBlobManager, IEnvironmentInformationService environmentInformationService, ILogger logger) : FileProjectConfigurator(browserLauncher, consoleReader, zipFileManager, fileDownloader, azureBlobManager, environmentInformationService, logger) { - private readonly IExternalCommandExecutor _externalCommandExecutor; - private readonly IImageConverter _imageConverter; - - public FlutterProjectConfigurator(IExternalCommandExecutor externalCommandExecutor, IImageConverter imageConverter, IBrowserLauncher browserLauncher, IConsoleReader consoleReader, IZipFileManager zipFileManager, IFileDownloader fileDownloader, IAzureBlobManager azureBlobManager, IEnvironmentInformationService environmentInformationService, ILogger logger) - : base(browserLauncher, consoleReader, zipFileManager, fileDownloader, azureBlobManager, environmentInformationService, logger) - { - _externalCommandExecutor = externalCommandExecutor ?? throw new ArgumentNullException(nameof(externalCommandExecutor)); - _imageConverter = imageConverter ?? throw new ArgumentNullException(nameof(imageConverter)); - } + private readonly IExternalCommandExecutor _externalCommandExecutor = externalCommandExecutor ?? throw new ArgumentNullException(nameof(externalCommandExecutor)); + private readonly IImageConverter _imageConverter = imageConverter ?? throw new ArgumentNullException(nameof(imageConverter)); public override string ToString() => "Flutter"; - public override string[] SupportedProjectPattern { get; } = new[] { "pubspec.yaml" }; + public override string[] SupportedProjectPattern { get; } = ["pubspec.yaml"]; - public override string[] PackageFilesExtensionInclude => new[] { ".msix" }; + public override string[] PackageFilesExtensionInclude => [".msix"]; public override string[]? PackageFilesExtensionExclude { get; } public override SearchOption PackageFilesSearchOption { get; } = SearchOption.AllDirectories; public override PublishFileSearchFilterStrategy PublishFileSearchFilterStrategy { get; } = PublishFileSearchFilterStrategy.All; public override string OutputSubdirectory { get; } = Path.Combine("build", "windows", "MSStore.CLI"); public override string DefaultInputSubdirectory { get; } = Path.Combine("build", "windows"); - public override IEnumerable? DefaultBuildArchs => new[] { BuildArch.X64 }; + public override IEnumerable? DefaultBuildArchs => [BuildArch.X64]; public override bool PackageOnlyOnWindows => true; - public override AllowTargetFutureDeviceFamily[] AllowTargetFutureDeviceFamilies { get; } = new[] - { + public override AllowTargetFutureDeviceFamily[] AllowTargetFutureDeviceFamilies { get; } = + [ AllowTargetFutureDeviceFamily.Desktop - }; + ]; public override async Task<(int returnCode, DirectoryInfo? outputDirectory)> ConfigureAsync(string pathOrUrl, DirectoryInfo? output, string publisherDisplayName, DevCenterApplication app, Version? version, IStorePackagedAPI storePackagedAPI, CancellationToken ct) { @@ -201,7 +194,7 @@ void TryAddOrUpdate(string key, string? value) public override async Task?> GetDefaultImagesAsync(string pathOrUrl, CancellationToken ct) { - List images = new List(); + List images = []; var flutterDir = await GetFlutterDirAsync(_externalCommandExecutor, ct); if (flutterDir == null) @@ -395,7 +388,7 @@ private async Task InstallMsixDependencyAsync(DirectoryInfo projectRootPath, Can } }); - if (msixInstalled == true) + if (msixInstalled) { return; } @@ -518,14 +511,14 @@ private async Task RunPubGet(DirectoryInfo projectRootPath, CancellationTo var cleanedStdOut = System.Text.RegularExpressions.Regex.Replace(result.StdOut, @"\e([^\[\]]|\[.*?[a-zA-Z]|\].*?\a)", string.Empty); - var msixLine = cleanedStdOut.Split(new string[] { "\n", Environment.NewLine }, StringSplitOptions.None).LastOrDefault(line => line.Contains("msix created:")); + var msixLine = cleanedStdOut.Split(["\n", Environment.NewLine], StringSplitOptions.None).LastOrDefault(line => line.Contains("msix created:")); int index; if (msixLine == null || (index = msixLine.IndexOf(": ", StringComparison.OrdinalIgnoreCase)) == -1) { throw new MSStoreException("Failed to find the path to the packaged msix file."); } - var msixPath = msixLine.Substring(index + 1).Trim(); + var msixPath = msixLine[(index + 1)..].Trim(); if (Logger.IsEnabled(LogLevel.Information)) { @@ -596,7 +589,7 @@ private async Task RunPubGet(DirectoryInfo projectRootPath, CancellationTo { if (commentStartIndex > indexOfProperty) { - propertyValue = line.Substring(0, commentStartIndex).Split(':').LastOrDefault()?.Trim(); + propertyValue = line[..commentStartIndex].Split(':').LastOrDefault()?.Trim(); } else { diff --git a/MSStore.CLI/ProjectConfigurators/MSIXProjectPublisher.cs b/MSStore.CLI/ProjectConfigurators/MSIXProjectPublisher.cs index 156ea21..27b1f9b 100644 --- a/MSStore.CLI/ProjectConfigurators/MSIXProjectPublisher.cs +++ b/MSStore.CLI/ProjectConfigurators/MSIXProjectPublisher.cs @@ -16,14 +16,14 @@ namespace MSStore.CLI.ProjectConfigurators { - internal class MSIXProjectPublisher : IProjectPublisher + internal class MSIXProjectPublisher(IBrowserLauncher browserLauncher, IConsoleReader consoleReader, IZipFileManager zipFileManager, IFileDownloader fileDownloader, IAzureBlobManager azureBlobManager, IEnvironmentInformationService environmentInformationService, IAppXManifestManager appXManifestManager, ILogger logger) : IProjectPublisher { - public string[] PackageFilesExtensionInclude => new[] - { + public string[] PackageFilesExtensionInclude => + [ ".msix", ".msixbundle", ".msixupload" - }; + ]; public override string ToString() => "MSIX"; @@ -31,34 +31,22 @@ internal class MSIXProjectPublisher : IProjectPublisher public SearchOption PackageFilesSearchOption { get; } = SearchOption.TopDirectoryOnly; - public AllowTargetFutureDeviceFamily[] AllowTargetFutureDeviceFamilies { get; } = new[] - { + public AllowTargetFutureDeviceFamily[] AllowTargetFutureDeviceFamilies { get; } = + [ AllowTargetFutureDeviceFamily.Desktop - }; - - private readonly IBrowserLauncher _browserLauncher; - private readonly IConsoleReader _consoleReader; - private readonly IZipFileManager _zipFileManager; - private readonly IFileDownloader _fileDownloader; - private readonly IAzureBlobManager _azureBlobManager; - private readonly IEnvironmentInformationService _environmentInformationService; - private readonly IAppXManifestManager _appXManifestManager; - private readonly ILogger _logger; + ]; + + private readonly IBrowserLauncher _browserLauncher = browserLauncher ?? throw new ArgumentNullException(nameof(browserLauncher)); + private readonly IConsoleReader _consoleReader = consoleReader ?? throw new ArgumentNullException(nameof(consoleReader)); + private readonly IZipFileManager _zipFileManager = zipFileManager ?? throw new ArgumentNullException(nameof(zipFileManager)); + private readonly IFileDownloader _fileDownloader = fileDownloader ?? throw new ArgumentNullException(nameof(fileDownloader)); + private readonly IAzureBlobManager _azureBlobManager = azureBlobManager ?? throw new ArgumentNullException(nameof(azureBlobManager)); + private readonly IEnvironmentInformationService _environmentInformationService = environmentInformationService ?? throw new ArgumentNullException(nameof(environmentInformationService)); + private readonly IAppXManifestManager _appXManifestManager = appXManifestManager ?? throw new ArgumentNullException(nameof(appXManifestManager)); + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); private DirectoryInfo? _tempExtractDir; private DevCenterApplication? _app; - public MSIXProjectPublisher(IBrowserLauncher browserLauncher, IConsoleReader consoleReader, IZipFileManager zipFileManager, IFileDownloader fileDownloader, IAzureBlobManager azureBlobManager, IEnvironmentInformationService environmentInformationService, IAppXManifestManager appXManifestManager, ILogger logger) - { - _browserLauncher = browserLauncher ?? throw new ArgumentNullException(nameof(browserLauncher)); - _consoleReader = consoleReader ?? throw new ArgumentNullException(nameof(consoleReader)); - _zipFileManager = zipFileManager ?? throw new ArgumentNullException(nameof(zipFileManager)); - _fileDownloader = fileDownloader ?? throw new ArgumentNullException(nameof(fileDownloader)); - _azureBlobManager = azureBlobManager ?? throw new ArgumentNullException(nameof(azureBlobManager)); - _environmentInformationService = environmentInformationService ?? throw new ArgumentNullException(nameof(environmentInformationService)); - _appXManifestManager = appXManifestManager ?? throw new ArgumentNullException(nameof(appXManifestManager)); - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - } - public Task CanPublishAsync(string pathOrUrl, CancellationToken ct) { if (string.IsNullOrEmpty(pathOrUrl)) diff --git a/MSStore.CLI/ProjectConfigurators/MauiProjectConfigurator.cs b/MSStore.CLI/ProjectConfigurators/MauiProjectConfigurator.cs index c461457..b7efbbd 100644 --- a/MSStore.CLI/ProjectConfigurators/MauiProjectConfigurator.cs +++ b/MSStore.CLI/ProjectConfigurators/MauiProjectConfigurator.cs @@ -18,41 +18,33 @@ namespace MSStore.CLI.ProjectConfigurators { - internal class MauiProjectConfigurator : FileProjectConfigurator + internal class MauiProjectConfigurator(IBrowserLauncher browserLauncher, IConsoleReader consoleReader, IZipFileManager zipFileManager, IFileDownloader fileDownloader, IAzureBlobManager azureBlobManager, INuGetPackageManager nuGetPackageManager, IExternalCommandExecutor externalCommandExecutor, IAppXManifestManager appXManifestManager, IEnvironmentInformationService environmentInformationService, ILogger logger) : FileProjectConfigurator(browserLauncher, consoleReader, zipFileManager, fileDownloader, azureBlobManager, environmentInformationService, logger) { - private readonly INuGetPackageManager _nuGetPackageManager; - private readonly IExternalCommandExecutor _externalCommandExecutor; - private readonly IAppXManifestManager _appXManifestManager; - - public MauiProjectConfigurator(IBrowserLauncher browserLauncher, IConsoleReader consoleReader, IZipFileManager zipFileManager, IFileDownloader fileDownloader, IAzureBlobManager azureBlobManager, INuGetPackageManager nuGetPackageManager, IExternalCommandExecutor externalCommandExecutor, IAppXManifestManager appXManifestManager, IEnvironmentInformationService environmentInformationService, ILogger logger) - : base(browserLauncher, consoleReader, zipFileManager, fileDownloader, azureBlobManager, environmentInformationService, logger) - { - _nuGetPackageManager = nuGetPackageManager ?? throw new ArgumentNullException(nameof(nuGetPackageManager)); - _externalCommandExecutor = externalCommandExecutor ?? throw new ArgumentNullException(nameof(externalCommandExecutor)); - _appXManifestManager = appXManifestManager ?? throw new ArgumentNullException(nameof(appXManifestManager)); - } + private readonly INuGetPackageManager _nuGetPackageManager = nuGetPackageManager ?? throw new ArgumentNullException(nameof(nuGetPackageManager)); + private readonly IExternalCommandExecutor _externalCommandExecutor = externalCommandExecutor ?? throw new ArgumentNullException(nameof(externalCommandExecutor)); + private readonly IAppXManifestManager _appXManifestManager = appXManifestManager ?? throw new ArgumentNullException(nameof(appXManifestManager)); public override string ToString() => "Maui"; - public override string[] SupportedProjectPattern => new[] { "*.csproj" }; + public override string[] SupportedProjectPattern => ["*.csproj"]; - public override string[] PackageFilesExtensionInclude => new[] { ".msix" }; + public override string[] PackageFilesExtensionInclude => [".msix"]; public override string[]? PackageFilesExtensionExclude { get; } public override SearchOption PackageFilesSearchOption { get; } = SearchOption.AllDirectories; public override PublishFileSearchFilterStrategy PublishFileSearchFilterStrategy { get; } = PublishFileSearchFilterStrategy.OneLevelDown; public override string OutputSubdirectory { get; } = Path.Combine("obj", "MSStore.CLI"); public override string DefaultInputSubdirectory { get; } = "AppPackages"; - public override IEnumerable? DefaultBuildArchs => new[] { BuildArch.X64 }; + public override IEnumerable? DefaultBuildArchs => [BuildArch.X64]; public override bool PackageOnlyOnWindows => true; - public override AllowTargetFutureDeviceFamily[] AllowTargetFutureDeviceFamilies { get; } = new[] - { + public override AllowTargetFutureDeviceFamily[] AllowTargetFutureDeviceFamilies { get; } = + [ AllowTargetFutureDeviceFamily.Desktop, AllowTargetFutureDeviceFamily.Mobile, AllowTargetFutureDeviceFamily.Holographic - }; + ]; public override async Task CanConfigureAsync(string pathOrUrl, CancellationToken ct) { @@ -167,7 +159,7 @@ internal static void UpdateCSProj(FileInfo fileInfo, DevCenterApplication app) return Task.FromResult?>(null); } - private Dictionary _nugetRestoreExecuted = new Dictionary(); + private Dictionary _nugetRestoreExecuted = []; private async Task RestorePackagesAsync(string workingDirectory, CancellationToken ct) { if (_nugetRestoreExecuted.TryGetValue(workingDirectory, out var value) && value) diff --git a/MSStore.CLI/ProjectConfigurators/NodeBaseProjectConfigurator.cs b/MSStore.CLI/ProjectConfigurators/NodeBaseProjectConfigurator.cs index 0db7c86..5cca1a6 100644 --- a/MSStore.CLI/ProjectConfigurators/NodeBaseProjectConfigurator.cs +++ b/MSStore.CLI/ProjectConfigurators/NodeBaseProjectConfigurator.cs @@ -13,24 +13,18 @@ namespace MSStore.CLI.ProjectConfigurators { - internal abstract class NodeBaseProjectConfigurator : FileProjectConfigurator + internal abstract class NodeBaseProjectConfigurator(IExternalCommandExecutor externalCommandExecutor, IBrowserLauncher browserLauncher, IConsoleReader consoleReader, IZipFileManager zipFileManager, IFileDownloader fileDownloader, IAzureBlobManager azureBlobManager, IEnvironmentInformationService environmentInformationService, ILogger logger) : FileProjectConfigurator(browserLauncher, consoleReader, zipFileManager, fileDownloader, azureBlobManager, environmentInformationService, logger) { - public override string[] SupportedProjectPattern { get; } = new[] { "package.json" }; + public override string[] SupportedProjectPattern { get; } = ["package.json"]; - protected IExternalCommandExecutor ExternalCommandExecutor { get; } - - protected NodeBaseProjectConfigurator(IExternalCommandExecutor externalCommandExecutor, IBrowserLauncher browserLauncher, IConsoleReader consoleReader, IZipFileManager zipFileManager, IFileDownloader fileDownloader, IAzureBlobManager azureBlobManager, IEnvironmentInformationService environmentInformationService, ILogger logger) - : base(browserLauncher, consoleReader, zipFileManager, fileDownloader, azureBlobManager, environmentInformationService, logger) - { - ExternalCommandExecutor = externalCommandExecutor ?? throw new ArgumentNullException(nameof(externalCommandExecutor)); - } + protected IExternalCommandExecutor ExternalCommandExecutor { get; } = externalCommandExecutor ?? throw new ArgumentNullException(nameof(externalCommandExecutor)); protected static bool IsYarn(DirectoryInfo projectRootPath) { return projectRootPath.GetFiles("yarn.lock", SearchOption.TopDirectoryOnly).Length != 0; } - private static Dictionary _npmInstallExecuted = new Dictionary(); + private static Dictionary _npmInstallExecuted = []; protected async Task RunNpmInstallAsync(DirectoryInfo projectRootPath, CancellationToken ct) { if (_npmInstallExecuted.TryGetValue(projectRootPath.FullName, out var value) && value) @@ -63,7 +57,7 @@ protected async Task RunNpmInstallAsync(DirectoryInfo projectRootPath, Can }); } - private static Dictionary _yarnInstallExecuted = new Dictionary(); + private static Dictionary _yarnInstallExecuted = []; protected async Task RunYarnInstallAsync(DirectoryInfo projectRootPath, CancellationToken ct) { if (_yarnInstallExecuted.TryGetValue(projectRootPath.FullName, out var value) && value) @@ -96,7 +90,7 @@ protected async Task RunYarnInstallAsync(DirectoryInfo projectRootPath, Ca }); } - private static Dictionary<(string rootPath, string packageName), bool> _npmListExecuted = new Dictionary<(string rootPath, string packageName), bool>(); + private static Dictionary<(string rootPath, string packageName), bool> _npmListExecuted = []; protected async Task NpmPackageExistsAsync(DirectoryInfo projectRootPath, string packageName, bool useCache = true, CancellationToken ct = default) { if (useCache && _npmListExecuted.TryGetValue((projectRootPath.FullName, packageName), out var value)) @@ -129,7 +123,7 @@ protected async Task NpmPackageExistsAsync(DirectoryInfo projectRootPath, }); } - private static Dictionary<(string rootPath, string packageName), bool> _yarnWhyExecuted = new Dictionary<(string rootPath, string packageName), bool>(); + private static Dictionary<(string rootPath, string packageName), bool> _yarnWhyExecuted = []; protected async Task YarnPackageExistsAsync(DirectoryInfo projectRootPath, string packageName, bool useCache = true, CancellationToken ct = default) { if (useCache && _yarnWhyExecuted.TryGetValue((projectRootPath.FullName, packageName), out var value)) diff --git a/MSStore.CLI/ProjectConfigurators/PWAProjectConfigurator.cs b/MSStore.CLI/ProjectConfigurators/PWAProjectConfigurator.cs index ec545c5..a9c88dd 100644 --- a/MSStore.CLI/ProjectConfigurators/PWAProjectConfigurator.cs +++ b/MSStore.CLI/ProjectConfigurators/PWAProjectConfigurator.cs @@ -19,63 +19,50 @@ namespace MSStore.CLI.ProjectConfigurators { - internal class PWAProjectConfigurator : IProjectConfigurator, IProjectPackager, IProjectPublisher + internal class PWAProjectConfigurator( + IConsoleReader consoleReader, + IBrowserLauncher browserLauncher, + IPWABuilderClient pwaBuilderClient, + IZipFileManager zipFileManager, + IAzureBlobManager azureBlobManager, + IFileDownloader fileDownloader, + IPWAAppInfoManager pwaAppInfoManager, + IEnvironmentInformationService environmentInformationService, + ILogger logger) : IProjectConfigurator, IProjectPackager, IProjectPublisher { - private readonly IConsoleReader _consoleReader; - private readonly IBrowserLauncher _browserLauncher; - private readonly IPWABuilderClient _pwaBuilderClient; - private readonly IZipFileManager _zipFileManager; - private readonly IAzureBlobManager _azureBlobManager; - private readonly IFileDownloader _fileDownloader; - private readonly IPWAAppInfoManager _pwaAppInfoManager; - private readonly IEnvironmentInformationService _environmentInformationService; - private readonly ILogger _logger; - - public PWAProjectConfigurator( - IConsoleReader consoleReader, - IBrowserLauncher browserLauncher, - IPWABuilderClient pwaBuilderClient, - IZipFileManager zipFileManager, - IAzureBlobManager azureBlobManager, - IFileDownloader fileDownloader, - IPWAAppInfoManager pwaAppInfoManager, - IEnvironmentInformationService environmentInformationService, - ILogger logger) - { - _consoleReader = consoleReader ?? throw new ArgumentNullException(nameof(consoleReader)); - _browserLauncher = browserLauncher ?? throw new ArgumentNullException(nameof(browserLauncher)); - _pwaBuilderClient = pwaBuilderClient ?? throw new ArgumentNullException(nameof(pwaBuilderClient)); - _zipFileManager = zipFileManager ?? throw new ArgumentNullException(nameof(zipFileManager)); - _azureBlobManager = azureBlobManager ?? throw new ArgumentNullException(nameof(azureBlobManager)); - _fileDownloader = fileDownloader ?? throw new ArgumentNullException(nameof(fileDownloader)); - _pwaAppInfoManager = pwaAppInfoManager ?? throw new ArgumentNullException(nameof(pwaAppInfoManager)); - _environmentInformationService = environmentInformationService ?? throw new ArgumentNullException(nameof(environmentInformationService)); - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - } + private readonly IConsoleReader _consoleReader = consoleReader ?? throw new ArgumentNullException(nameof(consoleReader)); + private readonly IBrowserLauncher _browserLauncher = browserLauncher ?? throw new ArgumentNullException(nameof(browserLauncher)); + private readonly IPWABuilderClient _pwaBuilderClient = pwaBuilderClient ?? throw new ArgumentNullException(nameof(pwaBuilderClient)); + private readonly IZipFileManager _zipFileManager = zipFileManager ?? throw new ArgumentNullException(nameof(zipFileManager)); + private readonly IAzureBlobManager _azureBlobManager = azureBlobManager ?? throw new ArgumentNullException(nameof(azureBlobManager)); + private readonly IFileDownloader _fileDownloader = fileDownloader ?? throw new ArgumentNullException(nameof(fileDownloader)); + private readonly IPWAAppInfoManager _pwaAppInfoManager = pwaAppInfoManager ?? throw new ArgumentNullException(nameof(pwaAppInfoManager)); + private readonly IEnvironmentInformationService _environmentInformationService = environmentInformationService ?? throw new ArgumentNullException(nameof(environmentInformationService)); + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); public override string ToString() => "PWA"; - public string[] PackageFilesExtensionInclude => new[] - { + public string[] PackageFilesExtensionInclude => + [ ".appxbundle", ".msixbundle", ".msix", ".appx" - }; - public string[]? PackageFilesExtensionExclude { get; } = new[] - { + ]; + public string[]? PackageFilesExtensionExclude { get; } = + [ ".sideload.msix" - }; + ]; public SearchOption PackageFilesSearchOption { get; } = SearchOption.AllDirectories; public IEnumerable? DefaultBuildArchs { get; } public bool PackageOnlyOnWindows => false; - public AllowTargetFutureDeviceFamily[] AllowTargetFutureDeviceFamilies { get; } = new[] - { + public AllowTargetFutureDeviceFamily[] AllowTargetFutureDeviceFamilies { get; } = + [ AllowTargetFutureDeviceFamily.Desktop, AllowTargetFutureDeviceFamily.Holographic - }; + ]; public Task CanConfigureAsync(string pathOrUrl, CancellationToken ct) { @@ -238,11 +225,13 @@ await _pwaBuilderClient.GenerateZipAsync( AllowSigning = true, ClassicPackage = new ClassicPackage { - Generate = true, Version = classicVersion.ToString() + Generate = true, + Version = classicVersion.ToString() }, Publisher = new Publisher { - DisplayName = publisherDisplayName, CommonName = app.PublisherName + DisplayName = publisherDisplayName, + CommonName = app.PublisherName }, ResourceLanguage = "en-us", // TODO: parametrize this }, @@ -291,7 +280,8 @@ await _pwaBuilderClient.GenerateZipAsync( await _pwaAppInfoManager.SaveAsync( new PWAAppInfo { - AppId = app.Id, Uri = uri, + AppId = app.Id, + Uri = uri, }, zipDir, ct); @@ -302,7 +292,7 @@ await _pwaAppInfoManager.SaveAsync( public Task?> GetAppImagesAsync(string pathOrUrl, CancellationToken ct) { // TODO: implement - return Task.FromResult?>(new List()); + return Task.FromResult?>([]); } public Task?> GetDefaultImagesAsync(string pathOrUrl, CancellationToken ct) diff --git a/MSStore.CLI/ProjectConfigurators/ProjectConfiguratorFactory.cs b/MSStore.CLI/ProjectConfigurators/ProjectConfiguratorFactory.cs index 7e1488d..76cdbb3 100644 --- a/MSStore.CLI/ProjectConfigurators/ProjectConfiguratorFactory.cs +++ b/MSStore.CLI/ProjectConfigurators/ProjectConfiguratorFactory.cs @@ -9,14 +9,9 @@ namespace MSStore.CLI.ProjectConfigurators { - internal class ProjectConfiguratorFactory : IProjectConfiguratorFactory + internal class ProjectConfiguratorFactory(IServiceProvider serviceProvider) : IProjectConfiguratorFactory { - private IServiceProvider _serviceProvider; - - public ProjectConfiguratorFactory(IServiceProvider serviceProvider) - { - _serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); - } + private IServiceProvider _serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); public async Task FindProjectConfiguratorAsync(string pathOrUrl, CancellationToken ct) { diff --git a/MSStore.CLI/ProjectConfigurators/ReactNativeProjectConfigurator.cs b/MSStore.CLI/ProjectConfigurators/ReactNativeProjectConfigurator.cs index 945f8f8..ab54232 100644 --- a/MSStore.CLI/ProjectConfigurators/ReactNativeProjectConfigurator.cs +++ b/MSStore.CLI/ProjectConfigurators/ReactNativeProjectConfigurator.cs @@ -16,19 +16,13 @@ namespace MSStore.CLI.ProjectConfigurators { - internal class ReactNativeProjectConfigurator : NodeBaseProjectConfigurator + internal class ReactNativeProjectConfigurator(IExternalCommandExecutor externalCommandExecutor, IBrowserLauncher browserLauncher, IConsoleReader consoleReader, IZipFileManager zipFileManager, IFileDownloader fileDownloader, IAzureBlobManager azureBlobManager, IAppXManifestManager appXManifestManager, IEnvironmentInformationService environmentInformationService, ILogger logger) : NodeBaseProjectConfigurator(externalCommandExecutor, browserLauncher, consoleReader, zipFileManager, fileDownloader, azureBlobManager, environmentInformationService, logger) { - private readonly IAppXManifestManager _appXManifestManager; - - public ReactNativeProjectConfigurator(IExternalCommandExecutor externalCommandExecutor, IBrowserLauncher browserLauncher, IConsoleReader consoleReader, IZipFileManager zipFileManager, IFileDownloader fileDownloader, IAzureBlobManager azureBlobManager, IAppXManifestManager appXManifestManager, IEnvironmentInformationService environmentInformationService, ILogger logger) - : base(externalCommandExecutor, browserLauncher, consoleReader, zipFileManager, fileDownloader, azureBlobManager, environmentInformationService, logger) - { - _appXManifestManager = appXManifestManager ?? throw new ArgumentNullException(nameof(appXManifestManager)); - } + private readonly IAppXManifestManager _appXManifestManager = appXManifestManager ?? throw new ArgumentNullException(nameof(appXManifestManager)); public override string ToString() => "React Native"; - public override string[] PackageFilesExtensionInclude => new[] { ".msixupload", ".appxupload" }; + public override string[] PackageFilesExtensionInclude => [".msixupload", ".appxupload"]; public override string[]? PackageFilesExtensionExclude { get; } public override SearchOption PackageFilesSearchOption { get; } = SearchOption.TopDirectoryOnly; public override PublishFileSearchFilterStrategy PublishFileSearchFilterStrategy { get; } = PublishFileSearchFilterStrategy.Newest; @@ -46,16 +40,16 @@ protected override DirectoryInfo GetInputDirectory(DirectoryInfo projectRootPath : windowsDirectory; } - public override IEnumerable? DefaultBuildArchs => new[] { BuildArch.X64, BuildArch.Arm64 }; + public override IEnumerable? DefaultBuildArchs => [BuildArch.X64, BuildArch.Arm64]; public override bool PackageOnlyOnWindows => true; - public override AllowTargetFutureDeviceFamily[] AllowTargetFutureDeviceFamilies { get; } = new[] - { + public override AllowTargetFutureDeviceFamily[] AllowTargetFutureDeviceFamilies { get; } = + [ AllowTargetFutureDeviceFamily.Desktop, AllowTargetFutureDeviceFamily.Mobile, AllowTargetFutureDeviceFamily.Holographic - }; + ]; public override async Task CanConfigureAsync(string pathOrUrl, CancellationToken ct) { diff --git a/MSStore.CLI/ProjectConfigurators/SubmissionImage.cs b/MSStore.CLI/ProjectConfigurators/SubmissionImage.cs index 4247fbd..fbe76f3 100644 --- a/MSStore.CLI/ProjectConfigurators/SubmissionImage.cs +++ b/MSStore.CLI/ProjectConfigurators/SubmissionImage.cs @@ -3,15 +3,9 @@ namespace MSStore.CLI.ProjectConfigurators { - internal class SubmissionImage + internal class SubmissionImage(string fileName, SubmissionImageType imageType) { - public SubmissionImage(string fileName, SubmissionImageType imageType) - { - FileName = fileName; - ImageType = imageType; - } - - public string FileName { get; private set; } - public SubmissionImageType ImageType { get; private set; } + public string FileName { get; private set; } = fileName; + public SubmissionImageType ImageType { get; private set; } = imageType; } } diff --git a/MSStore.CLI/ProjectConfigurators/UWPProjectConfigurator.cs b/MSStore.CLI/ProjectConfigurators/UWPProjectConfigurator.cs index 62df764..a11faf5 100644 --- a/MSStore.CLI/ProjectConfigurators/UWPProjectConfigurator.cs +++ b/MSStore.CLI/ProjectConfigurators/UWPProjectConfigurator.cs @@ -18,40 +18,32 @@ namespace MSStore.CLI.ProjectConfigurators { - internal class UWPProjectConfigurator : FileProjectConfigurator + internal class UWPProjectConfigurator(IExternalCommandExecutor externalCommandExecutor, IBrowserLauncher browserLauncher, IConsoleReader consoleReader, IZipFileManager zipFileManager, IFileDownloader fileDownloader, IAzureBlobManager azureBlobManager, INuGetPackageManager nuGetPackageManager, IAppXManifestManager appXManifestManager, IEnvironmentInformationService environmentInformationService, ILogger logger) : FileProjectConfigurator(browserLauncher, consoleReader, zipFileManager, fileDownloader, azureBlobManager, environmentInformationService, logger) { - protected IExternalCommandExecutor ExternalCommandExecutor { get; } - protected IAppXManifestManager AppXManifestManager { get; } - protected INuGetPackageManager NuGetPackageManager { get; } - - public UWPProjectConfigurator(IExternalCommandExecutor externalCommandExecutor, IBrowserLauncher browserLauncher, IConsoleReader consoleReader, IZipFileManager zipFileManager, IFileDownloader fileDownloader, IAzureBlobManager azureBlobManager, INuGetPackageManager nuGetPackageManager, IAppXManifestManager appXManifestManager, IEnvironmentInformationService environmentInformationService, ILogger logger) - : base(browserLauncher, consoleReader, zipFileManager, fileDownloader, azureBlobManager, environmentInformationService, logger) - { - ExternalCommandExecutor = externalCommandExecutor ?? throw new ArgumentNullException(nameof(externalCommandExecutor)); - NuGetPackageManager = nuGetPackageManager ?? throw new ArgumentNullException(nameof(nuGetPackageManager)); - AppXManifestManager = appXManifestManager ?? throw new ArgumentNullException(nameof(appXManifestManager)); - } + protected IExternalCommandExecutor ExternalCommandExecutor { get; } = externalCommandExecutor ?? throw new ArgumentNullException(nameof(externalCommandExecutor)); + protected IAppXManifestManager AppXManifestManager { get; } = appXManifestManager ?? throw new ArgumentNullException(nameof(appXManifestManager)); + protected INuGetPackageManager NuGetPackageManager { get; } = nuGetPackageManager ?? throw new ArgumentNullException(nameof(nuGetPackageManager)); public override string ToString() => "UWP"; - public override string[] SupportedProjectPattern { get; } = new[] { "Package.appxmanifest" }; + public override string[] SupportedProjectPattern { get; } = ["Package.appxmanifest"]; - public override string[] PackageFilesExtensionInclude => new[] { ".msixupload", ".appxupload" }; + public override string[] PackageFilesExtensionInclude => [".msixupload", ".appxupload"]; public override string[]? PackageFilesExtensionExclude { get; } public override SearchOption PackageFilesSearchOption { get; } = SearchOption.TopDirectoryOnly; public override PublishFileSearchFilterStrategy PublishFileSearchFilterStrategy { get; } = PublishFileSearchFilterStrategy.Newest; public override string OutputSubdirectory { get; } = Path.Combine("obj", "MSStore.CLI"); public override string DefaultInputSubdirectory { get; } = "AppPackages"; - public override IEnumerable? DefaultBuildArchs => new[] { BuildArch.X64, BuildArch.Arm64 }; + public override IEnumerable? DefaultBuildArchs => [BuildArch.X64, BuildArch.Arm64]; public override bool PackageOnlyOnWindows => true; - public override AllowTargetFutureDeviceFamily[] AllowTargetFutureDeviceFamilies { get; } = new[] - { + public override AllowTargetFutureDeviceFamily[] AllowTargetFutureDeviceFamilies { get; } = + [ AllowTargetFutureDeviceFamily.Desktop, AllowTargetFutureDeviceFamily.Mobile, AllowTargetFutureDeviceFamily.Holographic - }; + ]; public override Task<(int returnCode, DirectoryInfo? outputDirectory)> ConfigureAsync(string pathOrUrl, DirectoryInfo? output, string publisherDisplayName, DevCenterApplication app, Version? version, IStorePackagedAPI storePackagedAPI, CancellationToken ct) { @@ -245,7 +237,7 @@ internal static void ResetMSBuildPath() }); } - private static Dictionary _nugetRestoreExecuted = new Dictionary(); + private static Dictionary _nugetRestoreExecuted = []; [SupportedOSPlatform("windows")] protected static async Task RestorePackagesAsync(IExternalCommandExecutor externalCommandExecutor, ILogger logger, string workingDirectory, string msbuildPath, CancellationToken ct) { @@ -278,7 +270,7 @@ await AnsiConsole.Status().StartAsync("Restoring packages...", async ctx => }); } - private static Dictionary _nuGetExistsExecuted = new Dictionary(); + private static Dictionary _nuGetExistsExecuted = []; [SupportedOSPlatform("windows")] internal static async Task IsWinUI3Async(FileInfo appxManifestFile, IExternalCommandExecutor externalCommandExecutor, INuGetPackageManager nuGetPackageManager, ILogger logger, CancellationToken ct) diff --git a/MSStore.CLI/ProjectConfigurators/WinUIProjectConfigurator.cs b/MSStore.CLI/ProjectConfigurators/WinUIProjectConfigurator.cs index 99579ce..50c4e32 100644 --- a/MSStore.CLI/ProjectConfigurators/WinUIProjectConfigurator.cs +++ b/MSStore.CLI/ProjectConfigurators/WinUIProjectConfigurator.cs @@ -19,25 +19,20 @@ namespace MSStore.CLI.ProjectConfigurators { - internal class WinUIProjectConfigurator : UWPProjectConfigurator + internal class WinUIProjectConfigurator(IExternalCommandExecutor externalCommandExecutor, IBrowserLauncher browserLauncher, IConsoleReader consoleReader, IZipFileManager zipFileManager, IFileDownloader fileDownloader, IAzureBlobManager azureBlobManager, INuGetPackageManager nuGetPackageManager, IAppXManifestManager appXManifestManager, IEnvironmentInformationService environmentInformationService, ILogger logger) : UWPProjectConfigurator(externalCommandExecutor, browserLauncher, consoleReader, zipFileManager, fileDownloader, azureBlobManager, nuGetPackageManager, appXManifestManager, environmentInformationService, logger) { - public WinUIProjectConfigurator(IExternalCommandExecutor externalCommandExecutor, IBrowserLauncher browserLauncher, IConsoleReader consoleReader, IZipFileManager zipFileManager, IFileDownloader fileDownloader, IAzureBlobManager azureBlobManager, INuGetPackageManager nuGetPackageManager, IAppXManifestManager appXManifestManager, IEnvironmentInformationService environmentInformationService, ILogger logger) - : base(externalCommandExecutor, browserLauncher, consoleReader, zipFileManager, fileDownloader, azureBlobManager, nuGetPackageManager, appXManifestManager, environmentInformationService, logger) - { - } - public override string ToString() => "Windows App SDK/WinUI"; - public override string[] PackageFilesExtensionInclude => new[] { ".msixupload", ".appxupload", ".msix" }; + public override string[] PackageFilesExtensionInclude => [".msixupload", ".appxupload", ".msix"]; public override SearchOption PackageFilesSearchOption { get; } = SearchOption.AllDirectories; public override PublishFileSearchFilterStrategy PublishFileSearchFilterStrategy { get; } = PublishFileSearchFilterStrategy.OneLevelDown; - public override AllowTargetFutureDeviceFamily[] AllowTargetFutureDeviceFamilies { get; } = new[] - { + public override AllowTargetFutureDeviceFamily[] AllowTargetFutureDeviceFamilies { get; } = + [ AllowTargetFutureDeviceFamily.Desktop, AllowTargetFutureDeviceFamily.Mobile, AllowTargetFutureDeviceFamily.Holographic - }; + ]; public override async Task CanConfigureAsync(string pathOrUrl, CancellationToken ct) { diff --git a/MSStore.CLI/Properties/PublishProfiles/linux-arm64.pubxml b/MSStore.CLI/Properties/PublishProfiles/linux-arm64.pubxml index 7695de9..c5508b1 100644 --- a/MSStore.CLI/Properties/PublishProfiles/linux-arm64.pubxml +++ b/MSStore.CLI/Properties/PublishProfiles/linux-arm64.pubxml @@ -6,10 +6,10 @@ https://go.microsoft.com/fwlink/?LinkID=208121. Release Any CPU - bin\Release\net8.0\linux-arm64\publish\ + bin\Release\net9.0\linux-arm64\publish\ FileSystem <_TargetId>Folder - net8.0 + net9.0 linux-arm64 false true diff --git a/MSStore.CLI/Properties/PublishProfiles/linux-x64.pubxml b/MSStore.CLI/Properties/PublishProfiles/linux-x64.pubxml index 5e959c3..fa4e1b3 100644 --- a/MSStore.CLI/Properties/PublishProfiles/linux-x64.pubxml +++ b/MSStore.CLI/Properties/PublishProfiles/linux-x64.pubxml @@ -6,10 +6,10 @@ https://go.microsoft.com/fwlink/?LinkID=208121. Release Any CPU - bin\Release\net8.0\linux-x64\publish\ + bin\Release\net9.0\linux-x64\publish\ FileSystem <_TargetId>Folder - net8.0 + net9.0 linux-x64 false true diff --git a/MSStore.CLI/Properties/PublishProfiles/osx-arm64.pubxml b/MSStore.CLI/Properties/PublishProfiles/osx-arm64.pubxml index 8676b10..8fabc72 100644 --- a/MSStore.CLI/Properties/PublishProfiles/osx-arm64.pubxml +++ b/MSStore.CLI/Properties/PublishProfiles/osx-arm64.pubxml @@ -6,10 +6,10 @@ https://go.microsoft.com/fwlink/?LinkID=208121. Release Any CPU - bin\Release\net8.0\osx-arm64\publish\ + bin\Release\net9.0\osx-arm64\publish\ FileSystem <_TargetId>Folder - net8.0 + net9.0 osx-arm64 false true diff --git a/MSStore.CLI/Properties/PublishProfiles/osx-x64.pubxml b/MSStore.CLI/Properties/PublishProfiles/osx-x64.pubxml index f01a415..ea99c8c 100644 --- a/MSStore.CLI/Properties/PublishProfiles/osx-x64.pubxml +++ b/MSStore.CLI/Properties/PublishProfiles/osx-x64.pubxml @@ -6,10 +6,10 @@ https://go.microsoft.com/fwlink/?LinkID=208121. Release Any CPU - bin\Release\net8.0\osx-x64\publish\ + bin\Release\net9.0\osx-x64\publish\ FileSystem <_TargetId>Folder - net8.0 + net9.0 osx-x64 false true diff --git a/MSStore.CLI/Properties/PublishProfiles/win-arm64.pubxml b/MSStore.CLI/Properties/PublishProfiles/win-arm64.pubxml index 503f897..7c95de0 100644 --- a/MSStore.CLI/Properties/PublishProfiles/win-arm64.pubxml +++ b/MSStore.CLI/Properties/PublishProfiles/win-arm64.pubxml @@ -6,10 +6,10 @@ https://go.microsoft.com/fwlink/?LinkID=208121. Release Any CPU - bin\Release\net8.0-windows10.0.17763.0\win-arm64\publish\ + bin\Release\net9.0-windows10.0.17763.0\win-arm64\publish\ FileSystem <_TargetId>Folder - net8.0-windows10.0.17763.0 + net9.0-windows10.0.17763.0 win-arm64 false true diff --git a/MSStore.CLI/Properties/PublishProfiles/win-x64.pubxml b/MSStore.CLI/Properties/PublishProfiles/win-x64.pubxml index 6af33cc..580be03 100644 --- a/MSStore.CLI/Properties/PublishProfiles/win-x64.pubxml +++ b/MSStore.CLI/Properties/PublishProfiles/win-x64.pubxml @@ -6,10 +6,10 @@ https://go.microsoft.com/fwlink/?LinkID=208121. Release Any CPU - bin\Release\net8.0-windows10.0.17763.0\win-x64\publish\ + bin\Release\net9.0-windows10.0.17763.0\win-x64\publish\ FileSystem <_TargetId>Folder - net8.0-windows10.0.17763.0 + net9.0-windows10.0.17763.0 win-x64 false true diff --git a/MSStore.CLI/Services/AppXManifestManager.cs b/MSStore.CLI/Services/AppXManifestManager.cs index b9e11f1..1001005 100644 --- a/MSStore.CLI/Services/AppXManifestManager.cs +++ b/MSStore.CLI/Services/AppXManifestManager.cs @@ -435,7 +435,7 @@ public List GetAllImagesFromManifest(FileInfo appxManifest, ILogger logg private static List GetAllImagesFiles(string imageNodeText, FileInfo appxManifest, ILogger logger) { - List imagePaths = new List(); + List imagePaths = []; try { string installLocation = appxManifest.Directory?.FullName ?? string.Empty; diff --git a/MSStore.CLI/Services/AzureBlobManager.cs b/MSStore.CLI/Services/AzureBlobManager.cs index 7bfe7e6..d157487 100644 --- a/MSStore.CLI/Services/AzureBlobManager.cs +++ b/MSStore.CLI/Services/AzureBlobManager.cs @@ -14,14 +14,9 @@ namespace MSStore.CLI.Services { - internal class AzureBlobManager : IAzureBlobManager + internal class AzureBlobManager(TelemetryClient telemetryClient) : IAzureBlobManager { - private readonly TelemetryClient _telemetryClient = null!; - - public AzureBlobManager(TelemetryClient telemetryClient) - { - _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); - } + private readonly TelemetryClient _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); public async Task UploadFileAsync(string blobUri, string localFilePath, IProgress progress, CancellationToken ct) { @@ -53,18 +48,11 @@ public async Task UploadFileAsync(string blobUri, string localFilePath, } } - public class AddCorrelationIdHeaderPolicy : HttpPipelineSynchronousPolicy + public class AddCorrelationIdHeaderPolicy(TelemetryClient telemetryClient) : HttpPipelineSynchronousPolicy { - private readonly TelemetryClient _telemetryClient; - - public AddCorrelationIdHeaderPolicy(TelemetryClient telemetryClient) - { - _telemetryClient = telemetryClient; - } - public override void OnSendingRequest(HttpMessage message) { - message.Request.Headers.Add("ms-correlationid", _telemetryClient.Context.Session.Id); + message.Request.Headers.Add("ms-correlationid", telemetryClient.Context.Session.Id); base.OnSendingRequest(message); } } diff --git a/MSStore.CLI/Services/BrowserLauncher.cs b/MSStore.CLI/Services/BrowserLauncher.cs index 6d55856..480f335 100644 --- a/MSStore.CLI/Services/BrowserLauncher.cs +++ b/MSStore.CLI/Services/BrowserLauncher.cs @@ -10,24 +10,15 @@ namespace MSStore.CLI.Services { - internal class BrowserLauncher : IBrowserLauncher + internal class BrowserLauncher(IConsoleReader consoleReader, ILogger logger, IEnvironmentInformationService environmentInformationService) : IBrowserLauncher { - private readonly IConsoleReader _consoleReader; - private readonly IEnvironmentInformationService _environmentInformationService; - private readonly ILogger _logger; - - public BrowserLauncher(IConsoleReader consoleReader, ILogger logger, IEnvironmentInformationService environmentInformationService) - { - _consoleReader = consoleReader; - _logger = logger; - _environmentInformationService = environmentInformationService ?? throw new System.ArgumentNullException(nameof(environmentInformationService)); - } + private readonly IEnvironmentInformationService _environmentInformationService = environmentInformationService ?? throw new System.ArgumentNullException(nameof(environmentInformationService)); public async Task OpenBrowserAsync(string url, bool askConfirmation, CancellationToken ct) { if (_environmentInformationService.IsRunningOnCI) { - _logger.LogInformation("Skipping browser launch because we are running on CI. URL = {Url}", url); + logger.LogInformation("Skipping browser launch because we are running on CI. URL = {Url}", url); return; } @@ -36,13 +27,13 @@ public async Task OpenBrowserAsync(string url, bool askConfirmation, Cancellatio { AnsiConsole.MarkupLine($"Press [b green]Enter[/] to open the browser at this page: [link]{url.EscapeMarkup()}[/]"); - if (await _consoleReader.ReadNextAsync(false, ct) != string.Empty) + if (await consoleReader.ReadNextAsync(false, ct) != string.Empty) { return; } } - _logger.LogInformation("Trying to open browser with url: {Url}", url); + logger.LogInformation("Trying to open browser with url: {Url}", url); try { diff --git a/MSStore.CLI/Services/CLIConfigurator.cs b/MSStore.CLI/Services/CLIConfigurator.cs index 53d1d0a..d98bb54 100644 --- a/MSStore.CLI/Services/CLIConfigurator.cs +++ b/MSStore.CLI/Services/CLIConfigurator.cs @@ -2,7 +2,6 @@ // Licensed under the MIT License. using System; -using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; @@ -18,39 +17,26 @@ namespace MSStore.CLI.Services { - internal class CLIConfigurator : ICLIConfigurator + internal class CLIConfigurator( + IStoreAPIFactory storeAPIFactory, + IConsoleReader consoleReader, + ICredentialManager credentialManager, + IConfigurationManager configurationManager, + IGraphClient graphClient, + IBrowserLauncher browserLauncher, + IPartnerCenterManager partnerCenterManager, + ITokenManager tokenManager, + ILogger logger) : ICLIConfigurator { - private readonly IStoreAPIFactory _storeAPIFactory; - private readonly IConsoleReader _consoleReader; - private readonly ICredentialManager _credentialManager; - private readonly IConfigurationManager _configurationManager; - private readonly IGraphClient _graphClient; - private readonly IBrowserLauncher _browserLauncher; - private readonly IPartnerCenterManager _partnerCenterManager; - private readonly ITokenManager _tokenManager; - private readonly ILogger _logger; - - public CLIConfigurator( - IStoreAPIFactory storeAPIFactory, - IConsoleReader consoleReader, - ICredentialManager credentialManager, - IConfigurationManager configurationManager, - IGraphClient graphClient, - IBrowserLauncher browserLauncher, - IPartnerCenterManager partnerCenterManager, - ITokenManager tokenManager, - ILogger logger) - { - _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); - _consoleReader = consoleReader ?? throw new ArgumentNullException(nameof(consoleReader)); - _credentialManager = credentialManager ?? throw new ArgumentNullException(nameof(credentialManager)); - _configurationManager = configurationManager ?? throw new ArgumentNullException(nameof(configurationManager)); - _graphClient = graphClient ?? throw new ArgumentNullException(nameof(graphClient)); - _browserLauncher = browserLauncher ?? throw new ArgumentNullException(nameof(browserLauncher)); - _partnerCenterManager = partnerCenterManager ?? throw new ArgumentNullException(nameof(partnerCenterManager)); - _tokenManager = tokenManager ?? throw new ArgumentNullException(nameof(tokenManager)); - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - } + private readonly IStoreAPIFactory _storeAPIFactory = storeAPIFactory ?? throw new ArgumentNullException(nameof(storeAPIFactory)); + private readonly IConsoleReader _consoleReader = consoleReader ?? throw new ArgumentNullException(nameof(consoleReader)); + private readonly ICredentialManager _credentialManager = credentialManager ?? throw new ArgumentNullException(nameof(credentialManager)); + private readonly IConfigurationManager _configurationManager = configurationManager ?? throw new ArgumentNullException(nameof(configurationManager)); + private readonly IGraphClient _graphClient = graphClient ?? throw new ArgumentNullException(nameof(graphClient)); + private readonly IBrowserLauncher _browserLauncher = browserLauncher ?? throw new ArgumentNullException(nameof(browserLauncher)); + private readonly IPartnerCenterManager _partnerCenterManager = partnerCenterManager ?? throw new ArgumentNullException(nameof(partnerCenterManager)); + private readonly ITokenManager _tokenManager = tokenManager ?? throw new ArgumentNullException(nameof(tokenManager)); + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); public async Task ConfigureAsync(bool askConfirmation, Guid? tenantId = null, string? sellerId = null, Guid? clientId = null, string? clientSecret = null, string? certificateThumbprint = null, string? certificateFilePath = null, string? certificatePassword = null, CancellationToken ct = default) { @@ -231,7 +217,7 @@ public async Task ConfigureAsync(bool askConfirmation, Guid? tenantId = nu var appUpdateRequest = new AppUpdateRequest { - IdentifierUris = new List { $"https://{organization.Domain}/{clientApp.AppId}" }, + IdentifierUris = [$"https://{organization.Domain}/{clientApp.AppId}"], SignInAudience = "AzureADMyOrg" }; diff --git a/MSStore.CLI/Services/ConfigurationManager.cs b/MSStore.CLI/Services/ConfigurationManager.cs index c8d8b04..0b19aef 100644 --- a/MSStore.CLI/Services/ConfigurationManager.cs +++ b/MSStore.CLI/Services/ConfigurationManager.cs @@ -16,7 +16,7 @@ namespace MSStore.CLI.Services { - internal class ConfigurationManager : IConfigurationManager + internal class ConfigurationManager(JsonTypeInfo jsonTypeInfo, string fileName, ILogger>? logger) : IConfigurationManager where T : new() { private static readonly string SettingsDirectory = Path.Combine(GetSystemLocalApplicationDataPath(), "Microsoft", "MSStore.CLI"); @@ -43,19 +43,12 @@ private static string GetSystemLocalApplicationDataPath() return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); } - private readonly string _settingsPath; - private readonly JsonTypeInfo _jsonTypeInfo; - private readonly ILogger? _logger; + private readonly string _settingsPath = Path.Combine(SettingsDirectory, fileName); + private readonly JsonTypeInfo _jsonTypeInfo = jsonTypeInfo ?? throw new ArgumentNullException(nameof(jsonTypeInfo)); + private readonly ILogger? _logger = logger; public string ConfigPath => _settingsPath; - public ConfigurationManager(JsonTypeInfo jsonTypeInfo, string fileName, ILogger>? logger) - { - _settingsPath = Path.Combine(SettingsDirectory, fileName); - _jsonTypeInfo = jsonTypeInfo ?? throw new ArgumentNullException(nameof(jsonTypeInfo)); - _logger = logger; - } - public async Task LoadAsync(bool clearInvalidConfig, CancellationToken ct) { try diff --git a/MSStore.CLI/Services/CredentialManager/Unix/CredentialManagerUnix.cs b/MSStore.CLI/Services/CredentialManager/Unix/CredentialManagerUnix.cs index dd2c93e..0cee517 100644 --- a/MSStore.CLI/Services/CredentialManager/Unix/CredentialManagerUnix.cs +++ b/MSStore.CLI/Services/CredentialManager/Unix/CredentialManagerUnix.cs @@ -13,7 +13,7 @@ namespace MSStore.CLI.Services.CredentialManager.Unix internal class CredentialManagerUnix : ICredentialManager { private static readonly string SchemaName = "com.microsoft.store.credentials"; - private static readonly KeyValuePair LinuxKeyRingAttr1 = new KeyValuePair("Service", "msstore-cli"); + private static readonly KeyValuePair LinuxKeyRingAttr1 = new("Service", "msstore-cli"); private static readonly string LinuxKeyRingAttr2Key = "Account"; private static readonly string LinuxKeyRingCollection = "default"; @@ -35,7 +35,7 @@ internal class CredentialManagerUnix : ICredentialManager passwordData: out passwordDataPtr, itemRef: out itemPtr); - byte[] content = Array.Empty(); + byte[] content = []; switch (resultStatus) { case NativeMethods.SecResultCodes.ErrSecItemNotFound: @@ -176,7 +176,7 @@ private static void FreePointers(ref IntPtr itemPtr, ref IntPtr passwordDataPtr) } [SupportedOSPlatform("linux")] - private Lazy _libsecretSchema = new Lazy(() => + private Lazy _libsecretSchema = new(() => { var libsecretSchema = NativeMethods.secret_schema_new( name: SchemaName, diff --git a/MSStore.CLI/Services/CredentialManager/Unix/NativeMethods.cs b/MSStore.CLI/Services/CredentialManager/Unix/NativeMethods.cs index 275e208..12662aa 100644 --- a/MSStore.CLI/Services/CredentialManager/Unix/NativeMethods.cs +++ b/MSStore.CLI/Services/CredentialManager/Unix/NativeMethods.cs @@ -5,9 +5,6 @@ using System.Runtime.InteropServices; using System.Runtime.Versioning; -// https://github.com/dotnet/roslyn-analyzers/issues/5479 -#pragma warning disable CA2101 // Specify marshaling for P/Invoke string arguments - namespace MSStore.CLI.Services.CredentialManager.Unix { internal static class NativeMethods @@ -155,7 +152,7 @@ public enum NSSearchPathDomain : ulong [SupportedOSPlatform("macos")] [DllImport(CoreFoundationFramework, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] - private static unsafe extern char* CFStringGetCharactersPtr(IntPtr handle); + private static extern unsafe char* CFStringGetCharactersPtr(IntPtr handle); [SupportedOSPlatform("macos")] [DllImport(CoreFoundationFramework, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] @@ -180,7 +177,7 @@ public enum NSSearchPathDomain : ulong var c = (int)GetCount(handle); if (c == 0) { - return Array.Empty(); + return []; } var buffer = c <= 256 ? stackalloc IntPtr[c] : new IntPtr[c]; @@ -205,28 +202,18 @@ public enum NSSearchPathDomain : ulong [StructLayout(LayoutKind.Sequential)] private struct CFRange { +#pragma warning disable IDE0044 // Add readonly modifier private nint loc; // defined as 'long' in native code private nint len; // defined as 'long' in native code +#pragma warning restore IDE0044 // Add readonly modifier - public int Location - { - get { return (int)loc; } - } + public readonly int Location => (int)loc; - public int Length - { - get { return (int)len; } - } + public readonly int Length => (int)len; - public long LongLocation - { - get { return loc; } - } + public readonly long LongLocation => loc; - public long LongLength - { - get { return len; } - } + public readonly long LongLength => len; public CFRange(int loc, int len) { @@ -246,7 +233,7 @@ public CFRange(nint l, nint len) this.len = len; } - public override string ToString() + public override readonly string ToString() { return $"CFRange [Location: {loc} Length: {len}]"; } @@ -304,6 +291,4 @@ public override string ToString() return str; } } -} - -#pragma warning restore CA2101 // Specify marshaling for P/Invoke string arguments \ No newline at end of file +} \ No newline at end of file diff --git a/MSStore.CLI/Services/ExternalCommandExecutor.cs b/MSStore.CLI/Services/ExternalCommandExecutor.cs index f9ef8d6..5088362 100644 --- a/MSStore.CLI/Services/ExternalCommandExecutor.cs +++ b/MSStore.CLI/Services/ExternalCommandExecutor.cs @@ -12,14 +12,9 @@ namespace MSStore.CLI.Services { - internal class ExternalCommandExecutor : IExternalCommandExecutor + internal class ExternalCommandExecutor(ILogger logger) : IExternalCommandExecutor { - private ILogger _logger; - - public ExternalCommandExecutor(ILogger logger) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - } + private ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); public async Task RunAsync(string command, string arguments, string workingDirectory, CancellationToken ct) { @@ -123,7 +118,7 @@ public async Task FindToolAsync(string command, CancellationToken ct) } var toolPaths = result.StdOut.Trim(); - var toolPathList = toolPaths.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); + var toolPathList = toolPaths.Split([Environment.NewLine], StringSplitOptions.RemoveEmptyEntries); return toolPathList.Length == 0 ? string.Empty : toolPathList[0]; } } diff --git a/MSStore.CLI/Services/FileDownloader.cs b/MSStore.CLI/Services/FileDownloader.cs index c759906..effb049 100644 --- a/MSStore.CLI/Services/FileDownloader.cs +++ b/MSStore.CLI/Services/FileDownloader.cs @@ -10,14 +10,9 @@ namespace MSStore.CLI.Services { - internal class FileDownloader : IFileDownloader + internal class FileDownloader(IHttpClientFactory httpClientFactory) : IFileDownloader { - private readonly IHttpClientFactory _httpClientFactory = null!; - - public FileDownloader(IHttpClientFactory httpClientFactory) - { - _httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory)); - } + private readonly IHttpClientFactory _httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory)); public async Task DownloadAsync(string url, string destinationFileName, IProgress progress, ILogger? logger, CancellationToken ct = default) { diff --git a/MSStore.CLI/Services/Graph/GraphClient.cs b/MSStore.CLI/Services/Graph/GraphClient.cs index 3f98d28..7b3c6f5 100644 --- a/MSStore.CLI/Services/Graph/GraphClient.cs +++ b/MSStore.CLI/Services/Graph/GraphClient.cs @@ -14,23 +14,17 @@ namespace MSStore.CLI.Services.Graph { - internal class GraphClient : IGraphClient + internal class GraphClient(ITokenManager tokenManager, IHttpClientFactory httpClientFactory) : IGraphClient { - internal static readonly string[] GraphApplicationReadWriteScope = new[] { "https://graph.microsoft.com/Application.ReadWrite.All" }; + internal static readonly string[] GraphApplicationReadWriteScope = ["https://graph.microsoft.com/Application.ReadWrite.All"]; private static readonly string JsonContentType = "application/json"; - private readonly ITokenManager _tokenManager; - private readonly IHttpClientFactory _httpClientFactory = null!; + private readonly ITokenManager _tokenManager = tokenManager ?? throw new ArgumentNullException(nameof(tokenManager)); + private readonly IHttpClientFactory _httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory)); public bool Enabled => true; - public GraphClient(ITokenManager tokenManager, IHttpClientFactory httpClientFactory) - { - _tokenManager = tokenManager ?? throw new ArgumentNullException(nameof(tokenManager)); - _httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory)); - } - private async Task InvokeAsync( HttpMethod httpMethod, string relativeUrl, diff --git a/MSStore.CLI/Services/ImageConverter.cs b/MSStore.CLI/Services/ImageConverter.cs index 09d728d..399c3db 100644 --- a/MSStore.CLI/Services/ImageConverter.cs +++ b/MSStore.CLI/Services/ImageConverter.cs @@ -10,14 +10,9 @@ namespace MSStore.CLI.Services { - internal class ImageConverter : IImageConverter + internal class ImageConverter(ILogger logger) : IImageConverter { - private ILogger _logger; - - public ImageConverter(ILogger logger) - { - _logger = logger; - } + private ILogger _logger = logger; public async Task ConvertIcoToPngAsync(string sourceFilePath, string destinationFilePath, int destinationWidth, int destinationHeight, int paddingX, int paddingY, CancellationToken ct) { diff --git a/MSStore.CLI/Services/NuGetPackageManager.cs b/MSStore.CLI/Services/NuGetPackageManager.cs index 77c5c3e..b4d667b 100644 --- a/MSStore.CLI/Services/NuGetPackageManager.cs +++ b/MSStore.CLI/Services/NuGetPackageManager.cs @@ -11,14 +11,9 @@ namespace MSStore.CLI.Services { - internal class NuGetPackageManager : INuGetPackageManager + internal class NuGetPackageManager(ILogger logger) : INuGetPackageManager { - private readonly ILogger _logger; - - public NuGetPackageManager(ILogger logger) - { - _logger = logger; - } + private readonly ILogger _logger = logger; public virtual bool IsMaui(FileInfo fileInfo) { diff --git a/MSStore.CLI/Services/PWABuilder/IconExtensions.cs b/MSStore.CLI/Services/PWABuilder/IconExtensions.cs index 4b63cf1..c7e13e1 100644 --- a/MSStore.CLI/Services/PWABuilder/IconExtensions.cs +++ b/MSStore.CLI/Services/PWABuilder/IconExtensions.cs @@ -11,7 +11,7 @@ internal static class IconExtensions public static Vector2 GetSize(this Icon icon) { var sizes = icon.Sizes; - if(string.IsNullOrEmpty(sizes)) + if (string.IsNullOrEmpty(sizes)) { return default; } diff --git a/MSStore.CLI/Services/PWABuilder/PWABuilderClient.cs b/MSStore.CLI/Services/PWABuilder/PWABuilderClient.cs index 4516264..19cc7ac 100644 --- a/MSStore.CLI/Services/PWABuilder/PWABuilderClient.cs +++ b/MSStore.CLI/Services/PWABuilder/PWABuilderClient.cs @@ -12,15 +12,10 @@ namespace MSStore.CLI.Services.PWABuilder { - internal class PWABuilderClient : IPWABuilderClient + internal class PWABuilderClient(IHttpClientFactory httpClientFactory) : IPWABuilderClient { private static readonly string JsonContentType = "application/json"; - private readonly IHttpClientFactory _httpClientFactory; - - public PWABuilderClient(IHttpClientFactory httpClientFactory) - { - _httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory)); - } + private readonly IHttpClientFactory _httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory)); protected virtual void SetRequest(HttpRequestMessage request, object? requestContent) { diff --git a/MSStore.CLI/Services/PartnerCenter/PartnerCenterManager.cs b/MSStore.CLI/Services/PartnerCenter/PartnerCenterManager.cs index 703c7a5..aa94466 100644 --- a/MSStore.CLI/Services/PartnerCenter/PartnerCenterManager.cs +++ b/MSStore.CLI/Services/PartnerCenter/PartnerCenterManager.cs @@ -13,23 +13,17 @@ namespace MSStore.CLI.Services.PartnerCenter { - internal class PartnerCenterManager : IPartnerCenterManager + internal class PartnerCenterManager(ITokenManager tokenManager, IHttpClientFactory httpClientFactory) : IPartnerCenterManager { private static readonly string JsonContentType = "application/json"; - private static readonly string[] PartnerCenterUserImpersonationScope = new[] { "https://api.partnercenter.microsoft.com/user_impersonation" }; + private static readonly string[] PartnerCenterUserImpersonationScope = ["https://api.partnercenter.microsoft.com/user_impersonation"]; - private readonly ITokenManager _tokenManager; - private readonly IHttpClientFactory _httpClientFactory; + private readonly ITokenManager _tokenManager = tokenManager ?? throw new ArgumentNullException(nameof(tokenManager)); + private readonly IHttpClientFactory _httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory)); public bool Enabled => false; - public PartnerCenterManager(ITokenManager tokenManager, IHttpClientFactory httpClientFactory) - { - _tokenManager = tokenManager ?? throw new ArgumentNullException(nameof(tokenManager)); - _httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory)); - } - private async Task InvokeAsync( HttpMethod httpMethod, string relativeUrl, diff --git a/MSStore.CLI/Services/StoreAPIFactory.cs b/MSStore.CLI/Services/StoreAPIFactory.cs index b2465e2..bdc9967 100644 --- a/MSStore.CLI/Services/StoreAPIFactory.cs +++ b/MSStore.CLI/Services/StoreAPIFactory.cs @@ -13,20 +13,12 @@ namespace MSStore.CLI.Services { - internal class StoreAPIFactory : IStoreAPIFactory + internal class StoreAPIFactory(IConfigurationManager configurationManager, ICredentialManager credentialManager, IHttpClientFactory httpClientFactory, ILogger logger) : IStoreAPIFactory { - private readonly IConfigurationManager _configurationManager; - private readonly ICredentialManager _credentialManager; - private readonly IHttpClientFactory _httpClientFactory; - private readonly ILogger _logger; - - public StoreAPIFactory(IConfigurationManager configurationManager, ICredentialManager credentialManager, IHttpClientFactory httpClientFactory, ILogger logger) - { - _configurationManager = configurationManager ?? throw new ArgumentNullException(nameof(configurationManager)); - _credentialManager = credentialManager ?? throw new ArgumentNullException(nameof(credentialManager)); - _httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory)); - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - } + private readonly IConfigurationManager _configurationManager = configurationManager ?? throw new ArgumentNullException(nameof(configurationManager)); + private readonly ICredentialManager _credentialManager = credentialManager ?? throw new ArgumentNullException(nameof(credentialManager)); + private readonly IHttpClientFactory _httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory)); + private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); public async Task CreateAsync(Configurations? config = null, CancellationToken ct = default) { @@ -132,7 +124,7 @@ public async Task CreatePackagedAsync(Configurations? config } else if (config.CertificateFilePath != null) { - return new X509Certificate2(config.CertificateFilePath, string.IsNullOrEmpty(secret) ? null : secret); + return X509CertificateLoader.LoadPkcs12FromFile(config.CertificateFilePath, string.IsNullOrEmpty(secret) ? null : secret); } return null; diff --git a/MSStore.CLI/Services/TokenManager/MSALTokenManager.cs b/MSStore.CLI/Services/TokenManager/MSALTokenManager.cs index 2e49e1c..57b8672 100644 --- a/MSStore.CLI/Services/TokenManager/MSALTokenManager.cs +++ b/MSStore.CLI/Services/TokenManager/MSALTokenManager.cs @@ -17,7 +17,7 @@ namespace MSStore.CLI.Services.TokenManager { - internal class MSALTokenManager : ITokenManager + internal class MSALTokenManager(IConsoleReader consoleReader) : ITokenManager { private const string MSATenantId = "9188040d-6c67-4c5b-b112-36a304b66dad"; @@ -29,24 +29,19 @@ internal class MSALTokenManager : ITokenManager private static readonly string LinuxKeyRingSchema = "com.microsoft.store.tokencache"; private static readonly string LinuxKeyRingCollection = MsalCacheHelper.LinuxKeyRingDefaultCollection; private static readonly string LinuxKeyRingLabel = "MSAL token cache for all Microsoft Store Apps."; - private static readonly KeyValuePair LinuxKeyRingAttr1 = new KeyValuePair("Version", "1"); - private static readonly KeyValuePair LinuxKeyRingAttr2 = new KeyValuePair("ProductGroup", "msstore-cli"); + private static readonly KeyValuePair LinuxKeyRingAttr1 = new("Version", "1"); + private static readonly KeyValuePair LinuxKeyRingAttr2 = new("ProductGroup", "msstore-cli"); // Microsoft Store CLI private static readonly string ClientId = "76b1a1a3-44ef-4bb8-bbe3-cb462ebaeee4"; - private readonly IConsoleReader _consoleReader; + private readonly IConsoleReader _consoleReader = consoleReader ?? throw new ArgumentNullException(nameof(consoleReader)); private IPublicClientApplication? _app; private IAccount? _selectedAccount; public IAccount? CurrentUser => _selectedAccount; - public MSALTokenManager(IConsoleReader consoleReader) - { - _consoleReader = consoleReader ?? throw new ArgumentNullException(nameof(consoleReader)); - } - [MemberNotNull(nameof(_app))] private async Task InitAppAsync() { diff --git a/MSStore.CLI/StatusContextExtensions.cs b/MSStore.CLI/StatusContextExtensions.cs index b5722f6..d299bde 100644 --- a/MSStore.CLI/StatusContextExtensions.cs +++ b/MSStore.CLI/StatusContextExtensions.cs @@ -25,7 +25,7 @@ public static void ErrorStatus(this StatusContext _, Exception exception) var message = ex.Message + Environment.NewLine + string.Join(Environment.NewLine, ex.ResponseErrors); ErrorStatus(_, message); break; - case Exception _: + case Exception: ErrorStatus(_, "Error!"); break; }