Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ScriptCommandNodeBase.cs
1using System.Collections.Generic;
2using System.Text;
3using System.Threading.Tasks;
4using Waher.Script;
7
9{
13 public abstract class ScriptCommandNodeBase : VirtualNode
14 {
18 protected string[] script;
19
24
29 : base()
30 {
31 }
32
36 [Page(2, "Script", 100)]
37 [Header(14, "Command ID:")]
38 [ToolTip(15, "ID of command, as referenced by the caller.")]
39 [Required]
40 public string CommandId { get; set; }
41
45 [Page(2, "Script", 100)]
46 [Header(20, "Command Name:")]
47 [ToolTip(21, "Displayable name of command.")]
48 [Required]
49 public string CommandName { get; set; }
50
54 [Page(2, "Script", 100)]
55 [Header(16, "Sort Category:")]
56 [ToolTip(17, "Category in which the command will be ordered.")]
57 [Required]
58 public string SortCategory { get; set; }
59
63 [Page(2, "Script", 100)]
64 [Header(18, "Sort Key:")]
65 [ToolTip(19, "Key used when ordering commands within a sort category.")]
66 [Required]
67 public string SortKey { get; set; }
68
72 [Page(2, "Script", 100)]
73 [Header(22, "Confirmation Message:")]
74 [ToolTip(23, "Optional confirmation message. If defined, it will be presented to users before executing the command.")]
75 public string Confirmation { get; set; }
76
80 [Page(2, "Script", 100)]
81 [Header(24, "Success Message:")]
82 [ToolTip(25, "Optional success message. If defined, it will be presented to users after the successful execution of the command.")]
83 public string Success { get; set; }
84
88 [Page(2, "Script", 100)]
89 [Header(26, "Failure Message:")]
90 [ToolTip(27, "Optional failure message. If defined, it will be presented to users after the failed execution of the command.")]
91 public string Failure { get; set; }
92
96 public override bool ChildrenOrdered => true;
97
103 public override Task<bool> AcceptsChildAsync(INode Child)
104 {
105 return Task.FromResult(Child is ScriptParameterNode);
106 }
107
113 public override Task<bool> AcceptsParentAsync(INode Parent)
114 {
115 return Task.FromResult(Parent is ScriptNode);
116 }
117
122 {
123 get
124 {
125 Expression Exp = this.parsedScript;
126
127 if (Exp is null)
128 {
129 StringBuilder sb = new StringBuilder();
130
131 foreach (string s in this.script)
132 sb.AppendLine(s);
133
134 this.parsedScript = Exp = new Expression(sb.ToString());
135 }
136
137 return Exp;
138 }
139 }
140
141
147 public async Task<ScriptParameterNode[]> GetParameters(VirtualNode Node)
148 {
149 List<ScriptParameterNode> Parameters = new List<ScriptParameterNode>();
150
151 if (this.HasChildren)
152 {
153 IEnumerable<INode> Children = await this.ChildNodes;
154 if (!(Children is null))
155 {
156 foreach (INode Child in Children)
157 {
158 if (Child is ScriptParameterNode ParameterNode)
159 Parameters.Add(ParameterNode);
160 }
161 }
162 }
163
164 return Parameters.ToArray();
165 }
166
172 public abstract Task<ICommand> GetCommand(VirtualNode Node);
173 }
174}
Class managing a script expression.
Definition: Expression.cs:39
Abstract base class for script node commands and queries.
string Confirmation
Optional confirmation message.
string[] script
Unparsed script expression.
override bool ChildrenOrdered
If the children of the node have an intrinsic order (true), or if the order is not important (false).
async Task< ScriptParameterNode[]> GetParameters(VirtualNode Node)
Gets a node command based on the script command.
override Task< bool > AcceptsChildAsync(INode Child)
If the node accepts a presumptive child, i.e. can receive as a child (if that child accepts the node ...
ScriptCommandNodeBase()
Represents a command that can be executed on a script node or script reference node.
override Task< bool > AcceptsParentAsync(INode Parent)
If the node accepts a presumptive parent, i.e. can be added to that parent (if that parent accepts th...
string Success
Optional confirmation message.
Expression parsedScript
Parsed script expression.
string SortCategory
Sort category of command.
abstract Task< ICommand > GetCommand(VirtualNode Node)
Gets a node command based on the script command.
string CommandName
Displayable name of command
Expression ParsedScript
Parsed command script.
string Failure
Optional confirmation message.
Node defined by script.
Definition: ScriptNode.cs:19
Represents a parameter on a command.
Virtual node, that can be used as a placeholder for services.
Definition: VirtualNode.cs:28
Interface for nodes that are published through the concentrator interface.
Definition: INode.cs:49
bool HasChildren
If the source has any child sources.
Definition: INode.cs:76
Task< IEnumerable< INode > > ChildNodes
Child nodes. If no child nodes are available, null is returned.
Definition: INode.cs:140
INode Parent
Parent Node, or null if a root node.
Definition: INode.cs:116