async Task <bool> SetCurrent() { while (readerState.ReadNextProperty(jsonTextReader)) { readerState.ReadNextPropertyValue(jsonTextReader); CursorResult.SetFromJsonTextReader(readerState.PropertyName, readerState.Token, readerState.Value); } if (jsonTextReader.TokenType == JsonToken.EndObject) { new BaseResultAnalyzer(db).ThrowIfNeeded(CursorResult); if (db.Setting.ThrowForServerErrors == false && CursorResult.HasError()) { return(false); } } if (readerState.ReadNextArrayValue(jsonTextReader)) { var documentSerializer = new DocumentSerializer(db); if (db.Setting.DisableChangeTracking == true || jsonTextReader.TokenType != JsonToken.StartObject) { Current = documentSerializer.Deserialize <T>(jsonTextReader); } else { JObject jObject = null; Current = documentSerializer.DeserializeSingleResult <T>(jsonTextReader, out jObject); db.ChangeTracker.TrackChanges(Current, jObject); } return(true); } else { while (readerState.ReadNextProperty(jsonTextReader)) { readerState.ReadNextPropertyValue(jsonTextReader); CursorResult.SetFromJsonTextReader(readerState.PropertyName, readerState.Token, readerState.Value); } if (CursorResult.HasMore) { Dispose(); await MakeNextRequest().ConfigureAwait(false); readerState.InitiateRead(jsonTextReader); return(await SetCurrent().ConfigureAwait(false)); } else { Dispose(); return(false); } } }
public List <T> ParseBatchResult <T>(JsonTextReader jsonTextReader, out BaseResult baseResult) { var readerState = new ReaderState(); baseResult = new BaseResult(); var result = new List <T>(); jsonTextReader.Read(); while (readerState.ReadNextProperty(jsonTextReader)) { readerState.ReadNextPropertyValue(jsonTextReader); baseResult.SetFromJsonTextReader(readerState.PropertyName, readerState.Token, readerState.Value); } if (jsonTextReader.TokenType == JsonToken.EndObject) { // no need to check for base result //new BaseResultAnalyzer(db).ThrowIfNeeded(baseResult); return(result); } while (readerState.ReadNextArrayValue(jsonTextReader)) { JObject jObject = null; var document = ParseSingleResult <T>(jsonTextReader, out jObject); db.ChangeTracker.TrackChanges(document, jObject); result.Add(document); } while (readerState.ReadNextProperty(jsonTextReader)) { readerState.ReadNextPropertyValue(jsonTextReader); baseResult.SetFromJsonTextReader(readerState.PropertyName, readerState.Token, readerState.Value); } return(result); }