Exemple #1
0
        /// <inheritdoc />
        protected override MongoDbFilterDefinition HandleListOperation(
            MongoDbFilterVisitorContext context,
            IFilterField field,
            MongoDbFilterScope scope,
            string path)
        {
            var negatedChilds = new List <MongoDbFilterDefinition>();
            Queue <MongoDbFilterDefinition> level = scope.Level.Peek();

            while (level.Count > 0)
            {
                negatedChilds.Add(
                    new MongoDbFilterOperation(
                        path,
                        new MongoDbFilterOperation(
                            "$elemMatch",
                            new NotMongoDbFilterDefinition(level.Dequeue()))));
            }

            return(new AndFilterDefinition(
                       new MongoDbFilterOperation(
                           path,
                           new BsonDocument
            {
                { "$exists", true },
                { "$nin", new BsonArray {
                      new BsonArray(), BsonNull.Value
                  } }
            }),
                       new NotMongoDbFilterDefinition(
                           new OrMongoDbFilterDefinition(negatedChilds)
                           )));
        }
Exemple #2
0
 /// <inheritdoc />
 protected override MongoDbFilterDefinition HandleListOperation(
     MongoDbFilterVisitorContext context,
     IFilterField field,
     MongoDbFilterScope scope,
     string path) =>
 field.Type is IComparableOperationFilterInputType
         ? CreateArrayAllScalar(scope, path)
         : CreateArrayAll(scope, path);
Exemple #3
0
 /// <inheritdoc />
 protected override MongoDbFilterDefinition HandleListOperation(
     MongoDbFilterVisitorContext context,
     IFilterField field,
     MongoDbFilterScope scope,
     string path)
 {
     return(new MongoDbFilterOperation(
                path,
                new MongoDbFilterOperation("$elemMatch", CombineOperationsOfScope(scope))));
 }
Exemple #4
0
        /// <summary>
        /// Combines all definitions of the <paramref name="scope"/> with and
        /// </summary>
        /// <param name="scope">The scope where the definitions should be combined</param>
        /// <returns>A with and combined filter definition of all definitions of the scope</returns>
        protected static MongoDbFilterDefinition CombineOperationsOfScope(
            MongoDbFilterScope scope)
        {
            Queue <MongoDbFilterDefinition> level = scope.Level.Peek();

            if (level.Count == 1)
            {
                return(level.Peek());
            }

            return(new AndFilterDefinition(level.ToArray()));
        }
        public static bool TryCreateQuery(
            this MongoDbFilterScope scope,
            [NotNullWhen(true)] out MongoDbFilterDefinition?query)
        {
            query = null;

            if (scope.Level.Peek().Count == 0)
            {
                return(false);
            }

            query = new AndFilterDefinition(scope.Level.Peek().ToArray());

            return(true);
        }
Exemple #6
0
        private static MongoDbFilterDefinition CreateArrayAllScalar(
            MongoDbFilterScope scope,
            string path)
        {
            var negatedChilds = new List <MongoDbFilterDefinition>();
            Queue <MongoDbFilterDefinition> level = scope.Level.Peek();

            while (level.Count > 0)
            {
                negatedChilds.Add(
                    new MongoDbFilterOperation(
                        path,
                        new NotMongoDbFilterDefinition(level.Dequeue())));
            }

            return(new NotMongoDbFilterDefinition(
                       new OrMongoDbFilterDefinition(negatedChilds)));
        }
Exemple #7
0
 /// <inheritdoc />
 protected override MongoDbFilterDefinition HandleListOperation(
     MongoDbFilterVisitorContext context,
     IFilterField field,
     MongoDbFilterScope scope,
     string path)
 {
     return(new AndFilterDefinition(
                new MongoDbFilterOperation(
                    path,
                    new BsonDocument
     {
         { "$exists", true },
         { "$nin", new BsonArray {
               new BsonArray(), BsonNull.Value
           } }
     }),
                new MongoDbFilterOperation(
                    path,
                    new NotMongoDbFilterDefinition(
                        new MongoDbFilterOperation("$elemMatch", CombineOperationsOfScope(scope)))
                    )));
 }
Exemple #8
0
 /// <summary>
 /// Maps a operation field to a mongodb list filter definition.
 /// This method is called when the <see cref="FilterVisitor{TContext,T}"/> enters a
 /// field
 /// </summary>
 /// <param name="context">The context of the visitor</param>
 /// <param name="field">The currently visited filter field</param>
 /// <param name="scope">The current scope of the visitor</param>
 /// <param name="path">The path that leads to this visitor</param>
 /// <returns></returns>
 protected abstract MongoDbFilterDefinition HandleListOperation(
     MongoDbFilterVisitorContext context,
     IFilterField field,
     MongoDbFilterScope scope,
     string path);
 public static string GetPath(this MongoDbFilterScope scope) =>
 string.Join(".", scope.Path.Reverse());