Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ScriptJidsParameterNode.cs
1using System.Threading.Tasks;
10using Waher.Script;
12
14{
19 {
24 : base()
25 {
26 }
27
31 [Page(2, "Script", 100)]
32 [Header(29, "Default value:")]
33 [ToolTip(30, "Default value presented to user.")]
34 public string[] DefaultValue { get; set; }
35
39 [Page(2, "Script", 100)]
40 [Header(68, "Minimum Count:")]
41 [ToolTip(69, "The smallest amount of items accepted.")]
42 public ushort? MinCount { get; set; }
43
47 [Page(2, "Script", 100)]
48 [Header(70, "Maximum Count:")]
49 [ToolTip(71, "The largest amount of items accepted.")]
50 public ushort? MaxCount { get; set; }
51
57 public override Task<string> GetTypeNameAsync(Language Language)
58 {
59 return Language.GetStringAsync(typeof(ScriptNode), 67, "Multiple JIDs-valued parameter");
60 }
61
68 public override async Task PopulateForm(DataForm Parameters, Language Language, object Value)
69 {
70 ValidationMethod Validation = new BasicValidation();
72
73 if (this.MinCount.HasValue || this.MaxCount.HasValue)
74 Validation = new ListRangeValidation(Validation, this.MinCount ?? 0, this.MaxCount ?? ushort.MaxValue);
75
76 if (this.RestrictToOptions)
77 {
78 Field = new ListMultiField(Parameters, this.ParameterName, this.Label, this.Required,
79 this.DefaultValue, await this.GetOptions(), this.Description, StringDataType.Instance, Validation, string.Empty,
80 false, false, false);
81 }
82 else
83 {
85 this.DefaultValue, await this.GetOptions(), this.Description, StringDataType.Instance, Validation, string.Empty,
86 false, false, false);
87 }
88
89 Parameters.Add(Field);
90
91 Page Page = Parameters.GetPage(this.Page);
92 Page.Add(Field);
93 }
94
104 public override async Task SetParameter(DataForm Parameters, Language Language, bool OnlySetChanged, Variables Values,
106 {
108 if (Field is null)
109 {
110 if (this.Required)
111 Result.AddError(this.ParameterName, await Language.GetStringAsync(typeof(ScriptNode), 42, "Required parameter."));
112
113 Values[this.ParameterName] = null;
114 }
115 else
116 {
117 string[] s = Field.ValueStrings;
118
119 if (s is null || s.Length == 0)
120 {
121 if (this.Required)
122 Result.AddError(this.ParameterName, await Language.GetStringAsync(typeof(ScriptNode), 42, "Required parameter."));
123
124 Values[this.ParameterName] = null;
125 }
126 else
127 {
128 Values[this.ParameterName] = s;
129
130 foreach (string Jid in s)
131 {
132 if (!XmppClient.BareJidRegEx.IsMatch(Jid))
133 Result.AddError(this.ParameterName, "Invalid JID: " + Jid);
134 }
135
136 if (this.MinCount.HasValue && s.Length < this.MinCount.Value)
137 Result.AddError(this.ParameterName, await Language.GetStringAsync(typeof(ScriptNode), 72, "Too few rows."));
138 else if (this.MaxCount.HasValue && s.Length > this.MaxCount.Value)
139 Result.AddError(this.ParameterName, await Language.GetStringAsync(typeof(ScriptNode), 73, "Too many rows."));
140 }
141 }
142 }
143 }
144}
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
static readonly StringDataType Instance
Public instance of data type.
Base class for form fields
Definition: Field.cs:16
string[] ValueStrings
Values for the field (string representations).
Definition: Field.cs:96
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
Represents a multiple JIDs-valued script parameter.
ScriptJidsParameterNode()
Represents a multiple JIDs-valued script parameter.
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.
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.