示例#1
0
        /// <summary>
        /// Transforms a POST request targeted at a resource path ending in $query into a GET request.
        /// The query options are parsed from the request body and appended to the request URL.
        /// </summary>
        /// <param name="request">The request.</param>
        internal static void TransformQueryRequest(this HttpRequestMessage request)
        {
            // Fetch parser capable of parsing the query options in the request body
            IODataQueryOptionsParser queryOptionsParser = ODataQueryOptionsParserFactory.GetQueryOptionsParser(request);
            // Parse query options in request body
            Stream requestStream = request.Content.ReadAsStreamAsync().Result;
            string queryOptions  = queryOptionsParser.ParseAsync(requestStream).Result;

            Uri    requestUri  = request.RequestUri;
            string requestPath = requestUri.LocalPath;
            string queryString = requestUri.Query;

            // Strip off the /$query part
            requestPath = requestPath.Substring(0, requestPath.LastIndexOf('/' + ODataRouteConstants.QuerySegment, StringComparison.OrdinalIgnoreCase));
            if (!string.IsNullOrWhiteSpace(queryOptions))
            {
                if (string.IsNullOrWhiteSpace(queryString))
                {
                    queryString = '?' + queryOptions;
                }
                else
                {
                    queryString += '&' + queryOptions;
                }
            }

            request.RequestUri = new UriBuilder(requestUri.Scheme, requestUri.Host, requestUri.Port, requestPath, queryString).Uri;
            request.Method     = HttpMethod.Get;
        }
示例#2
0
        /// <summary>
        /// Transforms a POST request targeted at a resource path ending in $query into a GET request.
        /// The query options are parsed from the request body and appended to the request URL.
        /// </summary>
        /// <param name="request">The request.</param>
        internal static void TransformQueryRequest(this HttpRequest request)
        {
            // Fetch parser capable of parsing the query options in the request body
            IODataQueryOptionsParser queryOptionsParser = ODataQueryOptionsParserFactory.GetQueryOptionsParser(request);
            // Parse query options in request body
            string queryOptions = queryOptionsParser.ParseAsync(request.Body).Result;

            string requestPath = request.Path.Value;
            string queryString = request.QueryString.Value;

            // Strip off the /$query part
            requestPath = requestPath.Substring(0, requestPath.LastIndexOf('/' + ODataRouteConstants.QuerySegment, StringComparison.OrdinalIgnoreCase));
            if (!string.IsNullOrWhiteSpace(queryOptions))
            {
                if (string.IsNullOrWhiteSpace(queryString))
                {
                    queryString = '?' + queryOptions;
                }
                else
                {
                    queryString += '&' + queryOptions;
                }
            }

            request.Path        = new PathString(requestPath);
            request.QueryString = new QueryString(queryString);
            request.Method      = HttpMethods.Get;
        }
示例#3
0
        public static IODataQueryOptionsParser GetQueryOptionsParser(HttpRequest request)
        {
            string contentType = request.ContentType;
#endif

            IServiceProvider requestContainer = request.GetRequestContainer();

            Contract.Assert(requestContainer != null);

            // Fetch parsers available in the request container for parsing the query options in the request body
            IEnumerable <IODataQueryOptionsParser> parsers = requestContainer.GetRequiredService <IEnumerable <IODataQueryOptionsParser> >();
            IODataQueryOptionsParser parser = parsers.FirstOrDefault(d => d.CanParse(request));

            if (parser == null)
            {
                throw new ODataException(string.Format(
                                             CultureInfo.InvariantCulture,
                                             SRResources.CannotFindParserForRequestMediaType,
                                             contentType));
            }

            return(parser);
        }
 /// <summary>
 /// Initializes a new <see cref="SynapseIpcManagementApiClient"/>
 /// </summary>
 /// <param name="loggerFactory">The service used to create <see cref="ILogger"/>s</param>
 /// <param name="mediator">The service used to mediate calls</param>
 /// <param name="mapper">The service used to map objects</param>
 /// <param name="queryOptionsParser">The service used to parse <see cref="ODataQueryOptions"/></param>
 protected SynapseIpcManagementApiClient(ILoggerFactory loggerFactory, IMediator mediator, IMapper mapper, IODataQueryOptionsParser queryOptionsParser)
 {
     this.Logger             = loggerFactory.CreateLogger(this.GetType());
     this.Mediator           = mediator;
     this.Mapper             = mapper;
     this.QueryOptionsParser = queryOptionsParser;
 }
 /// <summary>
 /// Initializes a new <see cref="SynapseGrpcManagementApi"/>
 /// </summary>
 /// <param name="logger">The service used to perform logging</param>
 /// <param name="mediator">The service used to mediate calls</param>
 /// <param name="mapper">The service used to map objects</param>
 /// <param name="queryOptionsParser">The service used to parse <see cref="ODataQueryOptions"/></param>
 public SynapseGrpcManagementApi(ILogger <SynapseGrpcManagementApi> logger, IMediator mediator, IMapper mapper, IODataQueryOptionsParser queryOptionsParser)
 {
     this.Logger             = logger;
     this.Mediator           = mediator;
     this.Mapper             = mapper;
     this.QueryOptionsParser = queryOptionsParser;
 }