Catalog/Catalog.Communication/DependencyInjection/CatalogCommunicationServiceCollectionExtensions.cs
MaddoScientisto 15b1da4371 feat: Add race upload functionality and file transfer endpoints
- Implemented IRaceUploadCommunicationClient with methods for saving races, creating race points, indexing race points, retrieving race details, and uploading files to the receiver.
- Added ReceiveFilePath option to CatalogCommunicationOptions for file transfer configuration.
- Enhanced CatalogCommunicationServiceCollectionExtensions to validate ReceiveFilePath.
- Developed RaceUploadCommunicationClient to handle race-related API interactions, including saving race data and uploading processed images.
- Updated API documentation to reflect new race upload and file transfer endpoints.
- Modified Avalonia UI to support race creation and processed image uploads, including new input fields and buttons.
- Introduced RaceSaveRequest and ReceiveFileUploadRequest models for structured data handling.
2026-02-28 16:54:08 +01:00

47 lines
2.1 KiB
C#

using System.Net;
using Catalog.Communication.Abstractions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
namespace Catalog.Communication.DependencyInjection;
public static class CatalogCommunicationServiceCollectionExtensions
{
public static IServiceCollection AddCatalogCommunication(this IServiceCollection services, Action<CatalogCommunicationOptions> configure)
{
ArgumentNullException.ThrowIfNull(services);
ArgumentNullException.ThrowIfNull(configure);
services
.AddOptions<CatalogCommunicationOptions>()
.Configure(configure)
.Validate(o => o.BaseUri is not null, "CatalogCommunicationOptions.BaseUri is required.")
.Validate(o => !string.IsNullOrWhiteSpace(o.AdminPageBasePath), "AdminPageBasePath is required.")
.Validate(o => !string.IsNullOrWhiteSpace(o.ReceiveFilePath), "ReceiveFilePath is required.")
.Validate(o => o.RequestTimeout > TimeSpan.Zero, "RequestTimeout must be greater than zero.")
.Validate(o => o.RetryCount >= 0 && o.RetryCount <= 10, "RetryCount must be between 0 and 10.")
.Validate(o => o.RetryBaseDelay > TimeSpan.Zero, "RetryBaseDelay must be greater than zero.");
services.TryAddSingleton<CookieContainer>();
services
.AddHttpClient<IRaceUploadCommunicationClient, RaceUploadCommunicationClient>((sp, client) =>
{
var options = sp.GetRequiredService<IOptions<CatalogCommunicationOptions>>().Value;
client.BaseAddress = options.BaseUri;
})
.ConfigurePrimaryHttpMessageHandler(sp =>
{
var cookieContainer = sp.GetRequiredService<CookieContainer>();
return new HttpClientHandler
{
UseCookies = true,
CookieContainer = cookieContainer,
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate | DecompressionMethods.Brotli,
};
});
return services;
}
}