public async ValueTask <bool> MoveNextAsync() { this.cancellationToken.ThrowIfCancellationRequested(); if (!await this.crossPartitionEnumerator.MoveNextAsync()) { this.Current = default; return(false); } TryCatch <CrossPartitionPage <ReadFeedPage, ReadFeedState> > monadicCrossPartitionPage = this.crossPartitionEnumerator.Current; if (monadicCrossPartitionPage.Failed) { this.Current = TryCatch <ReadFeedPage> .FromException(monadicCrossPartitionPage.Exception); return(true); } CrossPartitionPage <ReadFeedPage, ReadFeedState> crossPartitionPage = monadicCrossPartitionPage.Result; ReadFeedPage backendPage = crossPartitionPage.Page; CrossPartitionState <ReadFeedState> crossPartitionState = crossPartitionPage.State; ReadFeedState state; if (crossPartitionState != null) { IReadOnlyList <(FeedRangeInternal, ReadFeedState)> rangesAndStates = crossPartitionState.Value; List <CosmosElement> changeFeedContinuationTokens = new List <CosmosElement>(); foreach ((FeedRangeInternal range, ReadFeedState readFeedState) in rangesAndStates) { this.cancellationToken.ThrowIfCancellationRequested(); ReadFeedContinuationToken readFeedContinuationToken = new ReadFeedContinuationToken( range, readFeedState); CosmosElement cosmosElementChangeFeedContinuationToken = ReadFeedContinuationToken.ToCosmosElement(readFeedContinuationToken); changeFeedContinuationTokens.Add(cosmosElementChangeFeedContinuationToken); } CosmosArray cosmosElementTokens = CosmosArray.Create(changeFeedContinuationTokens); state = new ReadFeedState(cosmosElementTokens); } else { state = null; } ReadFeedPage compositePage = new ReadFeedPage(backendPage.Content, backendPage.RequestCharge, backendPage.ActivityId, backendPage.Diagnostics, state); this.Current = TryCatch <ReadFeedPage> .FromResult(compositePage); return(true); }
public static CosmosElement ToCosmosElement(ReadFeedContinuationToken readFeedContinuationToken) { return(CosmosObject.Create(new Dictionary <string, CosmosElement>() { { PropertyNames.FeedRange, FeedRangeCosmosElementSerializer.ToCosmosElement(readFeedContinuationToken.Range) }, { PropertyNames.State, readFeedContinuationToken.State.ContinuationToken } })); }