protected async Task <IHttpActionResult> QueryAsync(string application, string service, string collection) { var serviceUri = GetServiceUri(application, service); try { var query = Request.GetQueryNameValuePairs(); // Query one service partition, allowing the partition to do the distributed query. var proxy = await GetServiceProxyAsync <IQueryableService>(serviceUri).ConfigureAwait(false); var results = await proxy.QueryAsync(collection, query).ConfigureAwait(false); // Construct the final, aggregated result. var result = new ODataResult { ODataMetadata = "", Value = results.Select(JsonConvert.DeserializeObject <JObject>), }; return(Ok(result)); } catch (Exception e) { return(HandleException(e, serviceUri)); } }
private async Task QueryCollectionAsync(HttpContext httpContext, StatefulServiceContext serviceContext, IReliableStateManager stateManager, string collection, Guid partitionId) { if (partitionId != serviceContext.PartitionId) { // Query this partition. await ForwardQueryCollectionAsync(httpContext, serviceContext, stateManager, collection, partitionId).ConfigureAwait(false); return; } // Query the local reliable collection. var query = httpContext.Request.Query.Select(p => new KeyValuePair <string, string>(p.Key, p.Value)); var results = await stateManager.QueryPartitionAsync(collection, query, partitionId, CancellationToken.None).ConfigureAwait(false); httpContext.Response.ContentType = "application/json"; httpContext.Response.StatusCode = (int)HttpStatusCode.OK; // Write the response. var result = new ODataResult { ODataMetadata = "", Value = results, }; string response = JsonConvert.SerializeObject(result); await httpContext.Response.WriteAsync(response).ConfigureAwait(false); }