-
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 update and publish flight submission commands.
- Loading branch information
Showing
9 changed files
with
305 additions
and
3 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
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,19 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
|
||
namespace MSStore.API.Packaged.Models | ||
{ | ||
public interface IDevCenterSubmission | ||
{ | ||
public string? Id { get; set; } | ||
public string? Status { get; set; } | ||
public StatusDetails? StatusDetails { get; set; } | ||
public PackageDeliveryOptions? PackageDeliveryOptions { get; set; } | ||
public string? FileUploadUrl { get; set; } | ||
public string? TargetPublishMode { get; set; } | ||
public DateTime? TargetPublishDate { get; set; } | ||
public string? NotesForCertification { 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
109 changes: 109 additions & 0 deletions
109
MSStore.CLI/Commands/Flights/Submission/PublishCommand.cs
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,109 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.CommandLine; | ||
using System.CommandLine.Invocation; | ||
using System.Threading.Tasks; | ||
using Microsoft.ApplicationInsights; | ||
using Microsoft.Extensions.Logging; | ||
using MSStore.API; | ||
using MSStore.CLI.Helpers; | ||
using MSStore.CLI.Services; | ||
using Spectre.Console; | ||
|
||
namespace MSStore.CLI.Commands.Flights.Submission | ||
{ | ||
internal class PublishCommand : Command | ||
{ | ||
public PublishCommand() | ||
: base("publish", "Starts the flight submission process for the existing Draft.") | ||
{ | ||
AddArgument(SubmissionCommand.ProductIdArgument); | ||
AddArgument(Flights.GetCommand.FlightIdArgument); | ||
} | ||
|
||
public new class Handler : ICommandHandler | ||
{ | ||
private readonly ILogger _logger; | ||
private readonly IStoreAPIFactory _storeAPIFactory; | ||
private readonly TelemetryClient _telemetryClient; | ||
|
||
public string ProductId { get; set; } = null!; | ||
public string FlightId { 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>( | ||
ProductId, | ||
await AnsiConsole.Status().StartAsync("Publishing flight submission", async ctx => | ||
{ | ||
try | ||
{ | ||
var storePackagedAPI = await _storeAPIFactory.CreatePackagedAsync(ct: ct); | ||
var flight = await storePackagedAPI.GetFlightAsync(ProductId, FlightId, ct); | ||
if (flight?.FlightId == null) | ||
{ | ||
ctx.ErrorStatus($"Could not find application flight with ID '{ProductId}'/'{FlightId}'"); | ||
return -1; | ||
} | ||
var flightSubmission = flight.PendingFlightSubmission; | ||
if (flightSubmission?.Id == null) | ||
{ | ||
ctx.ErrorStatus($"Could not find flight submission for application flight with ID '{ProductId}'/'{FlightId}'"); | ||
return -1; | ||
} | ||
var flightSubmissionCommit = await storePackagedAPI.CommitFlightSubmissionAsync(ProductId, FlightId, flightSubmission.Id, ct); | ||
if (flightSubmissionCommit == null) | ||
{ | ||
throw new MSStoreException("Flight Submission commit failed"); | ||
} | ||
if (flightSubmissionCommit.Status != null) | ||
{ | ||
ctx.SuccessStatus($"Flight Submission Commited with status [green u]{flightSubmissionCommit.Status}[/]"); | ||
return 0; | ||
} | ||
ctx.ErrorStatus($"Could not commit flight submission for application flight with ID '{ProductId}'/'{FlightId}'"); | ||
AnsiConsole.MarkupLine($"[red]{flightSubmissionCommit.ToErrorMessage()}[/]"); | ||
return -1; | ||
} | ||
catch (Exception err) | ||
{ | ||
_logger.LogError(err, "Error while publishing flight submission"); | ||
ctx.ErrorStatus(err); | ||
return -1; | ||
} | ||
}), ct); | ||
} | ||
} | ||
} | ||
} |
145 changes: 145 additions & 0 deletions
145
MSStore.CLI/Commands/Flights/Submission/UpdateCommand.cs
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,145 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.CommandLine; | ||
using System.CommandLine.Invocation; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
using Microsoft.ApplicationInsights; | ||
using Microsoft.Extensions.Logging; | ||
using MSStore.API; | ||
using MSStore.API.Models; | ||
using MSStore.API.Packaged; | ||
using MSStore.CLI.Helpers; | ||
using MSStore.CLI.Services; | ||
using Spectre.Console; | ||
|
||
namespace MSStore.CLI.Commands.Flights.Submission | ||
{ | ||
internal class UpdateCommand : Command | ||
{ | ||
public UpdateCommand() | ||
: base("update", "Updates the existing flight draft with the provided JSON.") | ||
{ | ||
var product = new Argument<string>( | ||
"product", | ||
description: "The updated JSON product representation."); | ||
|
||
AddArgument(SubmissionCommand.ProductIdArgument); | ||
AddArgument(Flights.GetCommand.FlightIdArgument); | ||
AddArgument(product); | ||
AddOption(SubmissionCommand.SkipInitialPolling); | ||
} | ||
|
||
public new class Handler : ICommandHandler | ||
{ | ||
private readonly ILogger _logger; | ||
private readonly IStoreAPIFactory _storeAPIFactory; | ||
private readonly TelemetryClient _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<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); | ||
} | ||
|
||
var updateFlightSubmission = JsonSerializer.Deserialize(Product, SourceGenerationContext.GetCustom().DevCenterFlightSubmissionUpdate); | ||
|
||
if (updateFlightSubmission == null) | ||
{ | ||
throw new MSStoreException("Invalid product provided."); | ||
} | ||
|
||
IStorePackagedAPI storePackagedAPI = null!; | ||
|
||
var flight = await AnsiConsole.Status().StartAsync("Retrieving application flight", async ctx => | ||
{ | ||
try | ||
{ | ||
storePackagedAPI = await _storeAPIFactory.CreatePackagedAsync(ct: ct); | ||
var flight = await storePackagedAPI.GetFlightAsync(ProductId, FlightId, ct); | ||
if (flight?.FlightId == null) | ||
{ | ||
throw new MSStoreException($"Could not find application flight with ID '{ProductId}'/'{FlightId}'"); | ||
} | ||
return flight; | ||
} | ||
catch (Exception err) | ||
{ | ||
_logger.LogError(err, "Error while updating submission product."); | ||
ctx.ErrorStatus(err); | ||
return null; | ||
} | ||
}); | ||
|
||
if (storePackagedAPI == null || flight == null || flight?.FlightId == null) | ||
{ | ||
return 1; | ||
} | ||
|
||
string? submissionId = flight.PendingFlightSubmission?.Id; | ||
|
||
if (submissionId == null) | ||
{ | ||
AnsiConsole.MarkupLine("Could not find an existing flight submission. [b green]Creating new flight submission[/]."); | ||
|
||
var flightSubmission = await storePackagedAPI.CreateNewFlightSubmissionAsync(ProductId, FlightId, _logger, ct); | ||
submissionId = flightSubmission?.Id; | ||
|
||
if (submissionId == null) | ||
{ | ||
throw new MSStoreException("Could not create new flight submission."); | ||
} | ||
} | ||
|
||
var updatedFlightSubmission = await AnsiConsole.Status().StartAsync("Updating flight submission product", async ctx => | ||
{ | ||
try | ||
{ | ||
return await storePackagedAPI.UpdateFlightSubmissionAsync(ProductId, FlightId, submissionId, updateFlightSubmission, ct); | ||
} | ||
catch (Exception err) | ||
{ | ||
_logger.LogError(err, "Error while updating flight submission product."); | ||
ctx.ErrorStatus(err); | ||
return null; | ||
} | ||
}); | ||
|
||
if (updatedFlightSubmission == null) | ||
{ | ||
return await _telemetryClient.TrackCommandEventAsync<Handler>(ProductId, -1, ct); | ||
} | ||
|
||
AnsiConsole.WriteLine(JsonSerializer.Serialize(updatedFlightSubmission, SourceGenerationContext.GetCustom(true).DevCenterFlightSubmission)); | ||
|
||
return await _telemetryClient.TrackCommandEventAsync<Handler>(ProductId, 0, 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
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