Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ScriptInt32ParameterNode.cs
1using System.Threading.Tasks;
9using Waher.Script;
11
13{
18 {
23 : base()
24 {
25 }
26
30 [Page(2, "Script", 100)]
31 [Header(29, "Default value:")]
32 [ToolTip(30, "Default value presented to user.")]
33 public int? DefaultValue { get; set; }
34
38 [Page(2, "Script", 100)]
39 [Header(44, "Minimum Value:")]
40 [ToolTip(45, "The smallest value allowed.")]
41 public int? Min { get; set; }
42
46 [Page(2, "Script", 100)]
47 [Header(46, "Maximum Value:")]
48 [ToolTip(47, "The largest value allowed.")]
49 public int? Max { get; set; }
50
56 public override Task<string> GetTypeNameAsync(Language Language)
57 {
58 return Language.GetStringAsync(typeof(ScriptNode), 48, "32-bit integer-valued parameter");
59 }
60
67 public override async Task PopulateForm(DataForm Parameters, Language Language, object Value)
68 {
69 ValidationMethod Validation;
71
72 if (this.Min.HasValue || this.Max.HasValue)
73 Validation = new RangeValidation(this.Min?.ToString(), this.Max?.ToString());
74 else
75 Validation = new BasicValidation();
76
77 if (this.RestrictToOptions)
78 {
79 Field = new ListSingleField(Parameters, this.ParameterName, this.Label, this.Required,
80 new string[] { this.DefaultValue?.ToString() ?? string.Empty }, await this.GetOptions(), this.Description,
81 IntDataType.Instance, Validation, string.Empty, false, false, false);
82 }
83 else
84 {
86 new string[] { this.DefaultValue?.ToString() ?? string.Empty }, await this.GetOptions(), this.Description,
87 IntDataType.Instance, Validation, string.Empty, false, false, false);
88 }
89
90 Parameters.Add(Field);
91
92 Page Page = Parameters.GetPage(this.Page);
93 Page.Add(Field);
94 }
95
105 public override async Task SetParameter(DataForm Parameters, Language Language, bool OnlySetChanged, Variables Values,
107 {
109 if (Field is null)
110 {
111 if (this.Required)
112 Result.AddError(this.ParameterName, await Language.GetStringAsync(typeof(ScriptNode), 42, "Required parameter."));
113
114 Values[this.ParameterName] = null;
115 }
116 else
117 {
118 string s = Field.ValueString;
119
120 if (string.IsNullOrEmpty(s))
121 {
122 if (this.Required)
123 Result.AddError(this.ParameterName, await Language.GetStringAsync(typeof(ScriptNode), 42, "Required parameter."));
124
125 Values[this.ParameterName] = null;
126 }
127 else if (int.TryParse(s, out int Parsed))
128 Values[this.ParameterName] = Parsed;
129 else
130 Result.AddError(this.ParameterName, await Language.GetStringAsync(typeof(ScriptNode), 49, "Invalid value."));
131 }
132 }
133
134 }
135}
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 IntDataType Instance
Public instance of data type.
Definition: IntDataType.cs:11
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
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 32-bit integer-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 async Task PopulateForm(DataForm Parameters, Language Language, object Value)
Populates a data form with parameters for the object.
ScriptInt32ParameterNode()
Represents a 32-bit integer-valued script parameter.
override Task< string > GetTypeNameAsync(Language Language)
Gets the type name of the node.
Represents a parameter with possible options on a command.
bool RestrictToOptions
If only values defined in options are valid values.
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.