Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ScriptJidParameterNode.cs
1using System;
2using System.Threading.Tasks;
10using Waher.Script;
12
14{
19 {
20 private string defaultValue;
21
26 : base()
27 {
28 }
29
33 [Page(2, "Script", 100)]
34 [Header(29, "Default value:")]
35 [ToolTip(30, "Default value presented to user.")]
36 public string DefaultValue
37 {
38 get => this.defaultValue;
39 set
40 {
41 if (!string.IsNullOrEmpty(value) && !XmppClient.BareJidRegEx.IsMatch(value))
42 throw new NotSupportedException("Invalid JID.");
43
44 this.defaultValue = value;
45 }
46 }
47
53 public override Task<string> GetTypeNameAsync(Language Language)
54 {
55 return Language.GetStringAsync(typeof(ScriptNode), 66, "JID-valued parameter");
56 }
57
64 public override async Task PopulateForm(DataForm Parameters, Language Language, object Value)
65 {
67
68 if (this.RestrictToOptions)
69 {
70 Field = new ListSingleField(Parameters, this.ParameterName, this.Label, this.Required,
71 new string[] { this.DefaultValue }, await this.GetOptions(), this.Description, null, new BasicValidation(),
72 string.Empty, false, false, false);
73 }
74 else
75 {
77 new string[] { this.DefaultValue }, await this.GetOptions(), this.Description, null, new BasicValidation(),
78 string.Empty, false, false, false);
79 }
80
81 Parameters.Add(Field);
82
83 Page Page = Parameters.GetPage(this.Page);
84 Page.Add(Field);
85 }
86
96 public override async Task SetParameter(DataForm Parameters, Language Language, bool OnlySetChanged, Variables Values,
98 {
100 if (Field is null)
101 {
102 if (this.Required)
103 Result.AddError(this.ParameterName, await Language.GetStringAsync(typeof(ScriptNode), 42, "Required parameter."));
104
105 Values[this.ParameterName] = null;
106 }
107 else
108 {
109 string s = Field.ValueString;
110 Values[this.ParameterName] = s;
111
112 if (string.IsNullOrEmpty(s))
113 {
114 if (this.Required)
115 Result.AddError(this.ParameterName, await Language.GetStringAsync(typeof(ScriptNode), 42, "Required parameter."));
116
117 Values[this.ParameterName] = null;
118 }
119 else if (!XmppClient.BareJidRegEx.IsMatch(s))
120 Result.AddError(this.ParameterName, "Invalid JID.");
121 }
122 }
123
124 }
125}
Static class managing editable parameters in objects. Editable parameters are defined by using the at...
Definition: Parameters.cs:25
void AddError(string Key, string Value)
Adds an error to the list of errors.
Implements support for data forms. Data Forms are defined in the following XEPs:
Definition: DataForm.cs:42
Base class for form fields
Definition: Field.cs:16
string ValueString
Value as a single string. If field contains multiple values, they will be concatenated into a single ...
Definition: Field.cs:101
Class managing a page in a data form layout.
Definition: Page.cs:11
void Add(LayoutElement Element)
Adds a layout element.
Definition: Section.cs:135
Manages an XMPP client connection. Implements XMPP, as defined in https://tools.ietf....
Definition: XmppClient.cs:59
static readonly Regex BareJidRegEx
Regular expression for Bare JIDs
Definition: XmppClient.cs:188
Contains information about a language.
Definition: Language.cs:17
Task< string > GetStringAsync(Type Type, int Id, string Default)
Gets the string value of a string ID. If no such string exists, a string is created with the default ...
Definition: Language.cs:209
Collection of variables.
Definition: Variables.cs:25
override async Task SetParameter(DataForm Parameters, Language Language, bool OnlySetChanged, Variables Values, SetEditableFormResult Result)
Sets the parameters of the object, based on contents in the data form.
override Task< string > GetTypeNameAsync(Language Language)
Gets the type name of the node.
ScriptJidParameterNode()
Represents a JID-valued script parameter.
override async Task PopulateForm(DataForm Parameters, Language Language, object Value)
Populates a data form with parameters for the object.
Represents a parameter with possible options on a command.
async Task< KeyValuePair< string, string >[]> GetOptions()
Gets available options, if any are defined.
Node defined by script.
Definition: ScriptNode.cs:19
bool Required
If parameter is required.
string Description
Parameter description.