Exemple #1
0
        /// <summary>
        /// Creates a range from a previously obtained string representation.
        /// </summary>
        /// <param name="toStringValue">A string representation obtained from <see cref="ToJsonString" />.</param>
        /// <returns>A <see cref="FeedRange" />.</returns>
        /// <exception cref="ArgumentException">If the <paramref name="toStringValue"/> does not represent a valid value.</exception>
        public static FeedRange FromJsonString(string toStringValue)
        {
            if (!FeedRangeInternal.TryParse(toStringValue, out FeedRangeInternal parsedRange))
            {
                throw new ArgumentException(string.Format(ClientResources.FeedToken_UnknownFormat, toStringValue));
            }

            return(parsedRange);
        }
Exemple #2
0
        public override object ReadJson(
            JsonReader reader,
            Type objectType,
            object existingValue,
            JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null)
            {
                return(null);
            }

            if (reader.TokenType != JsonToken.StartObject)
            {
                throw new JsonReaderException();
            }

            JObject jObject = JObject.Load(reader);

            if (!jObject.TryGetValue(FeedRangeCompositeContinuationConverter.ContinuationPropertyName, out JToken continuationJToken))
            {
                throw new JsonReaderException();
            }

            string containerRid = null;

            if (jObject.TryGetValue(FeedRangeCompositeContinuationConverter.RidPropertyName, out JToken ridJToken))
            {
                containerRid = ridJToken.Value <string>();
            }

            List <CompositeContinuationToken> ranges = serializer.Deserialize <List <CompositeContinuationToken> >(continuationJToken.CreateReader());

            if (!FeedRangeInternal.TryParse(jObject, serializer, out FeedRangeInternal feedRangeInternal))
            {
                throw new JsonReaderException();
            }

            return(new FeedRangeCompositeContinuation(
                       containerRid: containerRid,
                       feedRange: feedRangeInternal,
                       deserializedTokens: ranges));
        }