예제 #1
0
파일: Update.cs 프로젝트: iamr8/IoTGateway
        /// <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
        /// <summary>
        /// Evaluates the node, using the variables provided in the <paramref name="Variables"/> collection.
        /// </summary>
        /// <param name="Variables">Variables collection.</param>
        /// <returns>Result.</returns>
        public override IElement Evaluate(Variables Variables)
        {
            IElement E = this.source.Evaluate(Variables);

            if (!(E.AssociatedObjectValue is Type T))
            {
                throw new ScriptRuntimeException("Type expected.", this.source);
            }

            IEnumerator         e        = Select.Find(T, 0, int.MaxValue, this.where, Variables, new string[0], this);
            LinkedList <object> ToUpdate = new LinkedList <object>();
            int Count = 0;

            while (e.MoveNext())
            {
                ObjectProperties Properties = new ObjectProperties(e.Current, Variables, false);

                foreach (Assignment SetOperation in this.setOperations)
                {
                    SetOperation.Evaluate(Properties);
                }

                ToUpdate.AddLast(e.Current);
                Count++;
            }

            Database.Update(ToUpdate);

            return(new DoubleNumber(Count));
        }