Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
S2sGraph.cs
1using System.Text;
2using System.Threading.Tasks;
3using SkiaSharp;
4using Waher.Script;
6using System.Text.RegularExpressions;
7
9{
16 public class S2sGraph : CommandRegEx
17 {
24 public S2sGraph()
25 : base(@"^s2sgraph\s*.*$")
26 {
27 }
28
32 public override string Name => "S2SGraph";
33
42 public override async Task Execute(ChatState State, string[] Arguments, string OrgMessage, Match Details,
43 ResponseCallbackHandler ResponseCallback)
44 {
45 string Script = OrgMessage.Substring(8).Trim();
46 object Result;
47 SKColor Color;
48
49 if (string.IsNullOrEmpty(Script))
50 {
51 Result = null;
52 Color = SKColors.Empty;
53 }
54 else
55 {
56 Expression Exp = new Expression(Script);
57 Result = await Exp.EvaluateAsync(State.Session);
58 Result = TopologyQuery.Simplify(Result, out Color);
59 }
60
61 StringBuilder sb = new StringBuilder();
62 string Title = string.IsNullOrEmpty(IoTGateway.Gateway.Domain) ? IoTGateway.Gateway.XmppClient.BareJID : IoTGateway.Gateway.Domain.Value;
63
64 sb.AppendLine("```dot");
65 sb.AppendLine("digraph G {");
66 sb.AppendLine("rankdir=LR");
67
68 TopologyQuery.EmbedResult(sb, Title, Result, Color);
69
70 foreach (EndpointStatistics Stat in XmppServerModule.GetServerConnectionStatistics())
71 {
72 sb.Append('"');
73 sb.Append(Title);
74 sb.Append("\" -> \"");
75 sb.Append(Stat.Name);
76 sb.Append("\"");
77
78 if (Stat.Type != "XMPP")
79 {
80 sb.Append(" [label=\"");
81 sb.Append(Stat.Type);
82 sb.Append("\"]");
83 }
84
85 sb.AppendLine(";");
86 }
87
88 sb.AppendLine("}");
89 sb.AppendLine("```");
90
91 await ResponseCallback(sb.ToString(), string.Empty);
92 }
93
97 public override HelpItem[] GetHelp()
98 {
99 return new HelpItem[]
100 {
101 new HelpItem("S2SGraph[ SCRIPT]", "Returns a GraphViz graph of the current broker and how it is connected to other federated brokers. Such a graph illustrates the federated network. Optional script can be provided, and its result embedded in the graph. Consolidating responses from multiple brokers generates a S2S graph of all brokers.")
102 };
103 }
104 }
105}
Mainstains information about connectivity from a specific endpoint.
Class managing a script expression.
Definition: Expression.cs:39
async Task< object > EvaluateAsync(Variables Variables)
Evaluates the expression, using the variables provided in the Variables collection....
Definition: Expression.cs:4275
readonly Variables Session
Session variables
Definition: ChatState.cs:41
An administrative command whose syntax is validated with a regular expression.
Definition: CommandRegEx.cs:12
Contains an item of information about a command.
Definition: HelpItem.cs:9
Returns a GraphViz graph of the current broker and how it is connected to other federated brokers....
Definition: S2sGraph.cs:17
override HelpItem[] GetHelp()
Markdown description of syntax.
Definition: S2sGraph.cs:97
S2sGraph()
Returns a GraphViz graph of the current broker and how it is connected to other federated brokers....
Definition: S2sGraph.cs:24
override async Task Execute(ChatState State, string[] Arguments, string OrgMessage, Match Details, ResponseCallbackHandler ResponseCallback)
Executes the command.
Definition: S2sGraph.cs:42
override string Name
Command name
Definition: S2sGraph.cs:32
Executes script (if provided), and returns the result in the form of a GraphViz graph of the current ...
Service Module hosting the XMPP broker and its components.
delegate Task< string > ResponseCallbackHandler(string Markdown, string MessageId)
Delegate for response callback handler methods.