Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ScriptUriParameterNode.cs
1using System;
2using System.Threading.Tasks;
10using Waher.Script;
12
14{
19 {
24 : base()
25 {
26 }
27
31 [Page(2, "Script", 100)]
32 [Header(29, "Default value:")]
33 [ToolTip(30, "Default value presented to user.")]
34 public string DefaultValue { get; set; }
35
41 public override Task<string> GetTypeNameAsync(Language Language)
42 {
43 return Language.GetStringAsync(typeof(ScriptNode), 57, "URI-valued parameter");
44 }
45
52 public override async Task PopulateForm(DataForm Parameters, Language Language, object Value)
53 {
55
56 if (this.RestrictToOptions)
57 {
58 Field = new ListSingleField(Parameters, this.ParameterName, this.Label, this.Required,
59 new string[] { this.DefaultValue }, await this.GetOptions(), this.Description, AnyUriDataType.Instance,
60 new BasicValidation(), string.Empty, false, false, false);
61 }
62 else
63 {
65 new string[] { this.DefaultValue }, await this.GetOptions(), this.Description, AnyUriDataType.Instance,
66 new BasicValidation(), string.Empty, false, false, false);
67 }
68
69 Parameters.Add(Field);
70
71 Page Page = Parameters.GetPage(this.Page);
72 Page.Add(Field);
73 }
74
84 public override async Task SetParameter(DataForm Parameters, Language Language, bool OnlySetChanged, Variables Values,
86 {
88 if (Field is null)
89 {
90 if (this.Required)
91 Result.AddError(this.ParameterName, await Language.GetStringAsync(typeof(ScriptNode), 42, "Required parameter."));
92
93 Values[this.ParameterName] = null;
94 }
95 else
96 {
97 string s = Field.ValueString;
98
99 if (string.IsNullOrEmpty(s))
100 {
101 if (this.Required)
102 Result.AddError(this.ParameterName, await Language.GetStringAsync(typeof(ScriptNode), 42, "Required parameter."));
103
104 Values[this.ParameterName] = null;
105 }
106 else
107 {
108 Values[this.ParameterName] = s;
109
110 if (!Uri.TryCreate(s, UriKind.Absolute, out Uri _))
111 Result.AddError(this.ParameterName, await Language.GetStringAsync(typeof(ScriptNode), 49, "Invalid value."));
112 }
113 }
114 }
115
116 }
117}
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 AnyUriDataType 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
Represents a parameter with possible options on a command.
async Task< KeyValuePair< string, string >[]> GetOptions()
Gets available options, if any are defined.
Represents an URI-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.
ScriptUriParameterNode()
Represents an URI-valued script parameter.
override Task< string > GetTypeNameAsync(Language Language)
Gets the type name of the node.
Node defined by script.
Definition: ScriptNode.cs:19
bool Required
If parameter is required.
string Description
Parameter description.