Refactored `DocumentService.GetDocumentAsync` to throw `HttpRequestException` on failure instead of returning a tuple. Updated all consumers to handle exceptions, improving error handling consistency across the application. Enhanced error messages for better user feedback and added logging for improved traceability. Updated `EnvelopeReceiverPage`, `EnvelopeReceiverPage_DxReportViewer`, and `ReportViewer` to use the new exception-based API and handle errors gracefully. This change simplifies the API, improves maintainability, and makes the application more robust and user-friendly.
59 lines
2.2 KiB
Plaintext
59 lines
2.2 KiB
Plaintext
@page "/envelope/{EnvelopeKey}/DxReportViewer"
|
|
@using XtraReport = DevExpress.XtraReports.UI.XtraReport
|
|
@using DevExpress.Blazor.Reporting
|
|
@using Microsoft.Extensions.Options
|
|
@using EnvelopeGenerator.ReceiverUI.Options
|
|
@using EnvelopeGenerator.ReceiverUI.Services
|
|
@inject InMemoryReportStorageWebExtension ReportStorage
|
|
@inject DocumentService DocumentService
|
|
@inject IOptions<ApiOptions> AppOptions
|
|
|
|
<link href="_content/DevExpress.Blazor.Themes/blazing-berry.bs5.min.css" rel="stylesheet" />
|
|
<link href="_content/DevExpress.Blazor.Reporting.Viewer/css/dx-blazor-reporting-components.bs5.css" rel="stylesheet" />
|
|
|
|
|
|
@if (Report is not null) {
|
|
<DxReportViewer Report="Report" RootCssClasses="w-100 h-100" Zoom="1.3" />
|
|
}
|
|
|
|
@code {
|
|
[Parameter] public string EnvelopeKey { get; set; } = string.Empty;
|
|
|
|
XtraReport Report { get; set; } = null!;
|
|
|
|
byte[] BasePdfBytes { get; set; } = null!;
|
|
|
|
protected override async Task OnInitializedAsync() {
|
|
if (!AppOptions.Value.UsePredefinedReports) {
|
|
try {
|
|
var pdfBytes = await DocumentService.GetDocumentAsync(EnvelopeKey);
|
|
if (pdfBytes is { Length: > 0 })
|
|
BasePdfBytes = pdfBytes;
|
|
else
|
|
throw new InvalidOperationException($"No PDF bytes found for EnvelopeKey: {EnvelopeKey}");
|
|
} catch (HttpRequestException ex) {
|
|
throw new InvalidOperationException($"Failed to load document for EnvelopeKey: {EnvelopeKey}", ex);
|
|
}
|
|
}
|
|
|
|
Report = CreateReport();
|
|
}
|
|
|
|
XtraReport CreateReport()
|
|
{
|
|
if (AppOptions.Value.UsePredefinedReports)
|
|
{
|
|
return ReportStorage.TryGetReport("LargeDatasetReport", out var savedReport)
|
|
? savedReport
|
|
: PredefinedReports.ReportsFactory.GetReport("LargeDatasetReport");
|
|
}
|
|
else
|
|
{
|
|
var report = new XtraReport();
|
|
var detail = new DevExpress.XtraReports.UI.DetailBand();
|
|
report.Bands.Add(detail);
|
|
detail.Controls.Add(new DevExpress.XtraReports.UI.XRPdfContent { Source = BasePdfBytes, GenerateOwnPages = true });
|
|
return report;
|
|
}
|
|
}
|
|
} |