コード例 #1
0
ファイル: Update.cs プロジェクト: iamr8/IoTGateway
        /// <summary>
        /// Calls the callback method for all child nodes.
        /// </summary>
        /// <param name="Callback">Callback method to call.</param>
        /// <param name="State">State object to pass on to the callback method.</param>
        /// <param name="DepthFirst">If calls are made depth first (true) or on each node and then its leaves (false).</param>
        /// <returns>If the process was completed.</returns>
        public override bool ForAllChildNodes(ScriptNodeEventHandler Callback, object State, bool DepthFirst)
        {
            if (DepthFirst)
            {
                if (!(this.source?.ForAllChildNodes(Callback, State, DepthFirst) ?? true))
                {
                    return(false);
                }

                foreach (Assignment SetOperation in this.setOperations)
                {
                    if (!(SetOperation?.ForAllChildNodes(Callback, State, DepthFirst) ?? true))
                    {
                        return(false);
                    }
                }

                if (!(this.where?.ForAllChildNodes(Callback, State, DepthFirst) ?? true))
                {
                    return(false);
                }
            }

            ScriptNode Node = this.source;

            if (!(Node is null) && !Callback(ref Node, State))
            {
                return(false);
            }

            if (Node != this.source)
            {
                if (Node is SourceDefinition Source2)
                {
                    this.source = Source2;
                }
                else
                {
                    return(false);
                }
            }

            int i, c = this.setOperations.Length;

            for (i = 0; i < c; i++)
            {
                ScriptNode SetOperation = this.setOperations[i];

                if (!(SetOperation is null))
                {
                    if (!Callback(ref SetOperation, State))
                    {
                        return(false);
                    }

                    if (SetOperation is Assignment Assignment)
                    {
                        this.setOperations[i] = Assignment;
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            if (!(this.where is null) && !Callback(ref this.where, State))
            {
                return(false);
            }

            if (!DepthFirst)
            {
                if (!(this.source?.ForAllChildNodes(Callback, State, DepthFirst) ?? true))
                {
                    return(false);
                }

                foreach (Assignment SetOperation in this.setOperations)
                {
                    if (!(SetOperation?.ForAllChildNodes(Callback, State, DepthFirst) ?? true))
                    {
                        return(false);
                    }
                }

                if (!(this.where?.ForAllChildNodes(Callback, State, DepthFirst) ?? true))
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
ファイル: Update.cs プロジェクト: kalayaphat/IoTGateway
        /// <summary>
        /// Calls the callback method for all child nodes.
        /// </summary>
        /// <param name="Callback">Callback method to call.</param>
        /// <param name="State">State object to pass on to the callback method.</param>
        /// <param name="DepthFirst">If calls are made depth first (true) or on each node and then its leaves (false).</param>
        /// <returns>If the process was completed.</returns>
        public override bool ForAllChildNodes(ScriptNodeEventHandler Callback, object State, bool DepthFirst)
        {
            if (DepthFirst)
            {
                if (!this.source.ForAllChildNodes(Callback, State, DepthFirst))
                {
                    return(false);
                }

                foreach (Assignment SetOperation in this.setOperations)
                {
                    if (!SetOperation.ForAllChildNodes(Callback, State, DepthFirst))
                    {
                        return(false);
                    }
                }

                if (this.where != null)
                {
                    if (!this.where.ForAllChildNodes(Callback, State, DepthFirst))
                    {
                        return(false);
                    }
                }
            }

            if (!Callback(ref this.source, State))
            {
                return(false);
            }

            int i, c = this.setOperations.Length;

            for (i = 0; i < c; i++)
            {
                ScriptNode SetOperation = this.setOperations[i];

                if (!Callback(ref SetOperation, State))
                {
                    return(false);
                }

                if (SetOperation is Assignment Assignment)
                {
                    this.setOperations[i] = Assignment;
                }
                else
                {
                    return(false);
                }
            }

            if (this.where != null)
            {
                if (!Callback(ref this.where, State))
                {
                    return(false);
                }
            }

            if (!DepthFirst)
            {
                if (!this.source.ForAllChildNodes(Callback, State, DepthFirst))
                {
                    return(false);
                }

                foreach (Assignment SetOperation in this.setOperations)
                {
                    if (!SetOperation.ForAllChildNodes(Callback, State, DepthFirst))
                    {
                        return(false);
                    }
                }

                if (this.where != null)
                {
                    if (!this.where.ForAllChildNodes(Callback, State, DepthFirst))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }