-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added basic support for package flights (list only).
- Loading branch information
Showing
10 changed files
with
231 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace MSStore.API.Packaged.Models | ||
{ | ||
public class DevCenterFlight | ||
{ | ||
public string? FlightId { get; set; } | ||
public string? FriendlyName { get; set; } | ||
public ApplicationSubmissionInfo? LastPublishedFlightSubmission { get; set; } | ||
public ApplicationSubmissionInfo? PendingFlightSubmission { get; set; } | ||
public List<string>? GroupIds { get; set; } | ||
public string? RankHigherThan { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace MSStore.CLI.UnitTests | ||
{ | ||
[TestClass] | ||
public class FlightsCommandUnitTests : BaseCommandLineTest | ||
{ | ||
[TestInitialize] | ||
public void Init() | ||
{ | ||
FakeLogin(); | ||
AddDefaultFakeAccount(); | ||
AddFakeApps(); | ||
AddFakeFlights(); | ||
} | ||
|
||
[TestMethod] | ||
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)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.CommandLine; | ||
using System.CommandLine.Invocation; | ||
using System.Globalization; | ||
using System.Threading.Tasks; | ||
using Microsoft.ApplicationInsights; | ||
using Microsoft.Extensions.Logging; | ||
using MSStore.CLI.Helpers; | ||
using MSStore.CLI.Services; | ||
using Spectre.Console; | ||
|
||
namespace MSStore.CLI.Commands.Flights | ||
{ | ||
internal class ListCommand : Command | ||
{ | ||
public ListCommand() | ||
: base("list", "Retrieves all the Flights for the specified Application.") | ||
{ | ||
AddArgument(SubmissionCommand.ProductIdArgument); | ||
} | ||
|
||
public new class Handler : ICommandHandler | ||
{ | ||
private readonly ILogger _logger; | ||
private readonly IStoreAPIFactory _storeAPIFactory; | ||
private readonly TelemetryClient _telemetryClient; | ||
|
||
public string ProductId { get; set; } = null!; | ||
|
||
public Handler(ILogger<Handler> 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; | ||
} | ||
|
||
public async Task<int> InvokeAsync(InvocationContext context) | ||
{ | ||
var ct = context.GetCancellationToken(); | ||
|
||
if (ProductTypeHelper.Solve(ProductId) == ProductType.Unpackaged) | ||
{ | ||
AnsiConsole.WriteLine("This command is not supported for unpackaged applications."); | ||
return await _telemetryClient.TrackCommandEventAsync<Handler>(ProductId, -1, ct); | ||
} | ||
|
||
return await _telemetryClient.TrackCommandEventAsync<Handler>( | ||
await AnsiConsole.Status().StartAsync("Retrieving Flights", async ctx => | ||
{ | ||
try | ||
{ | ||
var storePackagedAPI = await _storeAPIFactory.CreatePackagedAsync(ct: ct); | ||
var flightsList = await storePackagedAPI.GetFlightsAsync(ProductId, ct); | ||
ctx.SuccessStatus("[bold green]Retrieved Flights[/]"); | ||
if (flightsList?.Count > 0) | ||
{ | ||
var table = new Table(); | ||
table.AddColumns(string.Empty, "FlightId", "FriendlyName", "LastPublishedFlightSubmission.Id", "PendingFlightSubmission.Id", "GroupIds", "RankHigherThan"); | ||
int i = 1; | ||
foreach (var f in flightsList) | ||
{ | ||
table.AddRow( | ||
i.ToString(CultureInfo.InvariantCulture), | ||
$"[bold u]{f.FlightId}[/]", | ||
$"[bold u]{f.FriendlyName}[/]", | ||
$"[bold u]{f.LastPublishedFlightSubmission?.Id}[/]", | ||
$"[bold u]{f.PendingFlightSubmission?.Id}[/]", | ||
$"[bold u]{string.Join(", ", f.GroupIds ?? new())}[/]", | ||
$"[bold u]{f.RankHigherThan}[/]"); | ||
i++; | ||
} | ||
AnsiConsole.Write(table); | ||
} | ||
else | ||
{ | ||
AnsiConsole.MarkupLine("The application has [bold][u]no[/] Flights[/]."); | ||
} | ||
AnsiConsole.WriteLine(); | ||
return 0; | ||
} | ||
catch (Exception err) | ||
{ | ||
_logger.LogError(err, "Error while retrieving Flights."); | ||
ctx.ErrorStatus(err); | ||
return -1; | ||
} | ||
}), ct); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.CommandLine; | ||
using MSStore.CLI.Commands.Flights; | ||
|
||
namespace MSStore.CLI.Commands | ||
{ | ||
internal class FlightsCommand : Command | ||
{ | ||
public FlightsCommand() | ||
: base("flights", "Execute flights related tasks.") | ||
{ | ||
AddCommand(new ListCommand()); | ||
this.SetDefaultHelpHandler(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters