示例#1
0
        /// <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));
        }
示例#2
0
            public async Task <bool> MoveNextAsync()
            {
                while (true)
                {
                    if (!(this.right is null))
                    {
                        if (await this.right.MoveNextAsync())
                        {
                            this.current = new JoinedObject(this.left.Current, this.leftName,
                                                            this.right.Current, this.rightName);

                            return(true);
                        }
                        else
                        {
                            this.right = null;
                        }
                    }

                    if (!await this.left.MoveNextAsync())
                    {
                        return(false);
                    }

                    ObjectProperties LeftVariables = new ObjectProperties(this.left.Current, this.variables);

                    if (this.hasLeftName)
                    {
                        LeftVariables[this.leftName] = this.left.Current;
                    }

                    this.right = await this.rightSource.Find(0, int.MaxValue, this.conditions, LeftVariables,
                                                             null, this.conditions);
                }
            }
 public FullOuterJoinEnumerator(IResultSetEnumerator Left, IResultSetEnumerator Right)
 {
     this.leftEnum  = Left;
     this.rightEnum = Right;
     this.leftMode  = true;
     this.current   = null;
 }
示例#4
0
 /// <summary>
 /// Enumerator that groups items into groups, and returns aggregated elements.
 /// </summary>
 /// <param name="ItemEnumerator">Item enumerator</param>
 /// <param name="Variables">Current set of variables</param>
 /// <param name="GroupBy">Group on these fields</param>
 /// <param name="GroupNames">Names given to grouped fields</param>
 public GroupEnumerator(IResultSetEnumerator ItemEnumerator, Variables Variables, ScriptNode[] GroupBy, ScriptNode[] GroupNames)
 {
     this.e          = ItemEnumerator;
     this.variables  = Variables;
     this.groupBy    = GroupBy;
     this.groupNames = GroupNames;
 }
        /// <summary>
        /// Finds objects matching filter conditions in <paramref name="Where"/>.
        /// </summary>
        /// <param name="Offset">Offset at which to return elements.</param>
        /// <param name="Top">Maximum number of elements to return.</param>
        /// <param name="Where">Filter conditions.</param>
        /// <param name="Variables">Current set of variables.</param>
        /// <param name="Order">Order at which to order the result set.</param>
        /// <param name="Node">Script node performing the evaluation.</param>
        /// <returns>Enumerator.</returns>
        public override async Task <IResultSetEnumerator> Find(int Offset, int Top, ScriptNode Where, Variables Variables,
                                                               KeyValuePair <VariableReference, bool>[] Order, ScriptNode Node)
        {
            ScriptNode LeftWhere = await Reduce(this.Left, Where);

            KeyValuePair <VariableReference, bool>[] LeftOrder = await Reduce(this.Left, Order);

            IResultSetEnumerator e = await this.Left.Find(0, int.MaxValue,
                                                          LeftWhere, Variables, LeftOrder, Node);

            ScriptNode RightWhere = this.Combine(await Reduce(this.Right, this.Left, Where), this.Conditions);

            e = new LeftOuterJoinEnumerator(e, this.Left.Name, this.Right, this.Right.Name,
                                            RightWhere, Variables, this.Flipped);

            if (!(Where is null))
            {
                e = new ConditionalEnumerator(e, Variables, Where);
            }

            if (Offset > 0)
            {
                e = new OffsetEnumerator(e, Offset);
            }

            if (Top != int.MaxValue)
            {
                e = new MaxCountEnumerator(e, Top);
            }

            return(e);
        }
示例#6
0
 /// <summary>
 /// Enumerator that limits the return set to a maximum number of records.
 /// </summary>
 /// <param name="ItemEnumerator">Item enumerator</param>
 /// <param name="Columns">Column definitions. Might be null if objects are to be returned.</param>
 /// <param name="Variables">Current set of variables.</param>
 public RecordEnumerator(IResultSetEnumerator ItemEnumerator, ScriptNode[] Columns, Variables Variables)
 {
     this.e         = ItemEnumerator;
     this.columns   = Columns;
     this.variables = Variables;
     this.count     = this.columns?.Length ?? 0;
 }
示例#7
0
 public InnerJoinEnumerator(IResultSetEnumerator Left, string LeftName,
                            IDataSource RightSource, string RightName, ScriptNode Conditions,
                            Variables Variables)
 {
     this.left        = Left;
     this.leftName    = LeftName;
     this.rightName   = RightName;
     this.rightSource = RightSource;
     this.conditions  = Conditions;
     this.variables   = Variables;
     this.hasLeftName = !string.IsNullOrEmpty(this.leftName);
 }
示例#8
0
        /// <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));
        }
示例#9
0
 /// <summary>
 /// Enumerator that reorders a sequence of items.
 /// </summary>
 /// <param name="ItemEnumerator">Item enumerator</param>
 /// <param name="Variables">Current set of variables.</param>
 /// <param name="Order">Custom order.</param>
 public CustomOrderEnumerator(IResultSetEnumerator ItemEnumerator, Variables Variables, KeyValuePair <ScriptNode, bool>[] Order)
 {
     this.order     = Order;
     this.items     = ItemEnumerator;
     this.variables = Variables;
 }
 public void Reset()
 {
     this.current = null;
     this.right   = null;
     this.left.Reset();
 }
            public async Task <bool> MoveNextAsync()
            {
                while (true)
                {
                    if (!(this.right is null))
                    {
                        bool First = this.rightFirst;
                        this.rightFirst = false;

                        if (await this.right.MoveNextAsync())
                        {
                            if (this.flipped)
                            {
                                this.current = new JoinedObject(this.right.Current, this.rightName,
                                                                this.left.Current, this.leftName);
                            }
                            else
                            {
                                this.current = new JoinedObject(this.left.Current, this.leftName,
                                                                this.right.Current, this.rightName);
                            }

                            return(true);
                        }
                        else
                        {
                            this.right = null;

                            if (First)
                            {
                                if (this.defaultRight is null)
                                {
                                    this.defaultRight = new GenericObject(this.rightSource.CollectionName,
                                                                          typeof(GenericObject).FullName, Guid.Empty,
                                                                          new KeyValuePair <string, object> [0]);
                                }

                                if (this.flipped)
                                {
                                    this.current = new JoinedObject(this.defaultRight, this.rightName,
                                                                    this.left.Current, this.leftName);
                                }
                                else
                                {
                                    this.current = new JoinedObject(this.left.Current, this.leftName,
                                                                    this.defaultRight, this.rightName);
                                }

                                return(true);
                            }
                        }
                    }

                    if (!await this.left.MoveNextAsync())
                    {
                        return(false);
                    }

                    ObjectProperties LeftVariables = new ObjectProperties(this.left.Current, this.variables);

                    if (this.hasLeftName)
                    {
                        LeftVariables[this.leftName] = this.left.Current;
                    }

                    this.right = await this.rightSource.Find(0, int.MaxValue, this.conditions, LeftVariables,
                                                             null, this.conditions);

                    this.rightFirst = true;
                }
            }
 /// <summary>
 /// Enumerator that limits the return set to a maximum number of records.
 /// </summary>
 /// <param name="ItemEnumerator">Item enumerator</param>
 /// <param name="Count">Maximum number of records to enumerate.</param>
 public MaxCountEnumerator(IResultSetEnumerator ItemEnumerator, int Count)
 {
     this.e     = ItemEnumerator;
     this.count = this.count0 = Count;
 }
 /// <summary>
 /// Enumerator that limits the return set to a maximum number of records.
 /// </summary>
 /// <param name="ItemEnumerator">Item enumerator</param>
 /// <param name="Columns">Column definitions. Might be null if objects are to be returned.</param>
 /// <param name="Variables">Current set of variables.</param>
 public DistinctEnumerator(IResultSetEnumerator ItemEnumerator, ScriptNode[] Columns, Variables Variables)
     : base(ItemEnumerator, Columns, Variables)
 {
 }
示例#14
0
 /// <summary>
 /// Enumerator that only returns elements matching a set of conditions.
 /// </summary>
 /// <param name="ItemEnumerator">Item enumerator</param>
 /// <param name="Variables">Current set of variables.</param>
 /// <param name="Conditions">Set of conditions that must be fulfilled.</param>
 public ConditionalEnumerator(IResultSetEnumerator ItemEnumerator, Variables Variables, ScriptNode Conditions)
 {
     this.e          = ItemEnumerator;
     this.variables  = Variables;
     this.conditions = Conditions;
 }
示例#15
0
 /// <summary>
 /// Enumerator that skips a given number of result records.
 /// </summary>
 /// <param name="ItemEnumerator">Item enumerator</param>
 /// <param name="Offset">Number of records to skip.</param>
 public OffsetEnumerator(IResultSetEnumerator ItemEnumerator, int Offset)
 {
     this.e      = ItemEnumerator;
     this.offset = this.offset0 = Offset;
 }
示例#16
0
 /// <summary>
 /// Enumerator that adds fields to enumerated items.
 /// </summary>
 /// <param name="ItemEnumerator">Item enumerator</param>
 /// <param name="Variables">Current set of variables</param>
 /// <param name="AdditionalFields">Fields to add to enumerated items.</param>
 public FieldAggregatorEnumerator(IResultSetEnumerator ItemEnumerator, Variables Variables, KeyValuePair <string, ScriptNode>[] AdditionalFields)
 {
     this.e                = ItemEnumerator;
     this.variables        = Variables;
     this.additionalFields = AdditionalFields;
 }