Add signature caching and logging to EnvelopeViewer
Introduced `SignatureCacheService` and `ILogger<EnvelopeViewer>` to enable caching and logging functionality. Added logic to load cached signatures when available, bypassing the signature popup. Implemented asynchronous, fire-and-forget caching of captured signatures, with error handling to ignore cache failures. Updated signature handling to integrate with the caching mechanism, improving user experience and performance.
This commit is contained in:
@@ -12,9 +12,11 @@
|
|||||||
@inject IOptions<PdfViewerOptions> PdfViewerOptions
|
@inject IOptions<PdfViewerOptions> PdfViewerOptions
|
||||||
@inject IJSRuntime JSRuntime
|
@inject IJSRuntime JSRuntime
|
||||||
@inject SignatureService SignatureService
|
@inject SignatureService SignatureService
|
||||||
|
@inject SignatureCacheService SignatureCacheService
|
||||||
@inject EnvelopeGenerator.ReceiverUI.Services.AuthService AuthService
|
@inject EnvelopeGenerator.ReceiverUI.Services.AuthService AuthService
|
||||||
@inject EnvelopeGenerator.ReceiverUI.Services.EnvelopeReceiverService EnvelopeReceiverService
|
@inject EnvelopeGenerator.ReceiverUI.Services.EnvelopeReceiverService EnvelopeReceiverService
|
||||||
@inject AppVersionService AppVersion
|
@inject AppVersionService AppVersion
|
||||||
|
@inject ILogger<EnvelopeViewer> logger
|
||||||
@implements IAsyncDisposable
|
@implements IAsyncDisposable
|
||||||
|
|
||||||
<link href="_content/DevExpress.Blazor.Themes/blazing-berry.bs5.min.css" rel="stylesheet" />
|
<link href="_content/DevExpress.Blazor.Themes/blazing-berry.bs5.min.css" rel="stylesheet" />
|
||||||
@@ -563,10 +565,34 @@ const int MaxThumbnailWidth = 400;
|
|||||||
|
|
||||||
await JSRuntime.InvokeVoidAsync("console.log", "Loaded signatures:", _signatures);
|
await JSRuntime.InvokeVoidAsync("console.log", "Loaded signatures:", _signatures);
|
||||||
|
|
||||||
// Open signature popup on page load
|
// Try to load cached signature first
|
||||||
_activeSignatureTab = SignatureTabDraw;
|
try
|
||||||
_signaturePopupVisible = true;
|
{
|
||||||
_popupValidationMessage = null;
|
var cachedSignature = await SignatureCacheService.GetSignatureAsync(EnvelopeKey);
|
||||||
|
if (cachedSignature is not null)
|
||||||
|
{
|
||||||
|
_capturedSignature = cachedSignature;
|
||||||
|
_signerFullName = cachedSignature.FullName;
|
||||||
|
_signerPosition = cachedSignature.Position;
|
||||||
|
_signaturePlace = cachedSignature.Place;
|
||||||
|
_signaturePopupVisible = false;
|
||||||
|
|
||||||
|
logger.LogInformation("Cached signature loaded for envelope {EnvelopeKey}", EnvelopeKey);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_activeSignatureTab = SignatureTabDraw;
|
||||||
|
_signaturePopupVisible = true;
|
||||||
|
_popupValidationMessage = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger.LogWarning(ex, "Failed to load cached signature, showing popup");
|
||||||
|
_activeSignatureTab = SignatureTabDraw;
|
||||||
|
_signaturePopupVisible = true;
|
||||||
|
_popupValidationMessage = null;
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
_errorMessage = $"Fehler: {ex.Message}";
|
_errorMessage = $"Fehler: {ex.Message}";
|
||||||
@@ -881,6 +907,22 @@ const int MaxThumbnailWidth = 400;
|
|||||||
};
|
};
|
||||||
_signaturePopupVisible = false;
|
_signaturePopupVisible = false;
|
||||||
|
|
||||||
|
// Save to cache (fire-and-forget, ignore errors)
|
||||||
|
if (!string.IsNullOrWhiteSpace(EnvelopeKey))
|
||||||
|
{
|
||||||
|
_ = Task.Run(async () =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await SignatureCacheService.SaveSignatureAsync(EnvelopeKey, _capturedSignature);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// Ignore cache errors
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
await InvokeAsync(StateHasChanged);
|
await InvokeAsync(StateHasChanged);
|
||||||
Console.WriteLine($"Signature saved: {_signerFullName}, {_signaturePlace}");
|
Console.WriteLine($"Signature saved: {_signerFullName}, {_signaturePlace}");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user