Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ODataQueryOptions"/> class based on the incoming request and some metadata information from
        /// the <see cref="ODataQueryContext"/>.
        /// </summary>
        /// <param name="context">The <see cref="ODataQueryContext"/> which contains the <see cref="IEdmModel"/> and some type information.</param>
        private void Initialize(ODataQueryContext context)
        {
            Contract.Assert(context != null);

            ODataUriResolver uriResolver = context.RequestContainer.GetRequiredService <ODataUriResolver>();

            if (uriResolver != null)
            {
                _enableNoDollarSignQueryOptions = uriResolver.EnableNoDollarQueryOptions;
            }

            // Parse the query from request Uri, including only keys which are OData query parameters or parameter alias
            // OData query parameters are normalized with the $-sign prefixes when the
            // <code>EnableNoDollarSignPrefixSystemQueryOption</code> option is used.
            RawValues = new ODataRawQueryOptions();
            IDictionary <string, string> normalizedQueryParameters = GetODataQueryParameters();

            _queryOptionParser = new ODataQueryOptionParser(
                context.Model,
                context.ElementType,
                context.NavigationSource,
                normalizedQueryParameters);

            // Note: the context.RequestContainer must be set by the ODataQueryOptions constructor.
            Contract.Assert(context.RequestContainer != null);
            _queryOptionParser.Resolver = context.RequestContainer.GetRequiredService <ODataUriResolver>();

            BuildQueryOptions(normalizedQueryParameters);

            Validator = ODataQueryValidator.GetODataQueryValidator(context);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ODataQueryOptions"/> class based on the incoming request and some metadata information from
        /// the <see cref="ODataQueryContext"/>.
        /// </summary>
        /// <param name="context">The <see cref="ODataQueryContext"/> which contains the <see cref="IEdmModel"/> and some type information.</param>
        private void Initialize(ODataQueryContext context)
        {
            Contract.Assert(context != null);

            ODataUriResolver uriResolver = null;

            if (context.RequestContainer != null)
            {
                uriResolver = context.RequestContainer.GetService <ODataUriResolver>();
            }

            if (uriResolver != null)
            {
                _enableNoDollarSignQueryOptions = uriResolver.EnableNoDollarQueryOptions;
            }
            else
            {
                // Use the global setting
                _enableNoDollarSignQueryOptions = context.Request.IsNoDollarQueryEnable();
            }

            // Parse the query from request Uri, including only keys which are OData query parameters or parameter alias
            // OData query parameters are normalized with the $-sign prefixes when the
            // <code>EnableNoDollarSignPrefixSystemQueryOption</code> option is used.
            RawValues = new ODataRawQueryOptions();
            IDictionary <string, string> normalizedQueryParameters = GetODataQueryParameters();

            _queryOptionParser = new ODataQueryOptionParser(
                context.Model,
                context.ElementType,
                context.NavigationSource,
                normalizedQueryParameters);

            if (uriResolver != null)
            {
                _queryOptionParser.Resolver = uriResolver;
            }
            else
            {
                // By default, let's enable the property name case-insensitive
                _queryOptionParser.Resolver = new ODataUriResolver {
                    EnableCaseInsensitive = true
                };
            }

            BuildQueryOptions(normalizedQueryParameters);

            Validator = ODataQueryValidator.GetODataQueryValidator(context);
        }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ODataQueryOptions"/> class based on the incoming request and some metadata information from
        /// the <see cref="ODataQueryContext"/>.
        /// </summary>
        /// <param name="context">The <see cref="ODataQueryContext"/> which contains the <see cref="IEdmModel"/> and some type information.</param>
        /// <param name="request">The incoming request message.</param>
        public ODataQueryOptions(ODataQueryContext context, HttpRequestMessage request)
        {
            if (context == null)
            {
                throw Error.ArgumentNull("context");
            }

            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            if (request.GetConfiguration() != null)
            {
                _assembliesResolver = request.GetConfiguration().Services.GetAssembliesResolver();
            }

            // fallback to the default assemblies resolver if none available.
            _assembliesResolver = _assembliesResolver ?? new DefaultAssembliesResolver();

            // remember the context and request
            Context = context;
            Request = request;

            // Parse the query from request Uri
            RawValues = new ODataRawQueryOptions();
            IDictionary <string, string> queryParameters =
                request.GetQueryNameValuePairs().ToDictionary(p => p.Key, p => p.Value);

            _queryOptionParser = new ODataQueryOptionParser(
                context.Model,
                context.ElementType,
                context.NavigationSource,
                queryParameters);

            HttpConfiguration configuration = Request.GetConfiguration();

            if (configuration != null)
            {
                ODataUriResolverSetttings resolverSettings = configuration.GetResolverSettings();
                _queryOptionParser.Resolver = resolverSettings.CreateResolver(context.Model);
            }

            BuildQueryOptions(queryParameters);

            Validator = new ODataQueryValidator();
        }
Exemple #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ODataQueryOptions"/> class based on the incoming request and some metadata information from
        /// the <see cref="ODataQueryContext"/>.
        /// </summary>
        /// <param name="context">The <see cref="ODataQueryContext"/> which contains the <see cref="IEdmModel"/> and some type information.</param>
        /// <param name="request">The incoming request message.</param>
        public ODataQueryOptions(ODataQueryContext context, HttpRequestMessage request)
        {
            if (context == null)
            {
                throw Error.ArgumentNull("context");
            }

            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            // Set the request container into context
            Contract.Assert(context.RequestContainer == null);
            context.RequestContainer = request.GetRequestContainer();

            // Remember the context and request
            Context = context;
            Request = request;

            ODataUriResolver uriResolver = request.GetRequestContainer().GetRequiredService <ODataUriResolver>();

            if (uriResolver != null)
            {
                _enableNoDollarSignQueryOptions = uriResolver.EnableNoDollarQueryOptions;
            }

            // Parse the query from request Uri, including only keys which are OData query parameters or parameter alias
            // OData query parameters are normalized with the $-sign prefixes when the
            // <code>EnableNoDollarSignPrefixSystemQueryOption</code> option is used.
            RawValues = new ODataRawQueryOptions();
            IDictionary <string, string> normalizedqueryParameters = GetODataQueryParameters();

            _queryOptionParser = new ODataQueryOptionParser(
                context.Model,
                context.ElementType,
                context.NavigationSource,
                normalizedqueryParameters);

            _queryOptionParser.Resolver = uriResolver;

            BuildQueryOptions(normalizedqueryParameters);

            Validator = ODataQueryValidator.GetODataQueryValidator(context);
        }
Exemple #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ODataQueryOptions"/> class based on the incoming request and some metadata information from
        /// the <see cref="ODataQueryContext"/>.
        /// </summary>
        /// <param name="context">The <see cref="ODataQueryContext"/> which contains the <see cref="IEdmModel"/> and some type information.</param>
        private void Initialize(ODataQueryContext context)
        {
            Contract.Assert(context != null);

            // Parse the query from request Uri, including only keys which are OData query parameters or parameter alias
            RawValues = new ODataRawQueryOptions();
            IDictionary <string, string> queryParameters = GetODataQueryParameters();

            _queryOptionParser = new ODataQueryOptionParser(
                context.Model,
                context.ElementType,
                context.NavigationSource,
                queryParameters);

            // Note: the context.RequestContainer must be set by the ODataQueryOptions constructor.
            Contract.Assert(context.RequestContainer != null);
            _queryOptionParser.Resolver = context.RequestContainer.GetRequiredService <ODataUriResolver>();

            BuildQueryOptions(queryParameters);

            Validator = ODataQueryValidator.GetODataQueryValidator(context);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ODataQueryOptions"/> class based on the incoming request and some metadata information from
        /// the <see cref="ODataQueryContext"/>.
        /// </summary>
        /// <param name="context">The <see cref="ODataQueryContext"/> which contains the <see cref="IEdmModel"/> and some type information.</param>
        /// <param name="request">The incoming request message.</param>
        public ODataQueryOptions(ODataQueryContext context, HttpRequestMessage request)
        {
            if (context == null)
            {
                throw Error.ArgumentNull("context");
            }

            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            // Set the request container into context
            Contract.Assert(context.RequestContainer == null);
            context.RequestContainer = request.GetRequestContainer();

            // Remember the context and request
            Context = context;
            Request = request;

            // Parse the query from request Uri, including only keys which are OData query parameters or parameter alias
            RawValues = new ODataRawQueryOptions();
            IDictionary <string, string> queryParameters = GetODataQueryParameters();

            _queryOptionParser = new ODataQueryOptionParser(
                context.Model,
                context.ElementType,
                context.NavigationSource,
                queryParameters);

            _queryOptionParser.Resolver = request.GetRequestContainer().GetRequiredService <ODataUriResolver>();

            BuildQueryOptions(queryParameters);

            Validator = ODataQueryValidator.GetODataQueryValidator(context);
        }
Exemple #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ODataQueryOptions"/> class based on the incoming request and some metadata information from
        /// the <see cref="ODataQueryContext"/>.
        /// </summary>
        /// <param name="context">The <see cref="ODataQueryContext"/> which contains the <see cref="IEdmModel"/> and some type information.</param>
        /// <param name="request">The incoming request message.</param>
        public ODataQueryOptions(ODataQueryContext context, HttpRequestMessage request)
        {
            if (context == null)
            {
                throw Error.ArgumentNull("context");
            }

            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            if (request.GetConfiguration() != null)
            {
                _assembliesResolver = request.GetConfiguration().Services.GetAssembliesResolver();
            }

            // fallback to the default assemblies resolver if none available.
            _assembliesResolver = _assembliesResolver ?? new DefaultAssembliesResolver();

            // remember the context and request
            Context = context;
            Request = request;

            // Parse the query from request Uri
            RawValues = new ODataRawQueryOptions();
            IEnumerable <KeyValuePair <string, string> > queryParameters = request.GetQueryNameValuePairs();

            foreach (KeyValuePair <string, string> kvp in queryParameters)
            {
                switch (kvp.Key)
                {
                case "$filter":
                    RawValues.Filter = kvp.Value;
                    ThrowIfEmpty(kvp.Value, "$filter");
                    Filter = new FilterQueryOption(kvp.Value, context);
                    break;

                case "$orderby":
                    RawValues.OrderBy = kvp.Value;
                    ThrowIfEmpty(kvp.Value, "$orderby");
                    OrderBy = new OrderByQueryOption(kvp.Value, context);
                    break;

                case "$top":
                    RawValues.Top = kvp.Value;
                    ThrowIfEmpty(kvp.Value, "$top");
                    Top = new TopQueryOption(kvp.Value, context);
                    break;

                case "$skip":
                    RawValues.Skip = kvp.Value;
                    ThrowIfEmpty(kvp.Value, "$skip");
                    Skip = new SkipQueryOption(kvp.Value, context);
                    break;

                case "$select":
                    RawValues.Select = kvp.Value;
                    break;

                case "$inlinecount":
                    RawValues.InlineCount = kvp.Value;
                    ThrowIfEmpty(kvp.Value, "$inlinecount");
                    InlineCount = new InlineCountQueryOption(kvp.Value, context);
                    break;

                case "$expand":
                    RawValues.Expand = kvp.Value;
                    break;

                case "$format":
                    RawValues.Format = kvp.Value;
                    break;

                case "$skiptoken":
                    RawValues.SkipToken = kvp.Value;
                    break;

                default:
                    // we don't throw if we can't recognize the query
                    break;
                }
            }

            Validator = new ODataQueryValidator();
        }
 public ODataQueryValidatorTest()
 {
     _validator = new ODataQueryValidator();
     _context   = ValidationTestHelper.CreateCustomerContext(false);
 }
Exemple #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ODataQueryOptions"/> class based on the incoming request and some metadata information from
        /// the <see cref="ODataQueryContext"/>.
        /// </summary>
        /// <param name="context">The <see cref="ODataQueryContext"/> which contains the <see cref="IEdmModel"/> and some type information.</param>
        /// <param name="request">The incoming request message.</param>
        public ODataQueryOptions(ODataQueryContext context, HttpRequestMessage request)
        {
            if (context == null)
            {
                throw Error.ArgumentNull("context");
            }

            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            if (request.GetConfiguration() != null)
            {
                _assembliesResolver = request.GetConfiguration().Services.GetAssembliesResolver();
            }

            // fallback to the default assemblies resolver if none available.
            _assembliesResolver = _assembliesResolver ?? new DefaultAssembliesResolver();

            // remember the context and request
            Context = context;
            Request = request;

            // Parse the query from request Uri
            RawValues = new ODataRawQueryOptions();
            IEnumerable <KeyValuePair <string, string> > queryParameters = request.GetQueryNameValuePairs();

            IDictionary <string, string> queryOptions = queryParameters.ToDictionary(p => p.Key, p => p.Value);

            _queryOptionParser = new ODataQueryOptionParser(context.Model, context.ElementType,
                                                            context.NavigationSource, queryOptions);

            foreach (KeyValuePair <string, string> kvp in queryParameters)
            {
                switch (kvp.Key)
                {
                case "$apply":
                    ThrowIfEmpty(kvp.Value, "$apply");
                    RawValues.Apply = kvp.Value;
                    Apply           = new ApplyQueryOption(context, _queryOptionParser);
                    break;

                case "aggregationWindowSize":
                    _aggregationWindowSize = int.Parse(kvp.Value);
                    break;

                case "$filter":
                    ThrowIfEmpty(kvp.Value, "$filter");
                    RawValues.Filter = kvp.Value;
                    Filter           = new FilterQueryOption(kvp.Value, context, _queryOptionParser);
                    break;

                case "$orderby":
                    ThrowIfEmpty(kvp.Value, "$orderby");
                    RawValues.OrderBy = kvp.Value;
                    OrderBy           = new OrderByQueryOption(kvp.Value, context, _queryOptionParser);
                    break;

                case "$top":
                    ThrowIfEmpty(kvp.Value, "$top");
                    RawValues.Top = kvp.Value;
                    Top           = new TopQueryOption(kvp.Value, context, _queryOptionParser);
                    break;

                case "$skip":
                    ThrowIfEmpty(kvp.Value, "$skip");
                    RawValues.Skip = kvp.Value;
                    Skip           = new SkipQueryOption(kvp.Value, context, _queryOptionParser);
                    break;

                case "$select":
                    RawValues.Select = kvp.Value;
                    break;

                case "$count":
                    ThrowIfEmpty(kvp.Value, "$count");
                    RawValues.Count = kvp.Value;
                    Count           = new CountQueryOption(kvp.Value, context, _queryOptionParser);
                    break;

                case "$expand":
                    RawValues.Expand = kvp.Value;
                    break;

                case "$format":
                    RawValues.Format = kvp.Value;
                    break;

                case "$skiptoken":
                    RawValues.SkipToken = kvp.Value;
                    break;

                default:
                    // we don't throw if we can't recognize the query
                    break;
                }
            }

            if (RawValues.Select != null || RawValues.Expand != null)
            {
                SelectExpand = new SelectExpandQueryOption(RawValues.Select, RawValues.Expand,
                                                           context, _queryOptionParser);
            }

            Validator = new ODataQueryValidator();
        }