Introduced new models (`SignatureDto`, `SignatureCaptureDto`, `EnvelopeReceiverDto`) to support a signature-based workflow. Added services for handling API interactions (`SignatureService`, `AuthService`, `DocumentService`, `EnvelopeReceiverService`, `SignatureCacheService`). Enhanced configuration with `ApiOptions` and `PdfViewerOptions`. Integrated DevExpress features with custom data connection providers, in-memory report storage, and font loading utilities. Marked `AnnotationDto` and `AnnotationService` as `[Obsolete]` in favor of newer implementations. Added detailed documentation for coordinate systems, unit conversions, and usage scenarios.
67 lines
2.3 KiB
C#
67 lines
2.3 KiB
C#
using System.Net.Http.Json;
|
|
using Microsoft.Extensions.Options;
|
|
using EnvelopeGenerator.WebUI.Client.Options;
|
|
using EnvelopeGenerator.WebUI.Client.Models;
|
|
|
|
namespace EnvelopeGenerator.WebUI.Client.Services;
|
|
|
|
/// <summary>
|
|
/// Client service for managing cached signatures via API.
|
|
/// </summary>
|
|
public class SignatureCacheService(HttpClient http, IOptions<ApiOptions> apiOptions)
|
|
{
|
|
private readonly ApiOptions _api = apiOptions.Value;
|
|
|
|
public async Task SaveSignatureAsync(
|
|
string envelopeKey,
|
|
SignatureCaptureDto signature,
|
|
CancellationToken cancel = default)
|
|
{
|
|
var response = await http.PostAsJsonAsync(
|
|
$"{_api.BaseUrl}/api/Cache/SignatureCapture/{Uri.EscapeDataString(envelopeKey)}",
|
|
signature,
|
|
cancel);
|
|
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
var error = await response.Content.ReadAsStringAsync(cancel);
|
|
throw new HttpRequestException($"Failed to cache signature: {response.StatusCode} - {error}");
|
|
}
|
|
}
|
|
|
|
public async Task<SignatureCaptureDto?> GetSignatureAsync(
|
|
string envelopeKey,
|
|
CancellationToken cancel = default)
|
|
{
|
|
var response = await http.GetAsync(
|
|
$"{_api.BaseUrl}/api/Cache/SignatureCapture/{Uri.EscapeDataString(envelopeKey)}",
|
|
cancel);
|
|
|
|
if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
|
|
return null;
|
|
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
var error = await response.Content.ReadAsStringAsync(cancel);
|
|
throw new HttpRequestException($"Failed to retrieve signature: {response.StatusCode} - {error}");
|
|
}
|
|
|
|
return await response.Content.ReadFromJsonAsync<SignatureCaptureDto>(cancellationToken: cancel);
|
|
}
|
|
|
|
public async Task DeleteSignatureAsync(
|
|
string envelopeKey,
|
|
CancellationToken cancel = default)
|
|
{
|
|
var response = await http.DeleteAsync(
|
|
$"{_api.BaseUrl}/api/Cache/SignatureCapture/{Uri.EscapeDataString(envelopeKey)}",
|
|
cancel);
|
|
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
var error = await response.Content.ReadAsStringAsync(cancel);
|
|
throw new HttpRequestException($"Failed to delete signature: {response.StatusCode} - {error}");
|
|
}
|
|
}
|
|
}
|