Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
GetTabIDs.cs
1using System;
2using System.Collections.Generic;
3using Waher.Script;
9
11{
16 {
25 {
26 }
27
36 : base(new ScriptNode[] { Page }, argumentTypes1Normal, Start, Length, Expression)
37 {
38 }
39
48 public GetTabIDs(ScriptNode Page, ScriptNode QueryFilter, int Start, int Length, Expression Expression)
49 : base(new ScriptNode[] { Page, QueryFilter }, argumentTypes2Scalar, Start, Length, Expression)
50 {
51 }
52
56 public override string FunctionName => nameof(GetTabIDs);
57
61 public override string[] DefaultArgumentNames => new string[] { "Page", "QueryFilter" };
62
70 {
71 return new ObjectVector(GetTabs(Arguments, this));
72 }
73
80 public static string[] GetTabs(IElement[] Arguments, ScriptNode Node)
81 {
82 switch (Arguments.Length)
83 {
84 case 0:
85 return ClientEvents.GetTabIDs();
86
87 case 1:
88 object Obj = Arguments[0].AssociatedObjectValue;
89 if (Obj is Array A)
90 {
91 if (!(A is string[] Pages))
92 Pages = (string[])Expression.ConvertTo(A, typeof(string[]), Node);
93
95 }
96 else if (Obj is IUser User)
97 return ClientEvents.GetTabIDsForUser(User);
98 else if (Obj is null)
99 return new string[0];
100 else
102
103 case 2:
104 return ClientEvents.GetTabIDsForLocation(Arguments[0].AssociatedObjectValue?.ToString(),
105 GetQueryFilter(Arguments[1], Node));
106
107 default:
108 return new string[0];
109 }
110 }
111
112 private static KeyValuePair<string, string>[] GetQueryFilter(IElement Argument, ScriptNode Node)
113 {
114 if (!(Argument.AssociatedObjectValue is IDictionary<string, IElement> Obj))
115 throw new ScriptRuntimeException("Query filter must be an object ex nihilo.", Node);
116
117 List<KeyValuePair<string, string>> Result = new List<KeyValuePair<string, string>>();
118
119 foreach (KeyValuePair<string, IElement> P in Obj)
120 Result.Add(new KeyValuePair<string, string>(P.Key, P.Value.AssociatedObjectValue?.ToString()));
121
122 return Result.ToArray();
123 }
124 }
125}
The ClientEvents class allows applications to push information asynchronously to web clients connecte...
Definition: ClientEvents.cs:51
static string[] GetTabIDsForLocation(string Location)
Gets the Tab IDs of all tabs that display a particular resource.
static string[] GetTabIDsForLocations(params string[] Locations)
Gets the Tab IDs of all tabs that display a set of resources.
static string[] GetTabIDsForUser(object User)
Gets the Tab IDs of all tabs that a specific user views.
static string[] GetTabIDs()
Gets all open Tab IDs.
Gets an array of Tab IDs (as strings) of currently open pages, given certain conditions.
Definition: GetTabIDs.cs:16
GetTabIDs(ScriptNode Page, ScriptNode QueryFilter, int Start, int Length, Expression Expression)
Gets an array of Tab IDs (as strings) of currently open pages, given certain conditions.
Definition: GetTabIDs.cs:48
GetTabIDs(ScriptNode Page, int Start, int Length, Expression Expression)
Gets an array of Tab IDs (as strings) of currently open pages, given certain conditions.
Definition: GetTabIDs.cs:35
static string[] GetTabs(IElement[] Arguments, ScriptNode Node)
Gets TabIDs based in restrictions in input arguments.
Definition: GetTabIDs.cs:80
override IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the function.
Definition: GetTabIDs.cs:69
override string[] DefaultArgumentNames
Default Argument names
Definition: GetTabIDs.cs:61
GetTabIDs(int Start, int Length, Expression Expression)
Gets an array of Tab IDs (as strings) of currently open pages, given certain conditions.
Definition: GetTabIDs.cs:23
override string FunctionName
Name of the function
Definition: GetTabIDs.cs:56
Class managing a script expression.
Definition: Expression.cs:39
static object ConvertTo(IElement Value, Type DesiredType, ScriptNode Node)
Tries to conevert an element value to a desired type.
Definition: Expression.cs:5127
Base class for multivariate funcions.
ScriptNode[] Arguments
Function arguments.
static readonly ArgumentType[] argumentTypes2Scalar
Two scalar parameters.
static readonly ArgumentType[] argumentTypes0
Zero parameters.
static readonly ArgumentType[] argumentTypes1Normal
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
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20
object AssociatedObjectValue
Associated object value.
Definition: IElement.cs:33
Basic interface for a user.
Definition: IUser.cs:7