Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/Particular.LicensingComponent/WebApi/LicensingController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Particular.LicensingComponent.WebApi
{
using System.IO.Compression;
using System.Text.Json;
using System.Threading;
using Contracts;
Expand Down Expand Up @@ -42,17 +43,28 @@ public async Task<ReportGenerationState> CanThroughputReportBeGenerated(Cancella
public async Task<IActionResult> GetThroughputReportFile([FromQuery(Name = "spVersion")] string? spVersion, CancellationToken cancellationToken)
{
var reportStatus = await CanThroughputReportBeGenerated(cancellationToken);
if (reportStatus.ReportCanBeGenerated)
if (!reportStatus.ReportCanBeGenerated)
{
var report = await throughputCollector.GenerateThroughputReport(
spVersion ?? "Unknown",
null,
cancellationToken);
return BadRequest($"Report cannot be generated - {reportStatus.Reason}");
}

var report = await throughputCollector.GenerateThroughputReport(
spVersion ?? "Unknown",
null,
cancellationToken);

return File(JsonSerializer.SerializeToUtf8Bytes(report, SerializationOptions.IndentedWithNoEscaping), "application/json", fileDownloadName: $"{report.ReportData.CustomerName}.throughput-report-{report.ReportData.EndTime:yyyyMMdd-HHmmss}.json");
var fileName = $"{report.ReportData.CustomerName}.throughput-report-{report.ReportData.EndTime:yyyyMMdd-HHmmss}";

using var memoryStream = new MemoryStream();
using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
{
var entry = archive.CreateEntry($"{fileName}.json");
await using var entryStream = entry.Open();
await JsonSerializer.SerializeAsync(entryStream, report, SerializationOptions.IndentedWithNoEscaping, cancellationToken);
}

return BadRequest($"Report cannot be generated - {reportStatus.Reason}");
memoryStream.Position = 0;
return File(memoryStream, "application/zip", fileDownloadName: $"{fileName}.zip");
}

[Route("settings/info")]
Expand Down