Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ScriptTimeParameterNode.cs
1using System;
2using System.Text.RegularExpressions;
3using System.Threading.Tasks;
11using Waher.Script;
13
15{
20 {
25 : base()
26 {
27 }
28
32 [Page(2, "Script", 100)]
33 [Header(29, "Default value:")]
34 [ToolTip(30, "Default value presented to user.")]
35 public TimeSpan? DefaultValue { get; set; }
36
40 [Page(2, "Script", 100)]
41 [Header(44, "Minimum Value:")]
42 [ToolTip(45, "The smallest value allowed.")]
43 public TimeSpan? Min { get; set; }
44
48 [Page(2, "Script", 100)]
49 [Header(46, "Maximum Value:")]
50 [ToolTip(47, "The largest value allowed.")]
51 public TimeSpan? Max { get; set; }
52
58 public override Task<string> GetTypeNameAsync(Language Language)
59 {
60 return Language.GetStringAsync(typeof(ScriptNode), 56, "Time-valued parameter");
61 }
62
69 public override async Task PopulateForm(DataForm Parameters, Language Language, object Value)
70 {
71 ValidationMethod Validation;
73
74 if (this.Min.HasValue || this.Max.HasValue)
75 Validation = new RangeValidation(this.Min?.ToString(), this.Max?.ToString());
76 else
77 Validation = new BasicValidation();
78
79 if (this.RestrictToOptions)
80 {
81 Field = new ListSingleField(Parameters, this.ParameterName, this.Label, this.Required,
82 new string[] { this.DefaultValue?.ToString() ?? string.Empty }, await this.GetOptions(), this.Description,
83 TimeDataType.Instance, Validation, string.Empty, false, false, false);
84 }
85 else
86 {
88 new string[] { this.DefaultValue?.ToString() ?? string.Empty }, await this.GetOptions(), this.Description,
89 TimeDataType.Instance, Validation, string.Empty, false, false, false);
90 }
91
92 Parameters.Add(Field);
93
94 Page Page = Parameters.GetPage(this.Page);
95 Page.Add(Field);
96 }
97
107 public override async Task SetParameter(DataForm Parameters, Language Language, bool OnlySetChanged, Variables Values,
109 {
111 if (Field is null)
112 {
113 if (this.Required)
114 Result.AddError(this.ParameterName, await Language.GetStringAsync(typeof(ScriptNode), 42, "Required parameter."));
115
116 Values[this.ParameterName] = null;
117 }
118 else
119 {
120 string s = Field.ValueString;
121
122 if (string.IsNullOrEmpty(s))
123 {
124 if (this.Required)
125 Result.AddError(this.ParameterName, await Language.GetStringAsync(typeof(ScriptNode), 42, "Required parameter."));
126
127 Values[this.ParameterName] = null;
128 }
129 else if (TimeSpan.TryParse(s, out TimeSpan Parsed))
130 Values[this.ParameterName] = Parsed;
131 else
132 Result.AddError(this.ParameterName, await Language.GetStringAsync(typeof(ScriptNode), 49, "Invalid value."));
133 }
134 }
135
136 }
137}
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 TimeDataType Instance
Public instance of data type.
Definition: TimeDataType.cs:13
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 parameter with possible options on a command.
async Task< KeyValuePair< string, string >[]> GetOptions()
Gets available options, if any are defined.
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.
override Task< string > GetTypeNameAsync(Language Language)
Gets the type name of the node.
ScriptTimeParameterNode()
Represents a Time-valued script parameter.
Node defined by script.
Definition: ScriptNode.cs:19
bool Required
If parameter is required.
string Description
Parameter description.