/// <summary>
        /// Specifically used the clone query steps.
        /// </summary>
        /// <param name="queryStep">queryStep.</param>
        /// <returns>QueryStep</returns>
        /// <remarks>Anytime we need to create a clone copy of query steps, this is used because deep knowldge of which property where JsonIgnoreAttribute is only known here.</remarks>
        public static QueryStep CloneQueryStep(this QueryStep queryStep)
        {
            var clone = queryStep.Clone();

            clone.SkipConnectionEdgeCheck    = queryStep.SkipConnectionEdgeCheck;
            clone.OverrideRepositoryWithType = queryStep.OverrideRepositoryWithType;
            clone.ContextAction = queryStep.ContextAction;
            clone.StepMapper    = queryStep.StepMapper;
            clone.InMemoryFilterQueryParameters = queryStep.InMemoryFilterQueryParameters;

            if (queryStep.Items != null && queryStep.Items.Count > 0)
            {
                clone.Items = new Dictionary <string, object>();
                foreach (var key in queryStep.Items.Keys)
                {
                    clone.Items.Add(key, queryStep.Items[key]);
                }
            }

            // Copy Member Models which are ignored via JsonIgnore.
            for (var i = 0; i < queryStep.QueryParameters.Count; i++)
            {
                var qp  = queryStep.QueryParameters[i];
                var cqp = clone.QueryParameters[i];

                cqp.MemberModel = qp.MemberModel;

                if (qp.Mapper != null)
                {
                    cqp.Mapper = qp.Mapper;
                }
            }

            return(clone);
        }
Exemplo n.º 2
0
        internal void Add <TProperty>(
            List <QueryStepBuilderParameter <TProperty> > parameters,
            Action <QueryExecutionContext> contextAction,
            Dictionary <string, object> stepBagItems,
            bool skipConnectionEdgeCheck,
            Type overrideRepositoryWithType)
        {
            var step = new QueryStep
            {
                ContextAction = contextAction,
                Items         = stepBagItems,
                OverrideRepositoryWithType = overrideRepositoryWithType,
                SkipConnectionEdgeCheck    = skipConnectionEdgeCheck
            };

            parameters.ForEach(parameter =>
            {
                // The property access might be getting converted to object to match the func.
                // If so, get the operand and see if that's a member expression.
                MemberExpression memberExpression = parameter.Expression.Body as MemberExpression ?? (parameter.Expression.Body as UnaryExpression)?.Operand as MemberExpression;

                if (memberExpression != null)
                {
                    // Find the member.
                    var rawMemberExpression = memberExpression.ToString();
                    var depth   = rawMemberExpression.Count(x => x == '.');
                    string path = depth > 1 ? rawMemberExpression[(rawMemberExpression.IndexOf('.') + 1)..] : memberExpression.Member.Name;
        internal void Add <TProperty>(
            List <QueryStepBuilderParameter <TProperty> > parameters,
            Action <QueryExecutionContext> contextAction,
            Dictionary <string, object> stepBagItems,
            bool skipConnectionEdgeCheck,
            Type overrideRepositoryWithType)
        {
            var step = new QueryStep
            {
                ContextAction = contextAction,
                Items         = stepBagItems,
                OverrideRepositoryWithType = overrideRepositoryWithType,
                SkipConnectionEdgeCheck    = skipConnectionEdgeCheck
            };

            parameters.ForEach(parameter =>
            {
                // The property access might be getting converted to object to match the func.
                // If so, get the operand and see if that's a member expression.
                MemberExpression memberExpression = parameter.Expression.Body as MemberExpression ?? (parameter.Expression.Body as UnaryExpression)?.Operand as MemberExpression;

                if (memberExpression != null)
                {
                    // Find the member.
                    var rawMemberExpression = memberExpression.ToString();
                    var depth   = rawMemberExpression.Count(x => x == '.');
                    string path = depth > 1 ? rawMemberExpression.Substring(rawMemberExpression.IndexOf('.') + 1) : memberExpression.Member.Name;

                    var accessor = TypeAccessor.Create(typeof(TProperty));
                    var member   = accessor.GetMembers().ToList().Single(x =>
                                                                         x.Name == (depth > 1 ? path.Substring(0, path.IndexOf('.')) : memberExpression.Member.Name));

                    var modelMember = new ModelMember(typeof(TProperty), accessor, member, false);

                    var qp = new QueryParameter
                    {
                        MemberModel = modelMember
                    };

                    if (parameter.Mapper == null)
                    {
                        Members.Add(modelMember);
                    }
                    else
                    {
                        qp.Mapper = ctx => parameter.Mapper(ctx.Context);
                    }

                    step.QueryParameters.Add(qp);
                }
                else
                {
                    throw new ArgumentException("Expression provided is not a member expression.");
                }
            });

            _querySteps.Add(step);
        }
Exemplo n.º 4
0
 public QueryParameterBuilder(QueryBuilder <TSource> queryBuilder,
                              IInMemoryComparerProvider inMemoryComparerProvider,
                              IContextValueResolver contextValueResolver)
 {
     _queryBuilder             = queryBuilder;
     _inMemoryComparerProvider = inMemoryComparerProvider;
     _contextValueResolver     = contextValueResolver;
     _queryStep = NewQueryStep();
 }
        internal void Add <TProperty>(
            List <Expression <Func <TProperty, object> > > expressions,
            Func <QueryExecutionContext, List <object> > mapper,
            Action <QueryExecutionContext> contextAction,
            Dictionary <string, object> stepBagItems)
        {
            var step = new QueryStep
            {
                ContextAction = contextAction,
                Mapper        = mapper,
                Items         = stepBagItems
            };

            bool first = mapper != null;

            expressions.ForEach(expression =>
            {
                // The property access might be getting converted to object to match the func.
                // If so, get the operand and see if that's a member expression.
                MemberExpression memberExpression = expression.Body as MemberExpression ?? (expression.Body as UnaryExpression)?.Operand as MemberExpression;

                if (memberExpression != null)
                {
                    // Find the member.
                    var rawMemberExpression = memberExpression.ToString();
                    var depth   = rawMemberExpression.Count(x => x == '.');
                    string path = depth > 1 ? rawMemberExpression.Substring(rawMemberExpression.IndexOf('.') + 1) : memberExpression.Member.Name;

                    var accessor = TypeAccessor.Create(typeof(TProperty));
                    var member   = accessor.GetMembers().ToList().Single(x =>
                                                                         x.Name == (depth > 1 ? path.Substring(0, path.IndexOf('.')) : memberExpression.Member.Name));

                    var modelMember = new ModelMember(typeof(TProperty), accessor, member, false);

                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        _modelMemberList.Add(modelMember);
                    }

                    step.QueryParameters.Add(new QueryParameter
                    {
                        MemberModel = modelMember
                    });
                }
                else
                {
                    throw new ArgumentException("Expression provided is not a member expression.");
                }
            });

            _querySteps.Add(step);
        }
        private static bool IsInvalidForNextQuery(QueryStep queryStep)
        {
            if (queryStep.QueryParameters.Count == 1 &&
                queryStep.QueryParameters.Single().Mapper != null)
            {
                var qp = queryStep.QueryParameters.Single();

                return(qp.ContextValue == null || (qp.ContextValue.Values == null));
            }

            return(false);
        }
        private async Task <List <object> > QueryAsync(string queryName, QueryStep queryStep, IGraphRequestContext graphRequestContext,
                                                       QueryExecutionContext queryExecutionContext,
                                                       List <ConnectionEdgeDestinationFilter> connectionEdgeDestinationFilters)
        {
            var results = (await _graphQlRepositoryProvider.QueryAsync(queryName, queryStep, graphRequestContext)).ToList();

            if (!queryStep.SkipConnectionEdgeCheck && results.Count > 0)
            {
                await _connectionEdgeHandler.QueryAsync(results, queryStep, graphRequestContext, queryExecutionContext,
                                                        connectionEdgeDestinationFilters);
            }
            return(results);
        }
        private async Task <List <object> > QueryAsync(string queryName, QueryStep queryStep, IGraphRequestContext graphRequestContext)
        {
            var results = (await _graphQlRepositoryProvider.QueryAsync(queryName, queryStep, graphRequestContext)).ToList();

            if (results.Count > 0)
            {
                if (results.First().GetType() == typeof(SearchResultModel))
                {
                    return(results);
                }

                await _connectionEdgeHandler.QueryAsync(results, queryStep, graphRequestContext);
            }
            return(results);
        }