Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ScriptBooleanParameterNode.cs
1using System.Text.RegularExpressions;
2using System.Threading.Tasks;
3using Waher.Content;
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 bool? DefaultValue { get; set; }
36
42 public override Task<string> GetTypeNameAsync(Language Language)
43 {
44 return Language.GetStringAsync(typeof(ScriptNode), 53, "Boolean-valued parameter");
45 }
46
53 public override Task PopulateForm(DataForm Parameters, Language Language, object Value)
54 {
56 new string[] { this.DefaultValue.HasValue ? CommonTypes.Encode(this.DefaultValue.Value) : string.Empty },
57 null, this.Description, BooleanDataType.Instance, new BasicValidation(), string.Empty, false, false, false);
58
59 Parameters.Add(Field);
60
61 Page Page = Parameters.GetPage(this.Page);
62 Page.Add(Field);
63
64 return Task.CompletedTask;
65 }
66
76 public override async Task SetParameter(DataForm Parameters, Language Language, bool OnlySetChanged, Variables Values,
78 {
80 if (Field is null)
81 {
82 if (this.Required)
83 Result.AddError(this.ParameterName, await Language.GetStringAsync(typeof(ScriptNode), 42, "Required parameter."));
84
85 Values[this.ParameterName] = null;
86 }
87 else
88 {
89 string s = Field.ValueString;
90
91 if (string.IsNullOrEmpty(s))
92 {
93 if (this.Required)
94 Result.AddError(this.ParameterName, await Language.GetStringAsync(typeof(ScriptNode), 42, "Required parameter."));
95
96 Values[this.ParameterName] = null;
97 }
98 else if (CommonTypes.TryParse(s, out bool Parsed))
99 Values[this.ParameterName] = Parsed;
100 else
101 Result.AddError(this.ParameterName, await Language.GetStringAsync(typeof(ScriptNode), 49, "Invalid value."));
102 }
103 }
104
105 }
106}
Helps with parsing of commong data types.
Definition: CommonTypes.cs:13
static string Encode(bool x)
Encodes a Boolean for use in XML and other formats.
Definition: CommonTypes.cs:594
static bool TryParse(string s, out double Value)
Tries to decode a string encoded double.
Definition: CommonTypes.cs:46
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 BooleanDataType 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
override Task PopulateForm(DataForm Parameters, Language Language, object Value)
Populates a data form with parameters for the object.
ScriptBooleanParameterNode()
Represents a Boolean-valued script parameter.
override Task< string > GetTypeNameAsync(Language Language)
Gets the type name of the node.
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.
Node defined by script.
Definition: ScriptNode.cs:19
Represents a parameter on a command.
bool Required
If parameter is required.
string Description
Parameter description.