Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Auto.cs
1using System.Text.RegularExpressions;
2using System.Threading.Tasks;
3using Waher.Content;
5
7{
11 public class Auto : CommandRegEx
12 {
16 public Auto()
17 : base(@"^auto(\s+(content\s+(0|1)|\d+))?$")
18 {
19 }
20
24 public override string Name => "Auto";
25
34 public override async Task Execute(ChatState State, string[] Arguments, string OrgMessage, Match Details,
35 ResponseCallbackHandler ResponseCallback)
36 {
37 long Delay;
38 bool InstallContentOnly;
39
40 Delay = await RuntimeSettings.GetAsync(XmppServerModule.AutoInstallDelayParameterName, 0);
41 InstallContentOnly = await RuntimeSettings.GetAsync(XmppServerModule.AutoInstallContentOnlyParameterName, false);
42
43 if (Arguments.Length > 0)
44 {
45 bool ContentOnly = Arguments.Length == 2;
46
47 if (ContentOnly)
48 {
49 if (!CommonTypes.TryParse(Arguments[1], out bool b))
50 await XmppServerModule.SendErrorMessage("Expected 0 or 1.", string.Empty, ResponseCallback);
51
52 InstallContentOnly = b;
53
54 await RuntimeSettings.SetAsync(XmppServerModule.AutoInstallContentOnlyParameterName, InstallContentOnly);
55 }
56 else
57 {
58 Delay = long.Parse(Arguments[0]);
59 if (Delay < 0)
60 await XmppServerModule.SendErrorMessage("Invalid delay.", string.Empty, ResponseCallback);
61
62 await RuntimeSettings.SetAsync(XmppServerModule.AutoInstallDelayParameterName, Delay);
63 }
64 }
65
66 if (Delay <= 0 || Delay >= int.MaxValue)
67 await ResponseCallback("Auto-installation of new packages not activated.", string.Empty);
68 else
69 await ResponseCallback("New packages will be installed " + Delay.ToString() + " minutes after receiving a new package.", string.Empty);
70
71 if (InstallContentOnly)
72 await ResponseCallback("New content-only packages will be installed when received.", string.Empty);
73 else
74 await ResponseCallback("Content-only packages are processed as other packages.", string.Empty);
75 }
76
81 public override HelpItem[] GetHelp()
82 {
83 return new HelpItem[]
84 {
85 new HelpItem("auto", "Displays if automatic updating of the broker is enabled, and the current delay between receiving an update, and the actual update, during which the installation can be cancelled using the `cancel` command."),
86 new HelpItem("auto 0", "Automatic software updates are disabled (default)."),
87 new HelpItem("auto DELAY_MIN", "If positive, the broker will be automatically updated after waiting this number of minutes after receiving a new validated software package."),
88 new HelpItem("auto content 0", "Content-only packages are processed as any other package (default)."),
89 new HelpItem("auto content 1", "The broker will automatically install validated content-only packages as they are received."),
90 };
91 }
92 }
93}
Helps with parsing of commong data types.
Definition: CommonTypes.cs:13
static bool TryParse(string s, out double Value)
Tries to decode a string encoded double.
Definition: CommonTypes.cs:46
Static class managing persistent settings.
static async Task< string > GetAsync(string Key, string DefaultValue)
Gets a string-valued setting.
static async Task< bool > SetAsync(string Key, string Value)
Sets a string-valued setting.
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
Automatic installation of new versions of the broker.
Definition: Auto.cs:12
override string Name
Command name
Definition: Auto.cs:24
Auto()
Automatic installation of new versions of the broker.
Definition: Auto.cs:16
override HelpItem[] GetHelp()
Gets help about the command.
Definition: Auto.cs:81
override async Task Execute(ChatState State, string[] Arguments, string OrgMessage, Match Details, ResponseCallbackHandler ResponseCallback)
Executes the command.
Definition: Auto.cs:34
Service Module hosting the XMPP broker and its components.
delegate Task< string > ResponseCallbackHandler(string Markdown, string MessageId)
Delegate for response callback handler methods.