Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public record LicensedEndpoint
public string ClientId { get; set; } = Guid.NewGuid().ToString();
public required string Name { get; set; }
public required int Classification { get; set; }
public bool Amended { get; set; } = false;
public string? EndpointSize { get; set; }

public QueueIdentity[] Queues { get; set; } = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public Task SaveLicensedEndpointDetails(LicensedEndpointDetails result, Cancella

public Task SaveLicensedEndpointDetailsAmendment(LicensedEndpointDetailsAmendment? result, CancellationToken cancellationToken = default)
{
result?.UnmappedQueues = [.. endpointDetailsAmendment?.UnmappedQueues ?? [], .. result.UnmappedQueues];
result.MergeWithExisting(endpointDetailsAmendment);
endpointDetailsAmendment = result;
return Task.CompletedTask;
}
Expand Down
15 changes: 15 additions & 0 deletions src/Particular.LicensingComponent.Persistence/LicenseMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ .. baseDetails.Endpoints.Where(endpoint => !amendments.RemovedEndpointIds.Contai
{
Name = amendment?.Name ?? endpoint.Name,
Classification = amendment?.Classification ?? endpoint.Classification,
Amended = amendment is not null,
Queues = [.. endpoint.Queues.Except(
[
.. amendments.UnassignedQueues,
Expand All @@ -64,5 +65,19 @@ .. amendments.Endpoints.Where(endpoint => !baseDetails.Endpoints.Any(baseEndpoin
return baseDetails;
}
}

extension(LicensedEndpointDetailsAmendment? amendment)
{
public void MergeWithExisting(LicensedEndpointDetailsAmendment? existing)
{
if (amendment is null || existing is null)
{
return;
}

// these do not round-trip the full collections, so reapply what we already have
amendment.UnmappedQueues = [.. existing.UnmappedQueues, .. amendment.UnmappedQueues];
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,7 @@ public Task SaveLicensedEndpointDetailsAmendment(LicensedEndpointDetailsAmendmen
await context.SaveChangesAsync(cancellationToken);
return;
}
// these do not round-trip
result.UnmappedQueues = [.. existing.UnmappedQueues, .. result.UnmappedQueues];
result.MergeWithExisting(existing);
}
await context.StoreSetting(SettingKeys.LicensedEndpointDetailsAmendment, result, token);
}, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,7 @@ public async Task SaveLicensedEndpointDetailsAmendment(LicensedEndpointDetailsAm
var existing = await session.LoadAsync<LicensedEndpointDetailsAmendment>(LicencedEndpointDetailsAmendmentDocumentId, cancellationToken);
if (existing is not null)
{
// these do not round-trip
result.UnmappedQueues = [.. existing.UnmappedQueues, .. result.UnmappedQueues];
result.MergeWithExisting(existing);
session.Advanced.Evict(existing);
}

Expand Down
Loading