namespace Bts.PubSub.Routing; using BCG; using bts; using System.Collections.Generic; using System.Linq; public class PubSubRoutingConfig : ICloneable { public List? PublisherRoutes { get; set; } public List? SubscriberRoutes { get; set; } public void MergeWith(PubSubRoutingConfig other) { PublisherRoutes = MergeRoutes(PublisherRoutes, other.PublisherRoutes); SubscriberRoutes = MergeRoutes(SubscriberRoutes, other.SubscriberRoutes); List? MergeRoutes(List? routes, List? otherRoutes) { if (otherRoutes is null) { return routes; } if (routes is null) { return otherRoutes; } foreach (var route in otherRoutes) { if (!routes.Any(r => r.TagRegExp == route.TagRegExp || r.Name == route.Name)) { routes.Add(route); } } return routes; } } public PubSubRoutingConfig Clone() => new() { PublisherRoutes = PublisherRoutes?.Select(r => r.Clone()).ToList(), SubscriberRoutes = SubscriberRoutes?.Select(r => r.Clone()).ToList(), }; }