Exemple #1
0
        void HandleActualQuery(Type queryType, object actualQuery, Type resultType, QueryResult result, PagingInfo paging)
        {
            var provider       = GetQueryProvider(queryType, resultType, actualQuery);
            var providerResult = ExecuteOnProvider(provider, actualQuery, paging);

            result.TotalItems = providerResult.TotalItems;
            var readModels = providerResult.Items as IEnumerable <IReadModel>;

            result.Items = readModels != null?_filters.Filter(readModels) : providerResult.Items;

            _logger.Trace($"Query resulted in {result.TotalItems} items");
        }
Exemple #2
0
#pragma warning disable 1591 // Xml Comments
        public QueryResult Execute(IQuery query, PagingInfo paging)
        {
            ThrowIfNoQueryPropertyOnQuery(query);

            var result = QueryResult.For(query);

            try
            {
                var authorizationResult = _fetchingSecurityManager.Authorize(query);
                if (!authorizationResult.IsAuthorized)
                {
                    result.SecurityMessages = authorizationResult.BuildFailedAuthorizationMessages();
                    result.Items            = new object[0];
                    return(result);
                }
                result.Validation = _validator.Validate(query);
                if (!result.Validation.Success)
                {
                    result.Items = new object[0];
                    return(result);
                }

                var property       = GetQueryPropertyFromQuery(query);
                var actualQuery    = property.GetValue(query, null);
                var provider       = GetQueryProvider(query, property, actualQuery);
                var providerResult = ExecuteOnProvider(provider, actualQuery, paging);
                result.TotalItems = providerResult.TotalItems;
                var readModels = providerResult.Items as IEnumerable <IReadModel>;
                result.Items = readModels != null?_filters.Filter(readModels) : providerResult.Items;
            }
            catch (TargetInvocationException ex)
            {
                _exceptionPublisher.Publish(ex.InnerException);
                result.Exception = ex.InnerException;
            }
            catch (Exception ex)
            {
                _exceptionPublisher.Publish(ex);
                result.Exception = ex;
            }

            return(result);
        }
Exemple #3
0
        public object InstanceMatching(ReadModelQueryDescriptor descriptor)
        {
            var readModelType = _typeDiscoverer.FindTypeByFullName(descriptor.GeneratedFrom);

            if (readModelType != null)
            {
                var readModelOfType        = typeof(IReadModelOf <>).MakeGenericType(readModelType);
                var readModelOf            = _container.Get(readModelOfType);
                var instanceMatchingMethod = readModelOfType.GetMethod("InstanceMatching");

                var genericAuthorizeMethod = _authorizeMethod.MakeGenericMethod(readModelType);
                var authorizationResult    = genericAuthorizeMethod.Invoke(_fetchingSecurityManager, new[] { readModelOf }) as AuthorizationResult;
                if (!authorizationResult.IsAuthorized)
                {
                    return(null);
                }

                var funcType       = typeof(Func <,>).MakeGenericType(readModelType, typeof(bool));
                var expressionType = typeof(Expression <>).MakeGenericType(funcType);
                var expressions    = Array.CreateInstance(expressionType, descriptor.PropertyFilters.Count);
                var index          = 0;
                foreach (var key in descriptor.PropertyFilters.Keys)
                {
                    var expression = GetPropertyEqualsExpression(readModelType, key.ToPascalCase(), descriptor.PropertyFilters[key]);
                    expressions.SetValue(expression, index);
                    index++;
                }

                var result   = instanceMatchingMethod.Invoke(readModelOf, new[] { expressions });
                var filtered = _readModelFilters.Filter(new[] { result as IReadModel });
                if (filtered.Count() == 1)
                {
                    return(filtered.First());
                }
            }
            return(null);
        }