Exemplo n.º 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)
                           )));
        }
 /// <inheritdoc />
 public override MongoDbFilterDefinition HandleOperation(
     MongoDbFilterVisitorContext context,
     IFilterOperationField field,
     IValueNode value,
     object?parsedValue)
 {
     if (parsedValue is {})
Exemplo n.º 3
0
 /// <inheritdoc />
 public override MongoDbFilterDefinition HandleOperation(
     MongoDbFilterVisitorContext context,
     IFilterOperationField field,
     IValueNode value,
     object?parsedValue)
 {
     if (context.RuntimeTypes.Count > 0 &&
         context.RuntimeTypes.Peek().TypeArguments is { Count : > 0 } &&
Exemplo n.º 4
0
 /// <inheritdoc />
 protected override MongoDbFilterDefinition HandleListOperation(
     MongoDbFilterVisitorContext context,
     IFilterField field,
     MongoDbFilterScope scope,
     string path) =>
 field.Type is IComparableOperationFilterInputType
         ? CreateArrayAllScalar(scope, path)
         : CreateArrayAll(scope, path);
Exemplo n.º 5
0
        /// <inheritdoc />
        public override MongoDbFilterDefinition HandleOperation(
            MongoDbFilterVisitorContext context,
            IFilterOperationField field,
            IValueNode value,
            object?parsedValue)
        {
            var doc = new MongoDbFilterOperation("$eq", parsedValue);

            return(new MongoDbFilterOperation(context.GetMongoFilterScope().GetPath(), doc));
        }
Exemplo n.º 6
0
 /// <inheritdoc />
 protected override MongoDbFilterDefinition HandleListOperation(
     MongoDbFilterVisitorContext context,
     IFilterField field,
     MongoDbFilterScope scope,
     string path)
 {
     return(new MongoDbFilterOperation(
                path,
                new MongoDbFilterOperation("$elemMatch", CombineOperationsOfScope(scope))));
 }
Exemplo n.º 7
0
        public override MongoDbFilterDefinition HandleOperation(
            MongoDbFilterVisitorContext context,
            IFilterOperationField field,
            IValueNode value,
            object?parsedValue)
        {
            if (parsedValue is string str)
            {
                var doc = new MongoDbFilterOperation(
                    "$regex",
                    new BsonRegularExpression($"/^{Regex.Escape(str)}/"));

                return(new MongoDbFilterOperation(context.GetMongoFilterScope().GetPath(), doc));
            }

            throw new InvalidOperationException();
        }
Exemplo n.º 8
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)))
                    )));
 }
Exemplo n.º 9
0
 /// <summary>
 /// Tries to build the query based on the items that are stored on the scope
 /// </summary>
 /// <param name="context">the context</param>
 /// <param name="query">The query that was build</param>
 /// <returns>True in case the query has been build successfully, otherwise false</returns>
 public static bool TryCreateQuery(
     this MongoDbFilterVisitorContext context,
     [NotNullWhen(true)] out MongoDbFilterDefinition?query)
 {
     return(context.GetMongoFilterScope().TryCreateQuery(out query));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Reads the current scope from the context
 /// </summary>
 /// <param name="context">The context</param>
 /// <returns>The current scope</returns>
 public static MongoDbFilterScope GetMongoFilterScope(
     this MongoDbFilterVisitorContext context) =>
 (MongoDbFilterScope)context.GetScope();