예제 #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)
                           )));
        }
예제 #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);
예제 #3
0
 /// <inheritdoc />
 protected override MongoDbFilterDefinition HandleListOperation(
     MongoDbFilterVisitorContext context,
     IFilterField field,
     MongoDbFilterScope scope,
     string path)
 {
     return(new MongoDbFilterOperation(
                path,
                new MongoDbFilterOperation("$elemMatch", CombineOperationsOfScope(scope))));
 }
예제 #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);
        }
예제 #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)));
        }
예제 #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)))
                    )));
 }
예제 #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());