A default implementation of PomonaQuery, only simple querying.
示例#1
0
 public PomonaResponse(PomonaQuery query, object entity, HttpStatusCode statusCode)
 {
     if (query == null) throw new ArgumentNullException("query");
     this.entity = entity;
     this.statusCode = statusCode;
     expandedPaths = query.ExpandedPaths;
     resultType = query.ResultType;
 }
示例#2
0
        private void ParseOrderBy(PomonaQuery query, string s)
        {
            Type orderedType;

            if (query.GroupByExpression != null)
            {
                // When groupby is added to query, ordering will occur AFTER select, not before.
                orderedType = query.SelectExpression.ReturnType;
            }
            else
            {
                orderedType = query.OfType.Type;
            }
            query.OrderByExpressions = this.parser.ParseOrderBy(orderedType, s);
        }
示例#3
0
        private void UpdateResultType(PomonaQuery query)
        {
            TypeSpec elementType = query.OfType;

            if (query.SelectExpression != null)
            {
                elementType = this.typeMapper.FromType(query.SelectExpression.ReturnType);
            }

            if (query.Projection == QueryProjection.First ||
                query.Projection == QueryProjection.FirstOrDefault ||
                query.Projection == QueryProjection.Single ||
                query.Projection == QueryProjection.SingleOrDefault ||
                query.Projection == QueryProjection.Last ||
                query.Projection == QueryProjection.LastOrDefault)
            {
                query.ResultType = elementType;
            }
        }
        public PomonaQuery TransformRequest(PomonaContext context, StructuredType rootType, int? defaultTop = null)
        {
            if (context == null)
                throw new ArgumentNullException(nameof(context));
            if (rootType == null)
                throw new ArgumentNullException(nameof(rootType));

            StructuredType ofType = null;
            if (context.Query["$oftype"].HasValue)
                ofType = (StructuredType)this.typeMapper.FromType((string)context.Query["$oftype"]);

            var query = new PomonaQuery(rootType, ofType);

            if (context.Query["$debug"].HasValue)
            {
                query.DebugInfoKeys =
                    new HashSet<string>(((string)context.Query["$debug"]).ToLower().Split(',').Select(x => x.Trim()));
            }

            string filter = null;
            var top = defaultTop ?? 100;
            var skip = 0;

            if (context.Query["$totalcount"].HasValue && ((string)context.Query["$totalcount"]).ToLower() == "true")
                query.IncludeTotalCount = true;

            if (context.Query["$top"].HasValue)
                top = int.Parse(context.Query["$top"]);

            if (context.Query["$skip"].HasValue)
                skip = int.Parse(context.Query["$skip"]);

            if (context.Query["$filter"].HasValue)
                filter = (string)context.Query["$filter"];

            ParseFilterExpression(query, filter);
            var selectSourceType = query.OfType.Type;

            if (context.Query["$groupby"].HasValue)
            {
                var groupby = (string)context.Query["$groupby"];
                ParseGroupByExpression(query, groupby);
                selectSourceType =
                    typeof(IGrouping<,>).MakeGenericType(
                        query.GroupByExpression.ReturnType, selectSourceType);
            }

            if (context.Query["$projection"].HasValue)
            {
                var projectionString = (string)context.Query["$projection"];
                query.Projection = projectionMap[projectionString];

                QueryProjection projection;
                if (!projectionMap.TryGetValue(projectionString, out projection))
                {
                    throw new QueryParseException("\"" + projectionString +
                                                  "\" is not a valid value for query parameter $projection",
                                                  null,
                                                  QueryParseErrorReason.UnrecognizedProjection,
                                                  null);
                }
                query.Projection = projection;
            }
            else
            {
                query.Projection = QueryProjection.AsEnumerable;
            }

            if (context.Query["$select"].HasValue)
            {
                var select = (string)context.Query["$select"];
                ParseSelect(query, select, selectSourceType);
            }

            if (context.Query["$orderby"].HasValue)
                ParseOrderBy(query, (string)context.Query["$orderby"]);

            query.Top = top;
            query.Skip = skip;

            if (context.Query["$expand"].HasValue)
            {
                // TODO: Translate expanded paths using TypeMapper
                query.ExpandedPaths = ((string)context.Query["$expand"]);
            }
            else
                query.ExpandedPaths = string.Empty;

            query.Url = context.Url;

            UpdateResultType(query);

            return query;
        }
 private void ParseOrderBy(PomonaQuery query, string s)
 {
     Type orderedType;
     if (query.GroupByExpression != null)
     {
         // When groupby is added to query, ordering will occur AFTER select, not before.
         orderedType = query.SelectExpression.ReturnType;
     }
     else
         orderedType = query.OfType.Type;
     query.OrderByExpressions = this.parser.ParseOrderBy(orderedType, s);
 }
 private void ParseGroupByExpression(PomonaQuery query, string groupby)
 {
     query.GroupByExpression = this.parser.ParseSelectList(query.OfType.Type, groupby);
 }
 private void ParseFilterExpression(PomonaQuery query, string filter)
 {
     filter = filter ?? "true";
     query.FilterExpression = this.parser.Parse(query.OfType.Type, filter);
 }
 private void ParseSelect(PomonaQuery query, string select, Type thisType)
 {
     query.SelectExpression = this.parser.ParseSelectList(thisType, select);
 }
        private void UpdateResultType(PomonaQuery query)
        {
            TypeSpec elementType = query.OfType;
            if (query.SelectExpression != null)
                elementType = this.typeMapper.FromType(query.SelectExpression.ReturnType);

            if (query.Projection == QueryProjection.First
                || query.Projection == QueryProjection.FirstOrDefault
                || query.Projection == QueryProjection.Single
                || query.Projection == QueryProjection.SingleOrDefault
                || query.Projection == QueryProjection.Last
                || query.Projection == QueryProjection.LastOrDefault)
                query.ResultType = elementType;
        }
        private void UpdateResultType(PomonaQuery query)
        {
            TypeSpec elementType = query.OfType;
            if (query.SelectExpression != null)
                elementType = typeMapper.GetClassMapping(query.SelectExpression.ReturnType);

            if (query.Projection == PomonaQuery.ProjectionType.First || query.Projection == PomonaQuery.ProjectionType.FirstOrDefault)
                query.ResultType = elementType;
        }
示例#11
0
        public PomonaQuery TransformRequest(PomonaContext context, StructuredType rootType, int?defaultTop = null)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (rootType == null)
            {
                throw new ArgumentNullException(nameof(rootType));
            }

            StructuredType ofType = null;

            if (context.Query["$oftype"].HasValue)
            {
                ofType = (StructuredType)this.typeMapper.FromType((string)context.Query["$oftype"]);
            }

            var query = new PomonaQuery(rootType, ofType);

            if (context.Query["$debug"].HasValue)
            {
                query.DebugInfoKeys =
                    new HashSet <string>(((string)context.Query["$debug"]).ToLower().Split(',').Select(x => x.Trim()));
            }

            string filter = null;
            var    top    = defaultTop ?? 100;
            var    skip   = 0;

            if (context.Query["$totalcount"].HasValue && ((string)context.Query["$totalcount"]).ToLower() == "true")
            {
                query.IncludeTotalCount = true;
            }

            if (context.Query["$top"].HasValue)
            {
                top = int.Parse(context.Query["$top"]);
            }

            if (context.Query["$skip"].HasValue)
            {
                skip = int.Parse(context.Query["$skip"]);
            }

            if (context.Query["$filter"].HasValue)
            {
                filter = (string)context.Query["$filter"];
            }

            ParseFilterExpression(query, filter);
            var selectSourceType = query.OfType.Type;

            if (context.Query["$groupby"].HasValue)
            {
                var groupby = (string)context.Query["$groupby"];
                ParseGroupByExpression(query, groupby);
                selectSourceType =
                    typeof(IGrouping <,>).MakeGenericType(
                        query.GroupByExpression.ReturnType, selectSourceType);
            }

            if (context.Query["$projection"].HasValue)
            {
                var projectionString = (string)context.Query["$projection"];
                query.Projection = projectionMap[projectionString];

                QueryProjection projection;
                if (!projectionMap.TryGetValue(projectionString, out projection))
                {
                    throw new QueryParseException("\"" + projectionString +
                                                  "\" is not a valid value for query parameter $projection",
                                                  null,
                                                  QueryParseErrorReason.UnrecognizedProjection,
                                                  null);
                }
                query.Projection = projection;
            }
            else
            {
                query.Projection = QueryProjection.AsEnumerable;
            }

            if (context.Query["$select"].HasValue)
            {
                var select = (string)context.Query["$select"];
                ParseSelect(query, select, selectSourceType);
            }

            if (context.Query["$orderby"].HasValue)
            {
                ParseOrderBy(query, (string)context.Query["$orderby"]);
            }

            query.Top  = top;
            query.Skip = skip;

            if (context.Query["$expand"].HasValue)
            {
                // TODO: Translate expanded paths using TypeMapper
                query.ExpandedPaths = ((string)context.Query["$expand"]);
            }
            else
            {
                query.ExpandedPaths = string.Empty;
            }

            query.Url = context.Url;

            UpdateResultType(query);

            return(query);
        }
示例#12
0
 private void ParseGroupByExpression(PomonaQuery query, string groupby)
 {
     query.GroupByExpression = this.parser.ParseSelectList(query.OfType.Type, groupby);
 }
示例#13
0
 private void ParseFilterExpression(PomonaQuery query, string filter)
 {
     filter = filter ?? "true";
     query.FilterExpression = this.parser.Parse(query.OfType.Type, filter);
 }
示例#14
0
 private void ParseSelect(PomonaQuery query, string select, Type thisType)
 {
     query.SelectExpression = this.parser.ParseSelectList(thisType, select);
 }
示例#15
0
 public PomonaResponse(PomonaQuery query, T entity)
     : base(query, entity)
 {
 }
        public PomonaQuery TransformRequest(NancyContext nancyContext, TransformedType rootType)
        {
            var request = nancyContext.Request;
            if (request == null)
                throw new ArgumentNullException("request");
            if (nancyContext == null)
                throw new ArgumentNullException("nancyContext");
            if (rootType == null)
                throw new ArgumentNullException("rootType");

            TransformedType ofType = null;
            if (request.Query["$oftype"].HasValue)
            {
                ofType = (TransformedType) typeMapper.GetClassMapping((string) request.Query["$oftype"]);
            }

            var query = new PomonaQuery(rootType, ofType);

            if (request.Query["$debug"].HasValue)
            {
                query.DebugInfoKeys =
                    new HashSet<string>(((string) request.Query["$debug"]).ToLower().Split(',').Select(x => x.Trim()));
            }

            string filter = null;
            var top = 100;
            var skip = 0;

            if (request.Query["$totalcount"].HasValue && ((string) request.Query["$totalcount"]).ToLower() == "true")
                query.IncludeTotalCount = true;

            if (request.Query["$top"].HasValue)
                top = int.Parse(request.Query["$top"]);

            if (request.Query["$skip"].HasValue)
                skip = int.Parse(request.Query["$skip"]);

            if (request.Query["$filter"].HasValue)
                filter = (string) request.Query["$filter"];

            ParseFilterExpression(query, filter);
            var selectSourceType = query.OfType.Type;

            if (request.Query["$groupby"].HasValue)
            {
                var groupby = (string) request.Query["$groupby"];
                ParseGroupByExpression(query, groupby);
                selectSourceType =
                    typeof (IGrouping<,>).MakeGenericType(
                        query.GroupByExpression.ReturnType, selectSourceType);
            }

            if (request.Query["$projection"].HasValue)
            {
                var projectionString = (string) request.Query["$projection"];
                PomonaQuery.ProjectionType projection;
                if (!Enum.TryParse(projectionString, true, out projection))
                    throw new QueryParseException("\"" + projectionString +
                                                  "\" is not a valid value for query parameter $projection",
                        null,
                        QueryParseErrorReason.UnrecognizedProjection,
                        null);
                query.Projection = projection;
            }

            if (request.Query["$select"].HasValue)
            {
                var select = (string) request.Query["$select"];
                ParseSelect(query, select, selectSourceType);
            }

            if (request.Query["$orderby"].HasValue)
                ParseOrderBy(query, (string) request.Query["$orderby"]);

            query.Top = top;
            query.Skip = skip;

            if (request.Query["$expand"].HasValue)
            {
                // TODO: Translate expanded paths using TypeMapper
                query.ExpandedPaths = ((string) request.Query["$expand"]);
            }
            else
                query.ExpandedPaths = string.Empty;

            query.Url = request.Url.ToString();

            UpdateResultType(query);

            return query;
        }
示例#17
0
 public PomonaResponse(PomonaQuery query, T entity, HttpStatusCode statusCode)
     : base(query, entity, statusCode)
 {
 }
示例#18
0
 public PomonaResponse(PomonaQuery query, object entity)
     : this(query, entity, HttpStatusCode.OK)
 {
 }