internal static ServiceQuery GetServiceQuery(Uri uri)
        {
            if (uri == null)
            {
                throw Error.ArgumentNull("uri");
            }

            NameValueCollection queryPartCollection = UriQueryUtility.ParseQueryString(uri.Query);

            List <ServiceQueryPart> serviceQueryParts = new List <ServiceQueryPart>();

            foreach (string queryPart in queryPartCollection)
            {
                if (queryPart == null || !queryPart.StartsWith("$", StringComparison.Ordinal))
                {
                    // not a special query string
                    continue;
                }

                foreach (string value in queryPartCollection.GetValues(queryPart))
                {
                    string queryOperator = queryPart.Substring(1);
                    if (!ServiceQuery.IsSupportedQueryOperator(queryOperator))
                    {
                        // skip any operators we don't support
                        continue;
                    }

                    ServiceQueryPart serviceQueryPart = new ServiceQueryPart(queryOperator, value);
                    serviceQueryParts.Add(serviceQueryPart);
                }
            }

            // Query parts for OData need to be ordered $filter, $orderby, $skip, $top. For this
            // set of query operators, they are already in alphabetical order, so it suffices to
            // order by operator name. In the future if we support other operators, this may need
            // to be reexamined.
            serviceQueryParts = serviceQueryParts.OrderBy(p => p.QueryOperator).ToList();

            ServiceQuery serviceQuery = new ServiceQuery()
            {
                QueryParts = serviceQueryParts,
            };

            return(serviceQuery);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Public constructor
        /// </summary>
        /// <param name="queryOperator">The query operator</param>
        /// <param name="expression">The query expression</param>
        public ServiceQueryPart(string queryOperator, string expression)
        {
            if (queryOperator == null)
            {
                throw Error.ArgumentNull("queryOperator");
            }
            if (expression == null)
            {
                throw Error.ArgumentNull("expression");
            }

            if (!ServiceQuery.IsSupportedQueryOperator(queryOperator))
            {
                throw Error.Argument("queryOperator", SRResources.InvalidQueryOperator, queryOperator);
            }

            QueryOperator = queryOperator;
            Expression    = expression;
        }