Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
UriParameter.cs
1using System;
2using System.Threading.Tasks;
3using System.Xml;
12using Waher.Script;
13
15{
20 {
21 private readonly ReportStringAttribute defaultValue;
22
27 public UriParameter(XmlElement Xml)
28 : base(Xml)
29 {
30 this.defaultValue = new ReportStringAttribute(Xml, "default");
31 }
32
40 {
42 string Default = this.defaultValue.IsEmpty ? null : await this.defaultValue.Evaluate(Variables);
44 string[] DefaultValue;
45
46 if (!(Default is null))
47 DefaultValue = new string[] { Default };
48 else
49 DefaultValue = Array.Empty<string>();
50
51 if (Attributes.RestrictToOptions)
52 {
53 Field = new ListSingleField(Parameters, Attributes.Name, Attributes.Label, Attributes.Required,
54 DefaultValue, Attributes.Options, Attributes.Description, AnyUriDataType.Instance,
55 new BasicValidation(), string.Empty, false, false, false);
56 }
57 else
58 {
59 Field = new TextSingleField(Parameters, Attributes.Name, Attributes.Label, Attributes.Required,
60 DefaultValue, Attributes.Options, Attributes.Description, AnyUriDataType.Instance,
61 new BasicValidation(), string.Empty, false, false, false);
62 }
63
64 Parameters.Add(Field);
65
66 Page Page = Parameters.GetPage(Attributes.Page);
67 Page.Add(Field);
68 }
69
79 public override async Task SetParameter(DataForm Parameters, Language Language, bool OnlySetChanged, Variables Variables,
81 {
82 string Name = await this.GetName(Variables);
83 bool Required = await this.IsRequired(Variables);
84 Field Field = Parameters[Name];
85
86 if (Field is null)
87 {
88 if (Required)
89 Result.AddError(Name, await Language.GetStringAsync(typeof(ReportFileNode), 1, "Required parameter."));
90
91 Variables[Name] = null;
92 }
93 else
94 {
95 string s = Field.ValueString;
96
97 if (string.IsNullOrEmpty(s))
98 {
99 if (Required)
100 Result.AddError(Name, await Language.GetStringAsync(typeof(ReportFileNode), 1, "Required parameter."));
101
102 Variables[Name] = null;
103 }
104 else if (Uri.TryCreate(s, UriKind.Absolute, out _))
105 Variables[Name] = s;
106 else
107 Result.AddError(Name, await Language.GetStringAsync(typeof(ReportFileNode), 2, "Invalid value."));
108 }
109 }
110
111 }
112}
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 AnyUriDataType Instance
Public instance of data type.
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 parameter with possible options on a command.
async Task< ReportParameterWithOptionsAttributes > GetReportParameterWithOptionsAttributes(Variables Variables)
Evaluates the attributes of the report parameter with options.
Represents a Uri-valued parameter.
Definition: UriParameter.cs:20
override async Task PopulateForm(DataForm Parameters, Language Language, Variables Variables)
Populates a data form with parameters for the object.
Definition: UriParameter.cs:39
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.
Definition: UriParameter.cs:79
UriParameter(XmlElement Xml)
Represents a Uri-valued parameter.
Definition: UriParameter.cs:27
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
Definition: ImplTypes.g.cs:58