Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Help.cs
1using System.Collections.Generic;
2using System.Text;
3using System.Threading.Tasks;
5
7{
11 public class Help : IAdminCommand
12 {
16 public Help()
17 {
18 }
19
23 public string Name => "Help";
24
28 public string[] Aliases => new string[] { "Menu", "?", "#" };
29
37 public bool AppliesTo(string CommandLine, string[] Arguments, out object Details)
38 {
39 Details = null;
40 return Arguments.Length <= 1;
41 }
42
51 public Task Execute(ChatState State, string[] Arguments, string OrgMessage, object Details, ResponseCallbackHandler ResponseCallback)
52 {
53 StringBuilder Markdown = new StringBuilder();
54
55 switch (Arguments.Length)
56 {
57 case 0:
58 Markdown.AppendLine("The following commands are available through the chat interface.");
59 Markdown.AppendLine("To get help about a specific command, type `help COMMAND`, where `COMMAND` is the name of the command you want more help about.");
60 Markdown.AppendLine();
61
62 bool First = true;
63
64 foreach (string Command in XmppServerModule.Instance.AdminCommands)
65 {
66 if (First)
67 First = false;
68 else
69 Markdown.Append(", ");
70
71 Markdown.Append('`');
72 Markdown.Append(Command);
73 Markdown.Append('`');
74 }
75
76 Markdown.AppendLine(".");
77 Markdown.AppendLine();
78
79 if (State.CommandMode)
80 {
81 Markdown.AppendLine("Any other sentence will be executed on the command prompt, and the response returned.");
82 Markdown.AppendLine();
83 Markdown.AppendLine("Additional commands (apart from normal DOS commands) in command mode:");
84 Markdown.AppendLine();
85 Markdown.AppendLine("| Additional commands in command mode ||");
86 Markdown.AppendLine("|:-----------------------------------------|:----|");
87 Markdown.AppendLine("| `analyzeclock ...` | Executes `Waher.Utility.AnalyzeClock` with the provided parameters. |");
88 Markdown.AppendLine("| `csp ...` | Executes `Waher.Utility.Csp` with the provided parameters. |");
89 Markdown.AppendLine("| `exstat ...` | Executes `Waher.Utility.ExStat` with the provided parameters. |");
90 Markdown.AppendLine("| `extract ...` | Executes `Waher.Utility.Extract` with the provided parameters. |");
91 Markdown.AppendLine("| `install ...` | Executes `Waher.Utility.Install` with the provided parameters. |");
92 Markdown.AppendLine("| `regex ...` | Executes `Waher.Utility.RegEx` with the provided parameters. |");
93 Markdown.AppendLine("| `sign ...` | Executes `Waher.Utility.Sign` with the provided parameters. |");
94 Markdown.AppendLine("| `transform ...` | Executes `Waher.Utility.Transform` with the provided parameters. |");
95 }
96 else
97 Markdown.AppendLine("Any other sentence will be executed as [script](" + Gateway.GetUrl("/Script.md") + "), and the response returned.");
98 break;
99
100 case 1:
101 if (XmppServerModule.Instance.TryGetAdminCommand(Arguments[0].ToLower(), out LinkedList<IAdminCommand> Commands))
102 {
103 foreach (IAdminCommand Command in Commands)
104 {
105 foreach (HelpItem Help in Command.GetHelp())
106 {
107 Markdown.Append('`');
108 Markdown.Append(Help.Syntax);
109 Markdown.AppendLine("`");
110 Markdown.AppendLine();
111
112 foreach (string Paragraph in Help.Paragraphs)
113 {
114 Markdown.Append(':');
115 Markdown.Append('\t');
116 Markdown.AppendLine(Paragraph);
117 Markdown.AppendLine();
118 }
119 }
120 }
121 }
122 else
123 Markdown.Append("Command not recognized. No help available.");
124 break;
125 }
126
127 return ResponseCallback(Markdown.ToString(), string.Empty);
128 }
129
134 public HelpItem[] GetHelp()
135 {
136 return new HelpItem[]
137 {
138 new HelpItem("help", "Gets help about available commands."),
139 new HelpItem("help COMMAND", "Gets help about a specific command named `COMMAND`.")
140 };
141 }
142
143 }
144}
Static class managing the runtime environment of the IoT Gateway.
Definition: Gateway.cs:126
static string GetUrl(string LocalResource)
Gets a URL for a resource.
Definition: Gateway.cs:4167
bool CommandMode
Shell Command mode (true), or internal mode (false, default).
Definition: ChatState.cs:21
HelpItem[] GetHelp()
Gets help about the command.
Definition: Help.cs:134
Task Execute(ChatState State, string[] Arguments, string OrgMessage, object Details, ResponseCallbackHandler ResponseCallback)
Executes the command.
Definition: Help.cs:51
string[] Aliases
Optional set of aliases. Can be null.
Definition: Help.cs:28
bool AppliesTo(string CommandLine, string[] Arguments, out object Details)
If the command is applicable to the given command line.
Definition: Help.cs:37
Contains an item of information about a command.
Definition: HelpItem.cs:9
Service Module hosting the XMPP broker and its components.
Basic interface for administration commands
delegate Task< string > ResponseCallbackHandler(string Markdown, string MessageId)
Delegate for response callback handler methods.