/// <summary> /// Evaluates the node asynchronously, using the variables provided in /// the <paramref name="Variables"/> collection. /// </summary> /// <param name="Variables">Variables collection.</param> /// <returns>Result.</returns> public async Task <IElement> EvaluateAsync(Variables Variables) { IDataSource Source = this.source.GetSource(Variables); IResultSetEnumerator e = await Source.Find(0, int.MaxValue, this.where, Variables, new KeyValuePair <VariableReference, bool> [0], this); LinkedList <object> ToUpdate = new LinkedList <object>(); int Count = 0; while (await e.MoveNextAsync()) { if (this.properties is null) { this.properties = new ObjectProperties(e.Current, Variables, false); } else { this.properties.Object = e.Current; } foreach (Assignment SetOperation in this.setOperations) { SetOperation.Evaluate(this.properties); } ToUpdate.AddLast(e.Current); Count++; } await Source.Update(ToUpdate); return(new DoubleNumber(Count)); }
/// <summary> /// Evaluates the node asynchronously, using the variables provided in /// the <paramref name="Variables"/> collection. /// </summary> /// <param name="Variables">Variables collection.</param> /// <returns>Result.</returns> public async Task <IElement> EvaluateAsync(Variables Variables) { IDataSource Source = this.source.GetSource(Variables); IResultSetEnumerator e = await Source.Find(0, int.MaxValue, this.where, Variables, new KeyValuePair <VariableReference, bool> [0], this); LinkedList <object> ToDelete = new LinkedList <object>(); int Count = 0; while (await e.MoveNextAsync()) { ToDelete.AddLast(e.Current); Count++; } await Source.Delete(ToDelete); return(new DoubleNumber(Count)); }
/// <summary> /// Advances the enumerator to the next element of the collection. /// </summary> /// <returns>true if the enumerator was successfully advanced to the next element; false if /// the enumerator has passed the end of the collection.</returns> /// <exception cref="InvalidOperationException">The collection was modified after the enumerator was created.</exception> public async Task <bool> MoveNextAsync() { Dictionary <string, List <object> > Aggregated = null; ObjectProperties Variables = null; IElement E; object[] Last = null; int i, c = this.groupBy.Length; object o1, o2; while (this.processLast || await e.MoveNextAsync()) { this.processLast = false; Variables = new ObjectProperties(e.Current, this.variables); if (Last is null) { Last = new object[c]; for (i = 0; i < c; i++) { E = this.groupBy[i].Evaluate(Variables); Last[i] = E.AssociatedObjectValue; } } else { for (i = 0; i < c; i++) { E = this.groupBy[i].Evaluate(Variables); o1 = Last[i]; o2 = E.AssociatedObjectValue; if (o1 is null ^ o2 is null) { break; } if (o1 != null && !o1.Equals(o2)) { break; } } if (i < c) { this.processLast = true; break; } } o1 = e.Current; Type T = o1.GetType(); if (T != this.lastType) { this.lastType = T; this.properties = T.GetRuntimeProperties(); this.fields = T.GetRuntimeFields(); } if (Aggregated is null) { Aggregated = new Dictionary <string, List <object> >(); } foreach (PropertyInfo PI in this.properties) { if (!PI.CanRead || !PI.CanWrite) { continue; } if (!Aggregated.TryGetValue(PI.Name, out List <object> List)) { List = new List <object>(); Aggregated[PI.Name] = List; } List.Add(PI.GetValue(o1)); } foreach (FieldInfo FI in this.fields) { if (!Aggregated.TryGetValue(FI.Name, out List <object> List)) { List = new List <object>(); Aggregated[FI.Name] = List; } List.Add(FI.GetValue(o1)); } } if (Aggregated is null) { return(false); } Dictionary <string, object> Result = new Dictionary <string, object>(); bool First = true; foreach (KeyValuePair <string, List <object> > Rec in Aggregated) { object[] A = Rec.Value.ToArray(); Result[Rec.Key] = A; if (First) { First = false; Result[" First "] = A; } } if (this.groupNames != null) { for (i = 0; i < c; i++) { ScriptNode Node = this.groupNames[i]; if (Node is null) { continue; } if (Node is VariableReference Ref) { Result[Ref.VariableName] = Last[i]; } else { E = this.groupNames[i]?.Evaluate(Variables); if (E != null && E is StringValue S) { Result[S.Value] = Last[i]; } } } } this.current = Result; return(true); }
/// <summary> /// Advances the enumerator to the next element of the collection. /// </summary> /// <returns>true if the enumerator was successfully advanced to the next element; false if /// the enumerator has passed the end of the collection.</returns> /// <exception cref="InvalidOperationException">The collection was modified after the enumerator was created.</exception> public async Task <bool> MoveNextAsync() { List <object> Objects = null; IElement E; object[] Last = null; int i, c = this.groupBy.Length; object o1, o2; while (this.processLast || await e.MoveNextAsync()) { this.processLast = false; if (this.objectVariables is null) { this.objectVariables = new ObjectProperties(e.Current, this.variables); } else { this.objectVariables.Object = e.Current; } if (Last is null) { Last = new object[c]; for (i = 0; i < c; i++) { E = this.groupBy[i].Evaluate(this.objectVariables); Last[i] = E.AssociatedObjectValue; } } else { for (i = 0; i < c; i++) { E = this.groupBy[i].Evaluate(this.objectVariables); o1 = Last[i]; o2 = E.AssociatedObjectValue; if (o1 is null ^ o2 is null) { break; } if (!(o1 is null) && !o1.Equals(o2)) { break; } } if (i < c) { this.processLast = true; break; } } if (Objects is null) { Objects = new List <object>(); } Objects.Add(e.Current); } if (Objects is null) { return(false); } this.current = new GroupObject(Objects.ToArray(), Last, this.groupNames, this.variables); return(true); }