Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Dns.cs
1using System;
2using System.Threading.Tasks;
11
13{
18 {
27 : base(new ScriptNode[] { Name }, argumentTypes1Scalar, Start, Length, Expression)
28 {
29 }
30
40 : base(new ScriptNode[] { Name, Type }, argumentTypes2Scalar, Start, Length, Expression)
41 {
42 }
43
53 public Dns(ScriptNode Name, ScriptNode Type, ScriptNode Class, int Start, int Length, Expression Expression)
54 : base(new ScriptNode[] { Name, Type, Class }, argumentTypes3Scalar, Start, Length, Expression)
55 {
56 }
57
61 public override string FunctionName => nameof(Dns);
62
66 public override string[] DefaultArgumentNames => new string[] { "Name", "QTYPE", "QCLASS" };
67
72 public override bool IsAsynchronous => true;
73
81 {
82 return this.EvaluateAsync(Arguments, Variables).Result;
83 }
84
91 public override async Task<IElement> EvaluateAsync(IElement[] Arguments, Variables Variables)
92 {
93 string Name = Arguments[0].AssociatedObjectValue?.ToString() ?? string.Empty;
94 int c = Arguments.Length;
95 QTYPE TYPE = c < 2 ? QTYPE.A : this.ToEnum<QTYPE>(Arguments[1]);
96 QCLASS CLASS = c < 3 ? QCLASS.IN : this.ToEnum<QCLASS>(Arguments[2]);
97
98 ResourceRecord[] Records = await DnsResolver.Resolve(Name, TYPE, CLASS);
99
100 if (Records.Length == 0)
101 throw new ScriptRuntimeException("Unable to resolve name.", this);
102 else if (Records.Length == 1)
103 return new ObjectValue(Records[0]);
104 else
105 return new ObjectVector(Records);
106 }
107 }
108}
DNS resolver, as defined in:
Definition: DnsResolver.cs:32
static Task< ResourceRecord[]> Resolve(string Name, QTYPE TYPE, QCLASS CLASS)
Resolves a DNS name.
Definition: DnsResolver.cs:147
Abstract base class for a resource record.
Class managing a script expression.
Definition: Expression.cs:39
Base class for multivariate funcions.
ScriptNode[] Arguments
Function arguments.
static readonly ArgumentType[] argumentTypes2Scalar
Two scalar parameters.
static readonly ArgumentType[] argumentTypes3Scalar
Three scalar parameters.
static readonly ArgumentType[] argumentTypes1Scalar
One scalar parameter.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
override string ToString()
Definition: ScriptNode.cs:359
Expression Expression
Expression of which the node is a part.
Definition: ScriptNode.cs:177
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
Makes a DNS query regarding a name.
Definition: Dns.cs:18
Dns(ScriptNode Name, int Start, int Length, Expression Expression)
Makes a DNS query regarding a name.
Definition: Dns.cs:26
override bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
Definition: Dns.cs:72
Dns(ScriptNode Name, ScriptNode Type, ScriptNode Class, int Start, int Length, Expression Expression)
Makes a DNS query regarding a name.
Definition: Dns.cs:53
override async Task< IElement > EvaluateAsync(IElement[] Arguments, Variables Variables)
Evaluates the function.
Definition: Dns.cs:91
override IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the function.
Definition: Dns.cs:80
Dns(ScriptNode Name, ScriptNode Type, int Start, int Length, Expression Expression)
Makes a DNS query regarding a name.
Definition: Dns.cs:39
override string FunctionName
Name of the function
Definition: Dns.cs:61
override string[] DefaultArgumentNames
Default Argument names
Definition: Dns.cs:66
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20
CLASS
TYPE fields are used in resource records.
Definition: CLASS.cs:11
QTYPE
QTYPE fields appear in the question part of a query.
Definition: QTYPE.cs:11
QCLASS
QCLASS fields appear in the question section of a query.
Definition: QCLASS.cs:11
TYPE
TYPE fields are used in resource records.
Definition: TYPE.cs:11