Renamed namespaces and projects from DocumentOperator to DocumentService, updating all references accordingly. Refactored PdfSignatureAppearanceDto and related enums to use properties with init accessors for improved clarity. Removed and re-added IPkcs11SelfTestStatusProvider with updated namespace. Simplified dependency injection by removing DocumentOperatorApplication registration. Updated appsettings.json with a specific AssetsRootPath. Incremented version numbers in project files for a new release. Introduced PdfSignatureClient and IPdfSignatureClient for PDF digital-signing operations. Updated project files to use newer Microsoft.Extensions package versions. Removed all DocumentOperator references, completing the transition to DocumentService. Added new DTOs and enums for PDF signature options and appearance.
98 lines
3.7 KiB
C#
98 lines
3.7 KiB
C#
using DocumentService.Client.Configuration;
|
|
using DocumentService.Client.Extensions;
|
|
using DocumentService.Client.Interfaces;
|
|
using DocumentService.Client.Models.ValueObjects;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DocumentService.Client;
|
|
|
|
/// <summary>
|
|
/// Static entry point for configuring and building the DocumentService client.
|
|
/// </summary>
|
|
public static class Client
|
|
{
|
|
private static Action<DocumentServiceClientOptions> Options { get; set; } = null!;
|
|
|
|
private static readonly Lazy<IServiceProvider> LazyProvider = new(() =>
|
|
{
|
|
var services = new ServiceCollection();
|
|
services.AddDocumentServiceClients(Options);
|
|
return services.BuildServiceProvider();
|
|
});
|
|
|
|
public static bool IsConfigured => LazyProvider.IsValueCreated;
|
|
|
|
public static OnReconfigure OnReconfigure { get; set; } = OnReconfigure.ThrowException;
|
|
|
|
/// <summary>
|
|
/// Configures the client using a full <see cref="DocumentServiceClientOptions"/> action.
|
|
/// </summary>
|
|
/// <param name="configuration">Action that configures the client options.</param>
|
|
public static void Configure(Action<DocumentServiceClientOptions> configuration)
|
|
{
|
|
if(IsConfigured)
|
|
switch (OnReconfigure)
|
|
{
|
|
case OnReconfigure.ThrowException:
|
|
throw new InvalidOperationException("DocumentService.Client is already configured. Reconfiguration is not allowed.");
|
|
case OnReconfigure.Ignore:
|
|
return;
|
|
}
|
|
Options = configuration;
|
|
_ = LazyProvider.Value; // init service provider
|
|
}
|
|
|
|
/// <summary>
|
|
/// Configures the client with only a base URL. Use the overload with options action for full control.
|
|
/// </summary>
|
|
/// <param name="baseUrl">Base URL of the DocumentService API.</param>
|
|
public static void Configure(string baseUrl)
|
|
{
|
|
if (IsConfigured)
|
|
switch (OnReconfigure)
|
|
{
|
|
case OnReconfigure.ThrowException:
|
|
throw new InvalidOperationException("DocumentService.Client is already configured. Reconfiguration is not allowed.");
|
|
case OnReconfigure.Ignore:
|
|
return;
|
|
}
|
|
|
|
Options = options => {
|
|
options = new DocumentServiceClientOptions
|
|
{
|
|
BaseUrl = baseUrl
|
|
};
|
|
};
|
|
_ = LazyProvider.Value; // init service provider
|
|
}
|
|
|
|
private static IServiceProvider Provider => IsConfigured
|
|
? LazyProvider.Value
|
|
: throw new InvalidOperationException("DocumentService.Client is not configured.");
|
|
|
|
private static T GetRequiredServiceOfScope<T>() where T : notnull => Provider.CreateAsyncScope().ServiceProvider.GetRequiredService<T>();
|
|
|
|
#region Controllers
|
|
public static IPdfAttachmentClient Attachment => GetRequiredServiceOfScope<IPdfAttachmentClient>();
|
|
|
|
public static IPdfConversionClient Conversion => GetRequiredServiceOfScope<IPdfConversionClient>();
|
|
|
|
public static IPdfOperationsClient Operations => GetRequiredServiceOfScope<IPdfOperationsClient>();
|
|
|
|
public static IPdfValidationClient Validation => GetRequiredServiceOfScope<IPdfValidationClient>();
|
|
|
|
public static ISwissQrCodeClient SwissQrCode => GetRequiredServiceOfScope<ISwissQrCodeClient>();
|
|
|
|
public static IZugferdClient Zugferd => GetRequiredServiceOfScope<IZugferdClient>();
|
|
|
|
public static IPdfSignatureClient Signature => GetRequiredServiceOfScope<IPdfSignatureClient>();
|
|
|
|
public static IWorkflowsClient Workflows => GetRequiredServiceOfScope<IWorkflowsClient>();
|
|
#endregion
|
|
}
|