3using System.Reflection;
4using System.Threading.Tasks;
24 private readonly Dictionary<Type, bool> types =
new Dictionary<Type, bool>();
25 private readonly Dictionary<string, bool> isLabel =
new Dictionary<string, bool>();
26 private readonly
IVector vector;
28 private readonly
string name;
29 private readonly
string alias;
51 if (T is
null || T == LastType)
76 KeyValuePair<VariableReference, bool>[] Order,
ScriptNode Node)
78 return Find(this.vector, Offset, Top, Generic, Where,
Variables, Order, Node);
95 KeyValuePair<VariableReference, bool>[] Order,
ScriptNode Node)
100 if (!(Where is
null))
103 if ((c = Order?.Length ?? 0) > 0)
105 List<IElement> Items =
new List<IElement>();
115 IComparer<IElement> Order2;
118 Order2 = ToPropertyOrder(Node, Order[0]);
121 IComparer<IElement>[] Orders =
new IComparer<IElement>[c];
123 for (i = 0; i < c; i++)
124 Orders[i] = ToPropertyOrder(Node, Order[i]);
137 if (Top !=
int.MaxValue)
145 return new PropertyOrder(Node, Order.Key.VariableName, Order.Value ? 1 : -1);
165 return Process(Processor, this.vector, Offset, Top, Generic, Where,
Variables, Order, Node);
170 KeyValuePair<VariableReference, bool>[] Order,
ScriptNode Node)
184 if (!Processor.
Process(e.Current))
197 public Task
Update(
bool Lazy, IEnumerable<object> Objects)
199 return Task.CompletedTask;
202 private Exception InvalidOperation()
219 KeyValuePair<VariableReference, bool>[] Order,
ScriptNode Node)
221 throw this.InvalidOperation();
229 public Task
Insert(
bool Lazy,
object Object)
231 throw this.InvalidOperation();
255 get =>
string.IsNullOrEmpty(this.alias) ? this.name : this.alias;
266 string.Compare(this.name,
Name,
true) == 0 ||
267 string.Compare(this.alias,
Name,
true) == 0;
279 if (!this.isLabel.TryGetValue(Label, out
bool Result))
283 foreach (Type T
in this.types.Keys)
285 PropertyInfo PI = T.GetRuntimeProperty(Label);
289 FieldInfo FI = T.GetRuntimeField(Label);
293 Result = FI.IsPublic;
299 Result = PI.CanRead && PI.GetMethod.IsPublic;
304 this.isLabel[Label] = Result;
307 return Task.FromResult<
bool>(Result);
318 throw this.InvalidOperation();
328 throw this.InvalidOperation();
336 throw this.InvalidOperation();
348 throw new ArgumentException(
"Result Set lacks named columns.", nameof(ResultSet));
350 int Rows = ResultSet.
Rows;
351 int Columns = ResultSet.
Columns;
354 Dictionary<string, object> Object;
357 for (y = 0; y < Rows; y++)
359 Object =
new Dictionary<string, object>();
362 for (x = 0; x < Columns; x++)
Script runtime exception.
Class managing a script expression.
static IElement Encapsulate(object Value)
Encapsulates an object.
Base class for all nodes in a parsed script tree.
IElement GetElement(int Index)
Gets an element of the vector.
bool HasColumnNames
If the matrix has column names defined.
int Columns
Number of columns.
string[] ColumnNames
Contains optional column names.
Orders elements based on a sequence of comparers.
Orders elements based on values of a given property.
Creates a generalized representation of an object.
override Task< IElement > EvaluateAsync(IElement Argument, Variables Variables)
Evaluates the function.
Enumerator that only returns elements matching a set of conditions.
Enumerator that limits the return set to a maximum number of records.
Enumerator that skips a given number of result records.
Data Source defined by a vector.
VectorSource(string Name, string Alias, IVector Vector, ScriptNode Node)
Data Source defined by a vector.
Task< bool > DropIndex(string Name)
Drops an index from the source.
Task Update(bool Lazy, IEnumerable< object > Objects)
Updates a set of objects.
Task Insert(bool Lazy, object Object)
Inserts an object.
string TypeName
Name of corresponding type.
Task< bool > IsLabel(string Label)
Checks if the label is a label in the source.
static ObjectVector ToGenericObjectVector(ObjectMatrix ResultSet)
Converts an object matrix, with named columns, to a vector of objects ex nihilo.
static async Task< IResultSetEnumerator > Find(IVector Vector, int Offset, int Top, bool Generic, ScriptNode Where, Variables Variables, KeyValuePair< VariableReference, bool >[] Order, ScriptNode Node)
Finds elements in a vector.
string Name
Collection name or alias.
Task CreateIndex(string Name, string[] Fields)
Creates an index in the source.
Task< int?> Delete(bool Lazy, int Offset, int Top, ScriptNode Where, Variables Variables, KeyValuePair< VariableReference, bool >[] Order, ScriptNode Node)
Deletes a set of objects.
Task< IResultSetEnumerator > Find(int Offset, int Top, bool Generic, ScriptNode Where, Variables Variables, KeyValuePair< VariableReference, bool >[] Order, ScriptNode Node)
Finds objects matching filter conditions in Where .
bool IsSource(string Name)
Checks if the name refers to the source.
Task DropCollection()
Drops the collection specified by the source.
string CollectionName
Name of corresponding collection.
Task< bool > Process(IProcessor< object > Processor, int Offset, int Top, bool Generic, ScriptNode Where, Variables Variables, KeyValuePair< VariableReference, bool >[] Order, ScriptNode Node)
Processes objects matching filter conditions in Where .
Task< bool > MoveNextAsync()
Advances the enumerator to the next element of the collection.
Interface for processors of objects.
bool Process(T Object)
Processes an object synchronously.
bool IsAsynchronous
If the processor operates asynchronously.
Task< bool > ProcessAsync(T Object)
Processes an object asynchronously.
Basic interface for all types of elements.
object AssociatedObjectValue
Associated object value.
ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
Basic interface for vectors.
ICollection< IElement > VectorElements
An enumeration of vector elements.
Interface for result-set enumerators.
Interface for data sources that can be used in SQL statements.