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;
8
10{
17 public class S2sGraph : CommandRegEx
18 {
25 public S2sGraph()
26 : base(@"^s2sgraph\s*.*$")
27 {
28 }
29
33 public override string Name => "S2SGraph";
34
43 public override async Task Execute(ChatState State, string[] Arguments, string OrgMessage, Match Details,
44 ResponseCallbackHandler ResponseCallback)
45 {
46 string Script = OrgMessage.Substring(8).Trim();
47 object Result;
48 SKColor Color;
49
50 if (string.IsNullOrEmpty(Script))
51 {
52 Result = null;
53 Color = SKColors.Empty;
54 }
55 else
56 {
57 Expression Exp = new Expression(Script);
58 Result = await Exp.EvaluateAsync(State.Session);
59 Result = TopologyQuery.Simplify(Result, out Color);
60 }
61
62 StringBuilder sb = new StringBuilder();
63 string Title = Gateway.HasDomain ? Gateway.Domain.Value : Gateway.XmppClient.BareJID;
64
65 sb.AppendLine("```dot");
66 sb.AppendLine("digraph G {");
67 sb.AppendLine("rankdir=LR");
68
69 TopologyQuery.EmbedResult(sb, Title, Result, Color);
70
71 foreach (EndpointStatistics Stat in XmppServerModule.GetServerConnectionStatistics())
72 {
73 sb.Append('"');
74 sb.Append(Title);
75 sb.Append("\" -> \"");
76 sb.Append(Stat.Name);
77 sb.Append('"');
78
79 if (Stat.Type != "XMPP")
80 {
81 sb.Append(" [label=\"");
82 sb.Append(Stat.Type);
83 sb.Append("\"]");
84 }
85
86 sb.AppendLine(";");
87 }
88
89 sb.AppendLine("}");
90 sb.AppendLine("```");
91
92 await ResponseCallback(sb.ToString(), string.Empty);
93 }
94
98 public override HelpItem[] GetHelp()
99 {
100 return new HelpItem[]
101 {
102 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.")
103 };
104 }
105 }
106}
Static class managing the runtime environment of the IoT Gateway.
Definition: Gateway.cs:147
static XmppClient XmppClient
XMPP Client connection of gateway.
Definition: Gateway.cs:4038
Mainstains information about connectivity from a specific endpoint.
Class managing a script expression.
Definition: Expression.cs:41
async Task< object > EvaluateAsync(Variables Variables)
Evaluates the expression, using the variables provided in the Variables collection....
Definition: Expression.cs:4461
readonly Variables Session
Session variables
Definition: ChatState.cs:49
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:18
override HelpItem[] GetHelp()
Markdown description of syntax.
Definition: S2sGraph.cs:98
S2sGraph()
Returns a GraphViz graph of the current broker and how it is connected to other federated brokers....
Definition: S2sGraph.cs:25
override async Task Execute(ChatState State, string[] Arguments, string OrgMessage, Match Details, ResponseCallbackHandler ResponseCallback)
Executes the command.
Definition: S2sGraph.cs:43
override string Name
Command name
Definition: S2sGraph.cs:33
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.