Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
GetUserSetting.cs
1using System.Threading.Tasks;
7
9{
15 {
26 public GetUserSetting(ScriptNode User, ScriptNode Name, ScriptNode DefaultValue, int Start, int Length, Expression Expression)
27 : base(new ScriptNode[] { User, Name, DefaultValue }, argumentTypes3Scalar, Start, Length, Expression)
28 {
29 }
30
34 public override string FunctionName => nameof(GetUserSetting);
35
39 public override string[] DefaultArgumentNames => new string[] { "User", "Name", "DefaultValue" };
40
45 public override bool IsAsynchronous => true;
46
54 {
55 return this.EvaluateAsync(Arguments, Variables).Result;
56 }
57
64 public override async Task<IElement> EvaluateAsync(IElement[] Arguments, Variables Variables)
65 {
66 string User = await GetSetting.GetUser(Arguments[0].AssociatedObjectValue, this);
67
68 if (string.IsNullOrEmpty(User))
69 throw new ScriptRuntimeException("User not defined.", this);
70
71 string Name = ToString(Arguments[1]);
72 object DefaultValue = Arguments[2].AssociatedObjectValue;
73 object Result;
74
75 Result = await UserSettings.GetAsync(User, Name, DefaultValue);
76
77 return Expression.Encapsulate(Result);
78 }
79 }
80}
Static class managing persistent user settings. User settings default to runtime settings if user-spe...
Definition: UserSettings.cs:18
static async Task< string > GetAsync(string User, string Key, string DefaultValue)
Gets a string-valued setting.
Definition: UserSettings.cs:40
Class managing a script expression.
Definition: Expression.cs:41
static IElement Encapsulate(object Value)
Encapsulates an object.
Definition: Expression.cs:5241
Base class for multivariate funcions.
ScriptNode[] Arguments
Function arguments.
static readonly ArgumentType[] argumentTypes3Scalar
Three scalar parameters.
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
Gets a runtime setting with name Name. If Host is provided, the function first tries to get the corre...
Definition: GetSetting.cs:18
static async Task< string > GetUser(object Value, ScriptNode Node)
Gets the host name from a value.
Definition: GetSetting.cs:124
Gets a runtime hgost setting with name Name. User defines the user. If a user setting is not found,...
override bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
override string[] DefaultArgumentNames
Default Argument names
override async Task< IElement > EvaluateAsync(IElement[] Arguments, Variables Variables)
Evaluates the function.
GetUserSetting(ScriptNode User, ScriptNode Name, ScriptNode DefaultValue, int Start, int Length, Expression Expression)
Gets a runtime hgost setting with name Name. User defines the user. If a user setting is not found,...
override string FunctionName
Name of the function
override IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the function.
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:21