Skip to content

Commit

Permalink
added routing table poco to config
Browse files Browse the repository at this point in the history
  • Loading branch information
janzenisek committed Jan 19, 2024
1 parent 2a531fd commit f3690bf
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/Configuration/Configurations/BrokerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class BrokerConfiguration : IConfiguration {
public string BaseTopic { get; set; }
public string PayloadType { get; set; }

public RoutingTable Routing { get; set; }

public BrokerConfiguration() {

Check warning on line 27 in src/Configuration/Configurations/BrokerConfiguration.cs

View workflow job for this annotation

GitHub Actions / Build, Test and (Publish if not pull request) 7.0.x

Non-nullable property 'Type' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 27 in src/Configuration/Configurations/BrokerConfiguration.cs

View workflow job for this annotation

GitHub Actions / Build, Test and (Publish if not pull request) 7.0.x

Non-nullable property 'Url' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 27 in src/Configuration/Configurations/BrokerConfiguration.cs

View workflow job for this annotation

GitHub Actions / Build, Test and (Publish if not pull request) 7.0.x

Non-nullable event 'ConfigurationChanged' must contain a non-null value when exiting constructor. Consider declaring the event as nullable.

Check warning on line 27 in src/Configuration/Configurations/BrokerConfiguration.cs

View workflow job for this annotation

GitHub Actions / Build, Test and (Publish if not pull request) 7.0.x

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 27 in src/Configuration/Configurations/BrokerConfiguration.cs

View workflow job for this annotation

GitHub Actions / Build, Test and (Publish if not pull request) 7.0.x

Non-nullable property 'Id' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

}
Expand Down
27 changes: 14 additions & 13 deletions src/Configuration/Configurations/SocketConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,31 @@ public class SocketConfiguration : IConfiguration {
public SubscriptionOptions DefaultSubscriptionOptions { get; set; }

public RequestOptions DefaultRequestOptions { get; set; }


public SocketConfiguration() {
public RoutingTable Routing { get; set; }

public SocketConfiguration() {
DefaultPublicationOptions = new PublicationOptions();
DefaultSubscriptionOptions = new SubscriptionOptions();
DefaultRequestOptions = new RequestOptions();
DefaultRequestOptions = new RequestOptions();
}

public object Clone() {
var c = new SocketConfiguration();

c.Type = Type;
c.Type = Type;
c.Url = Url;
c.MonitorConfiguration = MonitorConfiguration;
c.MonitorIntervalMilliseconds= MonitorIntervalMilliseconds;
c.Name= Name;
c.Id= Id;
c.SocketType= SocketType;
c.Broker= Broker;
c.BaseTopic= BaseTopic;
c.PayloadType= PayloadType;
c.MonitorIntervalMilliseconds = MonitorIntervalMilliseconds;
c.Name = Name;
c.Id = Id;
c.SocketType = SocketType;
c.Broker = Broker;
c.BaseTopic = BaseTopic;
c.PayloadType = PayloadType;
c.DefaultPublicationOptions = (PublicationOptions)DefaultPublicationOptions.Clone();
c.DefaultSubscriptionOptions= (SubscriptionOptions)DefaultSubscriptionOptions.Clone();
c.DefaultRequestOptions= (RequestOptions)DefaultRequestOptions.Clone();
c.DefaultSubscriptionOptions = (SubscriptionOptions)DefaultSubscriptionOptions.Clone();
c.DefaultRequestOptions = (RequestOptions)DefaultRequestOptions.Clone();

return c;
}
Expand Down
102 changes: 102 additions & 0 deletions src/Configuration/DataStructures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,106 @@ public SubscriptionOptions GetResponseSubscriptionOptions() {
}
}

public class RoutingTable : ICloneable {

private List<Edge> edges;
private List<Node> nodes;

public List<Edge> Edges {
get { return edges; }
private set { edges = value; }
}
public List<Node> Nodes {
get { return nodes; }
private set { nodes = value; }
}

public RoutingTable() {
edges = new List<Edge>();
nodes = new List<Node>();
}

public object Clone() {
var t = new RoutingTable();
t.nodes.AddRange(nodes.Select(x => (Node)x.Clone()));
t.edges.AddRange(edges.Select(x => (Edge)x.Clone()));

return t;
}

public RoutingTable ExtractForNode(string id) {
var t = new RoutingTable();

t.edges.AddRange(edges.Where(x => x.Source.Id == id || x.Sink.Id == id));
nodes.AddRange(t.edges.Select(x => x.Source));
nodes.AddRange(t.edges.Select(x => x.Sink));

return t;
}

public void AddNode(Node n) {
nodes.Add(n);
}

public void AddEdge(Edge e) {
edges.Add(e);
}

public void RemoveNode(string id) {
edges.RemoveAll(x => x.Source.Id == id || x.Sink.Id == id);
nodes.RemoveAll(x => x.Id == id);
}

public void RemoveEdge(string id) {
edges.RemoveAll(x => x.Source.Id == id || x.Sink.Id == id);
}
}

public class Edge : ICloneable {

public string Id { get; set; }
public Node Source { get; set; }
public Node Sink { get; set; }
public string Query { get; set; }

public Edge() { }
public Edge(string id, Node source, Node sink, string query = null) {

Check warning on line 208 in src/Configuration/DataStructures.cs

View workflow job for this annotation

GitHub Actions / Build, Test and (Publish if not pull request) 7.0.x

Cannot convert null literal to non-nullable reference type.
Id = id;
Source = source;
Sink = sink;
Query = query;
}

public object Clone() {
return new Edge(Id, Source, Sink, Query);
}

public string GetRoutingString(string delimiter) {
return $"{Source.Typename}{delimiter}{Source.Id}";
}
}

public class Node : ICloneable {
public string Id { get; set; }

public string Typename { get; set; }

public string FullyQualifiedTypename { get; set; }

public Node() { }

public Node(string id, string typename, string fullyQualifiedTypename) {
Id = id;
Typename = typename;
FullyQualifiedTypename = fullyQualifiedTypename;
}

public object Clone() {
return new Node(Id, Typename, FullyQualifiedTypename);
}

public string GetRoutingString(string delimiter) {
return $"{Typename}{delimiter}{Id}";
}
}
}
2 changes: 2 additions & 0 deletions src/Configuration/Parser/YamlParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public IConfiguration Parse(string uri) {

if(config.Type == "Socket") {
config = dser.Deserialize<SocketConfiguration>(doc);
} else if(config.Type == "Broker") {
config = dser.Deserialize<BrokerConfiguration>(doc);
}

config.Url = uri;
Expand Down

0 comments on commit f3690bf

Please sign in to comment.