Exemplo n.º 1
0
        public ProcessingResult ProcessQuery(MethodCallExpression query, ProcessingResult parentResult, DataContext context)
        {
            var source1          = parentResult.GetLoadedItems(QueryProcessingHelper.GetSourceParameterType(query));
            var constantArgument = query.Arguments[1] as ConstantExpression;

            if (constantArgument == null)
            {
                return(ProcessingResult.Unsuccessful);
            }

            var source2 = (IEnumerable)constantArgument.Value;

            var resultElementType = QueryProcessingHelper.GetSourceParameterType(query);
            var resultList        = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(resultElementType));

            foreach (var item in source1)
            {
                resultList.Add(item);
            }

            foreach (var item in source2)
            {
                resultList.Add(item);
            }

            return(new ProcessingResult(true, resultList));
        }
        private static ProcessingResult LoadData(ProcessingResult result, Type dataType)
        {
            if (!result.IsSuccess)
            {
                return(ProcessingResult.Unsuccessful);
            }

            var loadedResult = result.IsSingleItem
                ? result.GetLoadedItem(dataType)
                : result.GetLoadedItems(dataType);

            return(new ProcessingResult(true, loadedResult, result.IsSingleItem));
        }
        public ProcessingResult ProcessQuery(MethodCallExpression query, ProcessingResult parentResult, DataContext context)
        {
            var elementType = QueryProcessingHelper.GetSourceParameterType(query);

            var items    = parentResult.GetLoadedItems(elementType);
            var comparer = query.Arguments.Count > 1 ? ((ConstantExpression)query.Arguments[1]).Value : null;

            var result = RuntimeMethodInvoker.InvokeFuncCached <IEnumerable <RuntimeType1>, IEqualityComparer <RuntimeType1>, List <RuntimeType1> >(
                Distinct, new RuntimeTypeBinding {
                new RuntimeType1(elementType)
            }, items, comparer);

            return(new ProcessingResult(true, result));
        }
        internal static object ProcessQueries(NodeReference node, DataContext context, Expression queryExpression)
        {
            var queries = GetQueriesInTurn(queryExpression);
            var nodes   = DatabaseManager.GetEntitiesNodes(node, context);

            var result = new ProcessingResult(true, nodes);

            result = queries.Aggregate(result, (current, query) => ProcessQuery(query, current, context));

            if (result.IsDeferred())
            {
                return(result.IsSingleItem
                    ? result.GetLoadedItem(GetReturnParameterType(queries.Last()))
                    : result.GetLoadedItems(GetReturnParameterType(queries.Last())));
            }

            return(result.Result);
        }
        public ProcessingResult ProcessQuery(MethodCallExpression query, ProcessingResult parentResult, DataContext context)
        {
            var source1 = parentResult.GetLoadedItems(QueryProcessingHelper.GetSourceParameterType(query));

            var constantArgument = query.Arguments[1] as ConstantExpression;

            if (constantArgument == null)
            {
                return(ProcessingResult.Unsuccessful);
            }

            var source2  = constantArgument.Value;
            var comparer = query.Arguments.Count > 2 ? ((ConstantExpression)query.Arguments[2]).Value : null;

            var sourceType = QueryProcessingHelper.GetSourceParameterType(query);

            Func <MethodCallExpression, IEnumerable <RuntimeType1>, IEnumerable <RuntimeType1>,
                  IEqualityComparer <RuntimeType1>, ProcessingResult> func = ProcessQuery;

            return((ProcessingResult)RuntimeMethodInvoker.InvokeFuncCached(
                       func, new RuntimeTypeBinding {
                new RuntimeType1(sourceType)
            }, query, source1, source2, comparer));
        }
Exemplo n.º 6
0
        public ProcessingResult ProcessQuery(MethodCallExpression query, ProcessingResult parentResult, DataContext context)
        {
            if (!parentResult.IsDeferred())
            {
                return(ProcessingResult.Unsuccessful);
            }

            var hasSelector = query.Arguments.Count > 1;
            var elementType = QueryProcessingHelper.GetReturnParameterType(query);

            if (!hasSelector)
            {
                var items = parentResult.GetLoadedItems(elementType);
                return(new ProcessingResult(true, ProcessQuery(items), true));
            }

            var unaryExpression = (UnaryExpression)query.Arguments[1];
            var selectorLambda  = (LambdaExpression)unaryExpression.Operand;

            var selectorResult = ExpressionProcessingHelper.ProcessExpression(selectorLambda.Body, parentResult.GetDeferredList(), context);

            if (!selectorResult.IsSuccess)
            {
                return(ProcessingResult.Unsuccessful);
            }

            if (selectorResult.IsSingleItem)
            {
                var result = Convert.ChangeType(selectorResult.Result, elementType);
                return(new ProcessingResult(true, result, true));
            }

            var loadedItems = selectorResult.GetLoadedItems(elementType);

            return(new ProcessingResult(true, ProcessQuery(loadedItems), true));
        }
        internal static ProcessingResult ProcessQueryByDefault(MethodCallExpression query, ProcessingResult parentResult, DataContext context)
        {
            var result = InvokeQuery(query, parentResult.GetLoadedItems(GetSourceParameterType(query)), context);

            return(new ProcessingResult(true, result));
        }