コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the DefaultQueryHandler class.
        /// </summary>
        /// <param name="sourcer">The query expression sourcer to use.</param>
        /// <param name="authorizer">The query expression authorizer to use.</param>
        /// <param name="expander">The query expression expander to use.</param>
        /// <param name="processor">The query expression processor to use.</param>
        public DefaultQueryHandler(IQueryExpressionSourcer sourcer,
                                   IQueryExpressionAuthorizer authorizer = null,
                                   IQueryExpressionExpander expander     = null,
                                   IQueryExpressionProcessor processor   = null)
        {
            Ensure.NotNull(sourcer, nameof(sourcer));

            this.authorizer = authorizer;
            this.expander   = expander;
            this.processor  = processor;
            this.sourcer    = sourcer;
        }
コード例 #2
0
            public QueryExpressionVisitor(QueryContext context,
                                          IQueryExpressionSourcer sourcer,
                                          IQueryExpressionAuthorizer authorizer = null,
                                          IQueryExpressionExpander expander     = null,
                                          IQueryExpressionProcessor processor   = null)
            {
                Ensure.NotNull(sourcer, nameof(sourcer));

                this.context         = new QueryExpressionContext(context);
                this.authorizer      = authorizer;
                this.expander        = expander;
                this.processor       = processor;
                this.sourcer         = sourcer;
                processedExpressions = new Dictionary <Expression, Expression>();
            }
コード例 #3
0
            private Expression Expand(Expression visited)
            {
                if (this.expander == null)
                {
                    this.expander = this.context.QueryContext
                                    .GetApiService <IQueryExpressionExpander>();
                }

                if (expander == null)
                {
                    return(visited);
                }

                var expanded = expander.Expand(this.context);
                var callback = this.context.AfterNestedVisitCallback;

                this.context.AfterNestedVisitCallback = null;
                if (expanded != null && expanded != visited)
                {
                    if (!visited.Type.IsAssignableFrom(expanded.Type))
                    {
                        throw new InvalidOperationException(
                                  Resources.ExpanderCannotChangeExpressionType);
                    }

                    this.context.PushVisitedNode(null);
                    expanded = this.Visit(expanded);
                    this.context.PopVisitedNode();
                    if (callback != null)
                    {
                        callback();
                    }

                    return(expanded);
                }

                return(visited);
            }
コード例 #4
0
            private Expression Expand(Expression visited)
            {
                if (this.expander == null)
                {
                    this.expander = this.context.QueryContext
                        .GetHookHandler<IQueryExpressionExpander>();
                }

                if (expander == null)
                {
                    return visited;
                }

                var expanded = expander.Expand(this.context);
                var callback = this.context.AfterNestedVisitCallback;
                this.context.AfterNestedVisitCallback = null;
                if (expanded != null && expanded != visited)
                {
                    if (!visited.Type.IsAssignableFrom(expanded.Type))
                    {
                        throw new InvalidOperationException(
                            Resources.ExpanderCannotChangeExpressionType);
                    }

                    this.context.PushVisitedNode(null);
                    expanded = this.Visit(expanded);
                    this.context.PopVisitedNode();
                    if (callback != null)
                    {
                        callback();
                    }

                    return expanded;
                }

                return visited;
            }