public static QueryResult Parse(JToken response, Uri nextLink, bool validate)
        {
            var result = new QueryResult() { Response = response };

            long? inlineCount = null;

            // Try and get the values as an array
            result.Values = response as JArray;
            if (result.Values == null && response is JObject)
            {
                // Otherwise try and get the values from the results property
                // (which is the case when we retrieve the count inline)
                result.Values = response[InlineCountResultsKey] as JArray;
                inlineCount = response.Value<long?>(InlineCountCountKey);
                if (result.Values == null && validate)
                {
                    string responseStr = response != null ? response.ToString() : "null";
                    throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture,
                                                                      Resources.MobileServiceTable_ExpectedArray,
                                                                      responseStr));
                }
                else if (result.Values == null)
                {
                    result.Values = new JArray(response);
                }
            }

            // Get the count via the inline count or default an unspecified count to -1
            result.TotalCount = inlineCount.GetValueOrDefault(-1L);

            result.NextLink = nextLink;

            return result;
        }
Ejemplo n.º 2
0
 private bool EndOfResult(QueryResult result)
 {
     // if we got as many as we initially wanted 
     // or there are no more results
     // then we're at the end
     return cursor.Complete || result.Values.Count == 0;
 }
Ejemplo n.º 3
0
        // follows next links in the query result and returns final result
        private async Task<QueryResult> FollowNextLinks(QueryResult result)
        {
            while (!this.EndOfResult(result) && // if we are not at the end of result
                    IsNextLinkValid(result.NextLink, this.options)) // and there is a valid link to get more results
            {
                this.CancellationToken.ThrowIfCancellationRequested();

                result = await this.Table.ReadAsync(result.NextLink);
                await this.ProcessAll(result.Values); // process the results as soon as we've gotten them
            }
            return result;
        }