/// <summary>
        /// Parse a JSON response into <see cref="QueryResult"/> object 
        /// that contains sequence of elements and the count of objects.  
        /// This method abstracts out the differences between a raw array response and 
        /// an inline count response.
        /// </summary>
        /// <param name="httpResponse">
        /// The HTTP response
        /// </param>
        /// <param name="serializerSettings">
        /// The serialization settings
        /// </param>
        /// <param name="validate">
        /// To throw if the content is null or empty
        /// </param>
        public static QueryResult Parse(MobileServiceHttpResponse httpResponse, JsonSerializerSettings serializerSettings, bool validate)
        {
            Debug.Assert(httpResponse != null);

            JToken response = httpResponse.Content.ParseToJToken(serializerSettings);

            Uri link = httpResponse.Link != null && httpResponse.Link.Relation == NextRelation ? httpResponse.Link.Uri : null;
            return Parse(response, link, validate);
        }
        /// <summary>
        /// Parse a JSON response into <see cref="QueryResult"/> object
        /// that contains sequence of elements and the count of objects.
        /// This method abstracts out the differences between a raw array response and
        /// an inline count response.
        /// </summary>
        /// <param name="httpResponse">
        /// The HTTP response
        /// </param>
        /// <param name="serializerSettings">
        /// The serialization settings
        /// </param>
        /// <param name="validate">
        /// To throw if the content is null or empty
        /// </param>
        public static QueryResult Parse(MobileServiceHttpResponse httpResponse, JsonSerializerSettings serializerSettings, bool validate)
        {
            Debug.Assert(httpResponse != null);

            JToken response = httpResponse.Content.ParseToJToken(serializerSettings);

            Uri link = httpResponse.Link != null && httpResponse.Link.Relation == NextRelation ? httpResponse.Link.Uri : null;

            return(Parse(response, link, validate));
        }
Esempio n. 3
0
        /// <summary>
        /// Parse a JSON response into <see cref="QueryResult"/> object
        /// that contains sequence of elements and the count of objects.
        /// This method abstracts out the differences between a raw array response and
        /// an inline count response.
        /// </summary>
        /// <param name="httpResponse">
        /// The HTTP response
        /// </param>
        /// <param name="serializerSettings">
        /// The serialization settings
        /// </param>
        /// <param name="validate">
        /// To throw if the content is null or empty
        /// </param>
        public static QueryResult Parse(MobileServiceHttpResponse httpResponse, JsonSerializerSettings serializerSettings, bool validate)
        {
            Arguments.IsNotNull(httpResponse, nameof(httpResponse));

            JToken jtokenResponse = httpResponse.Content.ParseToJToken(serializerSettings);

            JToken response = null;
            Uri    link     = null;

            // the below was added to allow for the modified form for which the data is recieved from the Proxy
            if (jtokenResponse is JArray array && array.Count == 1)
            {
                jtokenResponse = array[0];
                response       = jtokenResponse["value"];
                if (jtokenResponse["@odata.nextLink"] is JToken nextLink && nextLink.Value <string>() is string nv)
                {
                    /*
                     * if (!string.IsNullOrWhiteSpace(context))
                     * {
                     *  var trunkIndex = context.IndexOf("/tables");
                     *  var trunk = context.Substring(0, trunkIndex);
                     *  var branchIndex = nv.IndexOf("/tables");
                     *  var branch = nv.Substring(branchIndex);
                     *  nv = trunk + branch;
                     * }
                     */
                    link = new Uri(nv);
                }
            }

            //Uri link = httpResponse.Link != null && httpResponse.Link.Relation == NextRelation ? httpResponse.Link.Uri : null;

            /*
             * string context = null;
             * if (jtokenResponse["@odata.context"] is JToken contextToken && contextToken.Value<string>() is string ctx)
             * {
             *  context = ctx;
             * }
             */

            return(Parse(response, link, validate));
        }