Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ScriptInt16ParameterNode.cs
1using System.Text.RegularExpressions;
2using 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 short? DefaultValue { get; set; }
35
39 [Page(2, "Script", 100)]
40 [Header(44, "Minimum Value:")]
41 [ToolTip(45, "The smallest value allowed.")]
42 public short? Min { get; set; }
43
47 [Page(2, "Script", 100)]
48 [Header(46, "Maximum Value:")]
49 [ToolTip(47, "The largest value allowed.")]
50 public short? Max { get; set; }
51
57 public override Task<string> GetTypeNameAsync(Language Language)
58 {
59 return Language.GetStringAsync(typeof(ScriptNode), 51, "16-bit integer-valued parameter");
60 }
61
68 public override async Task PopulateForm(DataForm Parameters, Language Language, object Value)
69 {
70 ValidationMethod Validation;
72
73 if (this.Min.HasValue || this.Max.HasValue)
74 Validation = new RangeValidation(this.Min?.ToString(), this.Max?.ToString());
75 else
76 Validation = new BasicValidation();
77
78 if (this.RestrictToOptions)
79 {
80 Field = new ListSingleField(Parameters, this.ParameterName, this.Label, this.Required,
81 new string[] { this.DefaultValue?.ToString() ?? string.Empty }, await this.GetOptions(), this.Description,
82 ShortDataType.Instance, Validation, string.Empty, false, false, false);
83 }
84 else
85 {
87 new string[] { this.DefaultValue?.ToString() ?? string.Empty }, await this.GetOptions(), this.Description,
88 ShortDataType.Instance, Validation, string.Empty, false, false, false);
89 }
90
91 Parameters.Add(Field);
92
93 Page Page = Parameters.GetPage(this.Page);
94 Page.Add(Field);
95 }
96
106 public override async Task SetParameter(DataForm Parameters, Language Language, bool OnlySetChanged, Variables Values,
108 {
110 if (Field is null)
111 {
112 if (this.Required)
113 Result.AddError(this.ParameterName, await Language.GetStringAsync(typeof(ScriptNode), 42, "Required parameter."));
114
115 Values[this.ParameterName] = null;
116 }
117 else
118 {
119 string s = Field.ValueString;
120
121 if (string.IsNullOrEmpty(s))
122 {
123 if (this.Required)
124 Result.AddError(this.ParameterName, await Language.GetStringAsync(typeof(ScriptNode), 42, "Required parameter."));
125
126 Values[this.ParameterName] = null;
127 }
128 else if (short.TryParse(s, out short Parsed))
129 Values[this.ParameterName] = Parsed;
130 else
131 Result.AddError(this.ParameterName, await Language.GetStringAsync(typeof(ScriptNode), 49, "Invalid value."));
132 }
133 }
134
135 }
136}
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 ShortDataType Instance
Public instance of data type.
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
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 16-bit integer-valued script parameter.
ScriptInt16ParameterNode()
Represents a 16-bit integer-valued script parameter.
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.
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.
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.