Ejemplo n.º 1
0
        /// <summary>
        /// Adds the node.
        /// </summary>
        /// <param name="node">The query node.</param>
        /// <exception cref="ArgumentException">Cannot add two conditions in succession</exception>
        protected virtual void AddNode(QueryNode node)
        {
            Query query = node.Element as Query;

            if (query != null && this.Equals(query))
            {
                throw new ArgumentException("Cannot insert same query in it self");
            }

            if (this.IsEmpty() && node.Element is Condition)
            {
                throw new ArgumentException("First argument cannot be a condition");
            }

            if (node.IsQuery() && ((Query)node.Element).IsEmpty())
            {
                throw new ArgumentException("Query is invalid");
            }

            if (this.IsEmpty())
            {
                this.FirstNode = node;
                this.LastNode  = node;
            }
            else
            {
                if (this.LastNode.Element is Condition && node.Element is Condition)
                {
                    throw new ArgumentException("Cannot add two conditions in succession");
                }

                if (this.LastNode.Element is SubQuery && node.Element is SubQuery)
                {
                    throw new ArgumentException("Cannot add two subqueries without condition");
                }

                if (this.FirstNode.NextNode == null)
                {
                    this.FirstNode.NextNode = node;
                }
                else
                {
                    node.PreviousNode      = this.LastNode;
                    this.LastNode.NextNode = node;
                }

                this.LastNode = node;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Determines whether [contains] [the specified node].
        /// </summary>
        /// <param name="node">The query node.</param>
        /// <param name="query">The query.</param>
        /// <returns>
        /// <c>true</c> if [contains] [the specified node]; otherwise, <c>false</c>.
        /// </returns>
        protected virtual bool Contains(QueryNode node, SubQuery query)
        {
            if (node.Element.Equals(query))
            {
                return(true);
            }

            if (node.IsQuery())
            {
                return(this.Contains(((Query)node.Element).FirstNode, query));
            }

            if (!node.IsLast)
            {
                return(this.Contains(node.NextNode, query));
            }

            return(false);
        }
Ejemplo n.º 3
0
    /// <summary>
    /// Adds the node.
    /// </summary>
    /// <param name="node">The query node.</param>
    /// <exception cref="ArgumentException">Cannot add two conditions in succession</exception>
    protected virtual void AddNode(QueryNode node)
    {
      Query query = node.Element as Query;

      if (query != null && this.Equals(query))
      {
        throw new ArgumentException("Cannot insert same query in it self");
      }

      if (this.IsEmpty() && node.Element is Condition)
      {
        throw new ArgumentException("First argument cannot be a condition");
      }

      if (node.IsQuery() && ((Query)node.Element).IsEmpty())
      {
        throw new ArgumentException("Query is invalid");
      }

      if (this.IsEmpty())
      {
        this.FirstNode = node;
        this.LastNode = node;
      }
      else
      {
        if (this.LastNode.Element is Condition && node.Element is Condition)
        {
          throw new ArgumentException("Cannot add two conditions in succession");
        }

        if (this.LastNode.Element is SubQuery && node.Element is SubQuery)
        {
          throw new ArgumentException("Cannot add two subqueries without condition");
        }

        if (this.FirstNode.NextNode == null)
        {
          this.FirstNode.NextNode = node;
        }
        else
        {
          node.PreviousNode = this.LastNode;
          this.LastNode.NextNode = node;
        }

        this.LastNode = node;
      }
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Determines whether [contains] [the specified node].
    /// </summary>
    /// <param name="node">The query node.</param>
    /// <param name="query">The query.</param>
    /// <returns>
    /// <c>true</c> if [contains] [the specified node]; otherwise, <c>false</c>.
    /// </returns>
    protected virtual bool Contains(QueryNode node, SubQuery query)
    {
      if (node.Element.Equals(query))
      {
        return true;
      }

      if (node.IsQuery())
      {
        return this.Contains(((Query)node.Element).FirstNode, query);
      }

      if (!node.IsLast)
      {
        return this.Contains(node.NextNode, query);
      }

      return false;
    }