Beispiel #1
0
        /// <summary>
        /// Gets the stringified query expression format of the current instance. A formatted string for field-operation-parameter will be
        /// conjuncted by the value of the <see cref="RepoDb.Enumerations.Conjunction"/> property.
        /// </summary>
        /// <param name="index">The parameter index for batch operation.</param>
        /// <param name="dbSetting">The currently in used <see cref="IDbSetting"/> object.</param>
        /// <returns>A stringified formatted-text of the current instance.</returns>
        public string GetString(int index,
                                IDbSetting dbSetting)
        {
            // Fix first the parameters
            Fix();

            // Variables
            var groupList   = new List <string>();
            var conjunction = Conjunction.GetText();
            var separator   = string.Concat(" ", conjunction, " ");

            // Check the instance fields
            var queryFields = QueryFields.AsList();

            if (queryFields?.Count > 0)
            {
                var fields = QueryFields
                             .Select(qf =>
                                     qf.AsFieldAndParameter(index, dbSetting)).Join(separator);
                groupList.Add(fields);
            }

            // Check the instance groups
            var queryGroups = QueryGroups.AsList();

            if (queryGroups?.Count > 0)
            {
                var groups = QueryGroups
                             .Select(qg => qg.GetString(index, dbSetting)).Join(separator);
                groupList.Add(groups);
            }

            // Return the value
            return(IsNot ? string.Concat("NOT (", groupList.Join(conjunction), ")") : string.Concat("(", groupList.Join(separator), ")"));
        }
Beispiel #2
0
        /// <summary>
        /// Gets the stringified query expression format of the current instance. A formatted string for field-operation-parameter will be
        /// conjuncted by the value of the <see cref="Conjunction"/> property.
        /// </summary>
        /// <returns>A stringified formatted-text of the current instance.</returns>
        public string GetString()
        {
            var groupList   = new List <string>();
            var conjunction = GetConjunctionText();
            var separator   = string.Concat(" ", conjunction, " ");

            if (QueryFields != null && QueryFields.Any())
            {
                var fieldList = new List <string>();
                QueryFields.ToList().ForEach(queryField =>
                {
                    fieldList.Add(queryField.AsFieldAndParameter());
                });
                groupList.Add(fieldList.Join(separator));
            }
            if (QueryGroups != null && QueryGroups.Any())
            {
                var fieldList = new List <string>();
                QueryGroups.ToList().ForEach(queryGroup =>
                {
                    fieldList.Add(queryGroup.GetString());
                });
                groupList.Add(fieldList.Join(separator));
            }
            return(IsNot ? string.Concat("NOT (", groupList.Join(conjunction), ")") : string.Concat("(", groupList.Join(separator), ")"));
        }
Beispiel #3
0
        /// <summary>
        /// Gets the stringified query expression format of the current instance. A formatted string for field-operation-parameter will be
        /// conjuncted by the value of the <see cref="Conjunction"/> property.
        /// </summary>
        /// <returns>A stringified formatted-text of the current instance.</returns>
        public string GetString()
        {
            var groupList   = new List <string>();
            var conjunction = GetConjunctionText();
            var separator   = string.Concat(" ", conjunction, " ");

            if (QueryFields?.Count() > 0)
            {
                var fieldList = new List <string>();
                foreach (var queryField in QueryFields)
                {
                    fieldList.Add(queryField.AsFieldAndParameter());
                }
                groupList.Add(fieldList.Join(separator));
            }
            if (QueryGroups?.Count() > 0)
            {
                var fieldList = new List <string>();
                foreach (var queryGroup in QueryGroups)
                {
                    fieldList.Add(queryGroup.GetString());
                }
                groupList.Add(fieldList.Join(separator));
            }
            return(IsNot ? string.Concat("NOT (", groupList.Join(conjunction), ")") : string.Concat("(", groupList.Join(separator), ")"));
        }
Beispiel #4
0
        /// <summary>
        /// Reset the <see cref="QueryGroup"/> back to its default state (as is newly instantiated).
        /// </summary>
        public void Reset()
        {
            // Rest all fields
            if (QueryFields?.Any() == true)
            {
                foreach (var field in QueryFields)
                {
                    field.Reset();
                }
            }

            // Rest all groups
            if (QueryGroups?.Any() == true)
            {
                foreach (var group in QueryGroups)
                {
                    group.Reset();
                }
            }

            // Reset the attribute
            m_conjuctionTextAttribute = null;
            m_isFixed = false;

            // Reset the hash code
            m_hashCode = null;
        }
Beispiel #5
0
 /// <summary>
 /// Reset all the query groups.
 /// </summary>
 private void ResetQueryGroups()
 {
     if (QueryGroups?.Any() != true)
     {
         return;
     }
     foreach (var group in QueryGroups)
     {
         group.Reset();
     }
 }
Beispiel #6
0
 /// <summary>
 /// Forces to set the <see cref="isFixed"/> variable to True.
 /// </summary>
 private void ForceIsFixedVariables()
 {
     if (QueryGroups?.Any() == true)
     {
         foreach (var queryGroup in QueryGroups)
         {
             queryGroup.ForceIsFixedVariables();
         }
     }
     isFixed = true;
 }
Beispiel #7
0
        /// <summary>
        /// Force to set the <see cref="m_isFixed"/> variable to True.
        /// </summary>
        private void ForceFix()
        {
            // Set the flags of the children
            if (QueryGroups?.Any() == true)
            {
                foreach (var queryGroup in QueryGroups)
                {
                    queryGroup.ForceFix();
                }
            }

            // Set the flag of the current instance
            m_isFixed = true;
        }
        public void TestRemoveGroupAndEntities()
        {
            CreateTestEntity(0, Groups.GroupA);
            CreateTestEntity(1, Groups.GroupA);
            CreateTestEntity(1, Groups.GroupB);
            _scheduler.SubmitEntities();

            _functions.RemoveEntitiesFromGroup(Groups.GroupA);
            _scheduler.SubmitEntities();

            var query = new QueryGroups(GroupAB).Evaluate();

            var entityCount = query.Count <TestEntityComponent>(_entitiesDB.entitiesForTesting);

            Assert.AreEqual(1, entityCount, "Entities in the target group should be removed");
        }
Beispiel #9
0
        // Equality and comparers

        /// <summary>
        /// Returns the hashcode for this <see cref="QueryGroup"/>.
        /// </summary>
        /// <returns>The hashcode value.</returns>
        public override int GetHashCode()
        {
            // Make sure to check if this is already taken
            if (!ReferenceEquals(null, m_hashCode))
            {
                return(m_hashCode.Value);
            }

            // Set the default value (should not be nullable for better performance)
            var hashCode = 0;

            // Iterates the child query field
            if (!ReferenceEquals(null, QueryFields))
            {
                QueryFields.ToList().ForEach(queryField =>
                {
                    hashCode += queryField.GetHashCode();
                });
            }

            // Iterates the child query groups
            if (!ReferenceEquals(null, QueryGroups))
            {
                QueryGroups.ToList().ForEach(queryGroup =>
                {
                    hashCode += queryGroup.GetHashCode();
                });
            }

            // Set with conjunction
            hashCode += Conjunction.GetHashCode();

            // Set back the hashcode value
            m_hashCode = hashCode;

            // Return the actual hash code
            return(hashCode);
        }
Beispiel #10
0
        /// <summary>
        /// Returns the hashcode for this <see cref="QueryGroup"/>.
        /// </summary>
        /// <returns>The hashcode value.</returns>
        public override int GetHashCode()
        {
            // Make sure to check if this is already taken
            if (this.hashCode != null)
            {
                return(this.hashCode.Value);
            }

            var hashCode = 0;

            // Iterates the child query field
            if (QueryFields != null)
            {
                foreach (var queryField in QueryFields)
                {
                    hashCode += queryField.GetHashCode();
                }
            }

            // Iterates the child query groups
            if (QueryGroups?.Any() == true)
            {
                foreach (var queryGroup in QueryGroups)
                {
                    hashCode += queryGroup.GetHashCode();
                }
            }

            // Set with conjunction
            hashCode += (int)Conjunction;

            // Set the IsNot
            hashCode += IsNot.GetHashCode();

            // Set and return the hashcode
            return((this.hashCode = hashCode).Value);
        }
Beispiel #11
0
        public bool MoveNext()
        {
            var query = new QueryGroups(_groups).WithAny <T>(_entitiesDB);

            return(query.result.count == 0);
        }