Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Int8Parameter.cs
1using System;
2using System.Threading.Tasks;
3using System.Xml;
12using Waher.Script;
13
15{
20 {
21 private readonly ReportInt8Attribute defaultValue;
22 private readonly ReportInt8Attribute min;
23 private readonly ReportInt8Attribute max;
24
29 public Int8Parameter(XmlElement Xml)
30 : base(Xml)
31 {
32 this.defaultValue = new ReportInt8Attribute(Xml, "default");
33 this.min = new ReportInt8Attribute(Xml, "min");
34 this.max = new ReportInt8Attribute(Xml, "max");
35 }
36
44 {
46 sbyte? Default = this.defaultValue.IsEmpty ? null : (sbyte?)await this.defaultValue.Evaluate(Variables);
47 sbyte? Min = this.min.IsEmpty ? null : (sbyte?)await this.min.Evaluate(Variables);
48 sbyte? Max = this.max.IsEmpty ? null : (sbyte?)await this.max.Evaluate(Variables);
49 ValidationMethod Validation;
51 string[] DefaultValue;
52
53 if (Default.HasValue)
54 DefaultValue = new string[] { Default.Value.ToString() };
55 else
56 DefaultValue = Array.Empty<string>();
57
58 if (Min.HasValue || Max.HasValue)
59 Validation = new RangeValidation(Min?.ToString(), Max?.ToString());
60 else
61 Validation = new BasicValidation();
62
63 if (Attributes.RestrictToOptions)
64 {
65 Field = new ListSingleField(Parameters, Attributes.Name, Attributes.Label, Attributes.Required,
66 DefaultValue, Attributes.Options, Attributes.Description, ByteDataType.Instance, Validation,
67 string.Empty, false, false, false);
68 }
69 else
70 {
71 Field = new TextSingleField(Parameters, Attributes.Name, Attributes.Label, Attributes.Required,
72 DefaultValue, Attributes.Options, Attributes.Description, ByteDataType.Instance, Validation,
73 string.Empty, false, false, false);
74 }
75
76 Parameters.Add(Field);
77
78 Page Page = Parameters.GetPage(Attributes.Page);
79 Page.Add(Field);
80 }
81
91 public override async Task SetParameter(DataForm Parameters, Language Language, bool OnlySetChanged, Variables Variables,
93 {
94 string Name = await this.GetName(Variables);
95 bool Required = await this.IsRequired(Variables);
96 Field Field = Parameters[Name];
97
98 if (Field is null)
99 {
100 if (Required)
101 Result.AddError(Name, await Language.GetStringAsync(typeof(ReportFileNode), 1, "Required parameter."));
102
103 Variables[Name] = null;
104 }
105 else
106 {
107 string s = Field.ValueString;
108
109 if (string.IsNullOrEmpty(s))
110 {
111 if (Required)
112 Result.AddError(Name, await Language.GetStringAsync(typeof(ReportFileNode), 1, "Required parameter."));
113
114 Variables[Name] = null;
115 }
116 else if (sbyte.TryParse(s, out sbyte Parsed))
117 Variables[Name] = Parsed;
118 else
119 Result.AddError(Name, await Language.GetStringAsync(typeof(ReportFileNode), 2, "Invalid value."));
120 }
121 }
122
123 }
124}
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 ByteDataType Instance
Public instance of data type.
Definition: ByteDataType.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
Represents a Int8-valued parameter.
override async Task PopulateForm(DataForm Parameters, Language Language, Variables Variables)
Populates a data form with parameters for the object.
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.
Int8Parameter(XmlElement Xml)
Represents a Int8-valued parameter.
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