Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
JidParameter.cs
1using System;
2using System.Threading.Tasks;
3using System.Xml;
13using Waher.Script;
14
16{
21 {
22 private readonly ReportStringAttribute defaultValue;
23
28 public JidParameter(XmlElement Xml)
29 : base(Xml)
30 {
31 this.defaultValue = new ReportStringAttribute(Xml, "default");
32 }
33
41 {
43 string Default = this.defaultValue.IsEmpty ? null : await this.defaultValue.Evaluate(Variables);
45 string[] DefaultValue;
46
47 if (!(Default is null))
48 DefaultValue = new string[] { Default };
49 else
50 DefaultValue = Array.Empty<string>();
51
52 if (Attributes.RestrictToOptions)
53 {
54 Field = new ListSingleField(Parameters, Attributes.Name, Attributes.Label, Attributes.Required,
55 DefaultValue, Attributes.Options, Attributes.Description, StringDataType.Instance, new BasicValidation(),
56 string.Empty, false, false, false);
57 }
58 else
59 {
60 Field = new JidSingleField(Parameters, Attributes.Name, Attributes.Label, Attributes.Required,
61 DefaultValue, Attributes.Options, Attributes.Description, StringDataType.Instance, new BasicValidation(),
62 string.Empty, false, false, false);
63 }
64
65 Parameters.Add(Field);
66
67 Page Page = Parameters.GetPage(Attributes.Page);
68 Page.Add(Field);
69 }
70
80 public override async Task SetParameter(DataForm Parameters, Language Language, bool OnlySetChanged, Variables Variables,
82 {
83 string Name = await this.GetName(Variables);
84 bool Required = await this.IsRequired(Variables);
85 Field Field = Parameters[Name];
86
87 if (Field is null)
88 {
89 if (Required)
90 Result.AddError(Name, await Language.GetStringAsync(typeof(ReportFileNode), 1, "Required parameter."));
91
92 Variables[Name] = null;
93 }
94 else
95 {
96 string s = Field.ValueString;
97
98 if (string.IsNullOrEmpty(s))
99 {
100 if (Required)
101 Result.AddError(Name, await Language.GetStringAsync(typeof(ReportFileNode), 1, "Required parameter."));
102
103 Variables[Name] = null;
104 }
105 else if (XmppClient.BareJidRegEx.IsMatch(s))
106 Variables[Name] = s;
107 else
108 Result.AddError(Name, await Language.GetStringAsync(typeof(ReportFileNode), 4, "Invalid JID."));
109 }
110 }
111 }
112}
Static class managing editable parameters in objects. Editable parameters are defined by using the at...
Definition: Parameters.cs:26
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:17
string ValueString
Value as a single string. If field contains multiple values, they will be concatenated into a single ...
Definition: Field.cs:102
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:58
static readonly Regex BareJidRegEx
Regular expression for Bare JIDs
Definition: XmppClient.cs:187
Represents a Jid-valued parameter.
Definition: JidParameter.cs:21
override async Task SetParameter(DataForm Parameters, Language Language, bool OnlySetChanged, Variables Variables, SetEditableFormResult Result)
Sets the parameters of the object, based on contents in the data form.
Definition: JidParameter.cs:80
JidParameter(XmlElement Xml)
Represents a Jid-valued parameter.
Definition: JidParameter.cs:28
override async Task PopulateForm(DataForm Parameters, Language Language, Variables Variables)
Populates a data form with parameters for the object.
Definition: JidParameter.cs:40
Represents a parameter with possible options on a command.
async Task< ReportParameterWithOptionsAttributes > GetReportParameterWithOptionsAttributes(Variables Variables)
Evaluates the attributes of the report parameter with options.
Task< string > GetName(Variables Variables)
Name of the parameter.
Task< bool > IsRequired(Variables Variables)
If parameter is required.
Report node based on the contents of a report file.
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