| 123456789101112131415161718192021222324252627282930313233343536373839 |
- using Admin.NET.Plugin.AiDOP.DataPlatform.Core;
- namespace Admin.NET.Plugin.AiDOP.DataPlatform.UnifiedIngress;
- /// <summary>Bridges the host's authenticated source binding to the independent ingress contract.</summary>
- public sealed class MdpIngestContractBinder(MdpIngestDatasetRegistry datasets) : ITransient
- {
- private static readonly PurchaseOrderSchemaRegistry BuiltIn = new();
- public async Task<PreparedIngestBatch> PrepareAsync(
- long tenantId, long factoryId, long sourceId, string datasetKey, ReadOnlyMemory<byte> payload, IngestLimits limits, long? configurationFactoryId = null,
- IngestPayloadFormat format = IngestPayloadFormat.Json, string? schemaVersion = null)
- {
- var binding = await datasets.ResolveActiveBindingAsync(tenantId, configurationFactoryId ?? factoryId, sourceId, datasetKey)
- ?? throw new IngestContractException(IngestContractError.DatasetUnavailable);
- if (schemaVersion is not null && !string.Equals(schemaVersion, binding.SourceSchemaVersion, StringComparison.Ordinal))
- throw new IngestContractException(IngestContractError.UnknownSchema);
- var identity = new IngestDatasetIdentity(binding.TenantId, factoryId, binding.SourceId,
- binding.DatasetId, binding.SourceCode, binding.DatasetKey);
- var contract = await ReadContractAsync(binding);
- return new IngestBatchPreparer(contract.Registry).Prepare(identity, binding.SourceSchemaVersion, payload.Span, limits, format: format);
- }
- internal async Task<(ISchemaRegistry Registry, IngestContract Contract)> ReadContractAsync(MdpIngestActiveBinding binding)
- {
- ISchemaRegistry registry = BuiltIn;
- if (BuiltIn.Find(binding.DatasetKey, binding.SourceSchemaVersion) == null)
- {
- var json = await datasets.ReadPublishedMapping(binding)
- ?? throw new IngestContractException(IngestContractError.UnknownSchema);
- registry = new PurchaseVersionConfiguration(binding.DatasetKey, binding.SourceSchemaVersion, json);
- }
- var contract = registry.Find(binding.DatasetKey, binding.SourceSchemaVersion)
- ?? throw new IngestContractException(IngestContractError.UnknownSchema);
- return (registry, contract);
- }
- }
|