private object Execute <T>(RestQueryableTreeParser parser, bool executeAsync) { LambdaExpression clientSideSelectPart; var uri = BuildUri(parser, out clientSideSelectPart); if (parser.ResultMode == RestQueryableTreeParser.ResultModeType.ToUri) { return(new Uri(uri)); } var requestOptions = RequestOptions.Create <T>(x => parser.RequestOptionActions.ForEach(y => y(x))); if (parser.ResultMode == RestQueryableTreeParser.ResultModeType.ToJson) { return(Client.Get <JToken>(uri, requestOptions)); } var queryProjection = parser.Projection; if (clientSideSelectPart != null) { return(executeWithClientSelectPart.Invoke(clientSideSelectPart.Parameters[0].Type, clientSideSelectPart.ReturnType, this, uri, queryProjection, clientSideSelectPart, requestOptions, executeAsync)); } return(Execute <T, T>(uri, queryProjection, null, requestOptions, executeAsync)); }
private static void SetProjection(RestQueryableTreeParser parser, UriQueryBuilder builder) { string projection = null; switch (parser.Projection) { case RestQueryableTreeParser.QueryProjection.First: case RestQueryableTreeParser.QueryProjection.FirstLazy: projection = "first"; break; case RestQueryableTreeParser.QueryProjection.FirstOrDefault: projection = "firstordefault"; break; case RestQueryableTreeParser.QueryProjection.Single: projection = "single"; break; case RestQueryableTreeParser.QueryProjection.SingleOrDefault: projection = "singleordefault"; break; case RestQueryableTreeParser.QueryProjection.Last: projection = "last"; break; case RestQueryableTreeParser.QueryProjection.LastOrDefault: projection = "lastordefault"; break; case RestQueryableTreeParser.QueryProjection.Max: projection = "max"; break; case RestQueryableTreeParser.QueryProjection.Min: projection = "min"; break; //case RestQueryableTreeParser.QueryProjection.Any: // TODO: Remove backwards compatibility at some point in the future. // HACK for backwards compatibility. Any is not supported by old versions of pomona server // projection = "any"; // break; case RestQueryableTreeParser.QueryProjection.Any: case RestQueryableTreeParser.QueryProjection.Count: projection = "count"; break; case RestQueryableTreeParser.QueryProjection.Sum: projection = "sum"; break; } if (projection != null) { builder.AppendParameter("$projection", projection); } }
public override object Execute(Expression expression, Type resultType) { var queryTreeParser = new RestQueryableTreeParser(); queryTreeParser.Visit(expression); var executeAsync = resultType != null && typeof(Task).IsAssignableFrom(resultType); return(executeGenericMethod.Invoke(queryTreeParser.SelectReturnType, this, queryTreeParser, executeAsync)); }
private string BuildUri(RestQueryableTreeParser parser, out LambdaExpression clientSideSelectPart) { clientSideSelectPart = null; var builder = new UriQueryBuilder(); var resourceInfo = Client.GetResourceInfoForType(parser.ElementType); if (!resourceInfo.IsUriBaseType) { builder.AppendParameter("$oftype", resourceInfo.JsonTypeName); } SetProjection(parser, builder); if (parser.WherePredicate != null) { builder.AppendExpressionParameter("$filter", parser.WherePredicate); } if (parser.OrderKeySelectors.Count > 0) { builder.AppendExpressionParameter <QueryOrderByBuilder>("$orderby", Expression.Constant(parser.OrderKeySelectors)); } if (parser.GroupByKeySelector != null) { builder.AppendExpressionParameter <QuerySelectorBuilder>("$groupby", parser.GroupByKeySelector); } if (parser.SelectExpression != null) { var selectNode = parser.SelectExpression.Visit <ClientServerSplittingSelectBuilder>(); var splitSelect = selectNode as ClientServerSplitSelectExpression; if (splitSelect != null) { clientSideSelectPart = splitSelect.ClientSideExpression; selectNode = splitSelect.ServerExpression; } builder.AppendParameter("$select", selectNode); } if (parser.Projection == RestQueryableTreeParser.QueryProjection.Enumerable) { if (parser.SkipCount.HasValue) { builder.AppendParameter("$skip", parser.SkipCount.Value); } builder.AppendParameter("$top", parser.TakeCount.GetValueOrDefault(int.MaxValue)); } var expandedPaths = parser.ExpandedPaths; if (!string.IsNullOrEmpty(expandedPaths)) { builder.AppendParameter("$expand", expandedPaths); } if (parser.IncludeTotalCount) { builder.AppendParameter("$totalcount", "true"); } return(parser.RepositoryUri + "?" + builder); }