protected virtual ISelectionVisitorAction Visit(
        IOutputField field,
        TContext context)
    {
        TContext?localContext          = OnBeforeEnter(field, context);
        ISelectionVisitorAction?result = Enter(field, localContext);

        localContext = OnAfterEnter(field, localContext, result);

        if (result.Kind == SelectionVisitorActionKind.Continue)
        {
            if (VisitChildren(field, context).Kind == SelectionVisitorActionKind.Break)
            {
                return(Break);
            }
        }

        if (result.Kind == SelectionVisitorActionKind.Continue ||
            result.Kind == SelectionVisitorActionKind.SkipAndLeave)
        {
            localContext = OnBeforeLeave(field, localContext);
            result       = Leave(field, localContext);
            OnAfterLeave(field, localContext, result);
        }

        return(result);
    }
Example #2
0
        /// <inheritdoc/>
        public override bool TryHandleEnter(
            Neo4JProjectionVisitorContext context,
            ISelection selection,
            [NotNullWhen(true)] out ISelectionVisitorAction?action)
        {
            ++context.CurrentLevel;

            selection.Field.ContextData.TryGetValue(
                nameof(Neo4JRelationshipAttribute),
                out object?relationship);

            if (relationship is Neo4JRelationshipAttribute rel)
            {
                context.RelationshipTypes.Push(rel);
            }

            context.StartNodes.Push(Cypher.NamedNode(selection.DeclaringType.Name.Value));

            if (context.RelationshipProjections.ContainsKey(context.CurrentLevel))
            {
                context.RelationshipProjections[context.CurrentLevel]
                .Enqueue(selection.Field.GetName());
            }
            else
            {
                Queue <object> queue = new();
                queue.Enqueue(selection.Field.GetName());
                context.RelationshipProjections.Add(context.CurrentLevel, queue);
            }

            action = SelectionVisitor.Continue;
            return(true);
        }
 public bool TryHandleEnter(
     T context,
     ISelection selection,
     [NotNullWhen(true)] out ISelectionVisitorAction?action)
 {
     _interceptor.BeforeProjection(context, selection);
     return(_handler.TryHandleEnter(context, selection, out action));
 }
Example #4
0
 public override bool TryHandleEnter(
     QueryableProjectionContext context,
     ISelection selection,
     [NotNullWhen(true)] out ISelectionVisitorAction?action)
 {
     action = SelectionVisitor.Continue;
     return(true);
 }
Example #5
0
 /// <inheritdoc/>
 public override bool TryHandleLeave(
     MongoDbProjectionVisitorContext context,
     ISelection selection,
     [NotNullWhen(true)] out ISelectionVisitorAction?action)
 {
     action = SelectionVisitor.Continue;
     return(true);
 }
 public bool TryHandleLeave(
     T context,
     ISelection selection,
     [NotNullWhen(true)] out ISelectionVisitorAction?action)
 {
     _handler.TryHandleLeave(context, selection, out action);
     _interceptor.AfterProjection(context, selection);
     return(action is not null);
 }
        /// <inheritdoc/>
        public override bool TryHandleEnter(
            MongoDbProjectionVisitorContext context,
            ISelection selection,
            [NotNullWhen(true)] out ISelectionVisitorAction?action)
        {
            IObjectField field = selection.Field;

            context.Path.Push(field.GetName());
            action = SelectionVisitor.Continue;
            return(true);
        }
        /// <inheritdoc/>
        public override bool TryHandleEnter(
            MongoDbProjectionVisitorContext context,
            ISelection selection,
            out ISelectionVisitorAction?action)
        {
            IObjectField field = selection.Field;

            context.Path.Push(field.GetName());
            context.Projections.Push(
                new MongoDbIncludeProjectionOperation(context.GetPath()));
            context.Path.Pop();

            action = SelectionVisitor.SkipAndLeave;
            return(true);
        }
Example #9
0
        /// <inheritdoc/>
        public override bool TryHandleLeave(
            Neo4JProjectionVisitorContext context,
            ISelection selection,
            [NotNullWhen(true)] out ISelectionVisitorAction?action)
        {
            if (context.StartNodes.Any())
            {
                object field = context.RelationshipProjections[context.CurrentLevel].Dequeue();

                context.TryCreateRelationshipProjection(out PatternComprehension? projections);

                switch (context.CurrentLevel)
                {
                case > 1:
                    context.RelationshipProjections[context.CurrentLevel - 1].Enqueue(field);
                    context.RelationshipProjections[context.CurrentLevel - 1]
                    .Enqueue(projections);
                    break;

                case 1:
                    context.Projections.Push(field);
                    context.Projections.Push(projections);
                    break;
                }
            }

            --context.CurrentLevel;

            context.StartNodes.Pop();
            context.EndNodes.Pop();
            context.Relationships.Pop();

            if (context.CurrentLevel == 0)
            {
                context.RelationshipProjections.Clear();
            }

            action = SelectionVisitor.Continue;
            return(true);
        }
 public abstract bool TryHandleLeave(
     T context,
     ISelection selection,
     [NotNullWhen(true)] out ISelectionVisitorAction?action);