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 TryCatch <FeedRangeState <ReadFeedState> > CreateFromCosmosElement(CosmosElement cosmosElement) { if (cosmosElement == null) { throw new ArgumentNullException(nameof(cosmosElement)); } if (!(cosmosElement is CosmosObject cosmosObject)) { return(TryCatch <FeedRangeState <ReadFeedState> > .FromException( new FormatException( $"Expected object for ChangeFeed Continuation: {cosmosElement}."))); } if (!cosmosObject.TryGetValue(PropertyNames.FeedRange, out CosmosElement feedRangeCosmosElement)) { return(TryCatch <FeedRangeState <ReadFeedState> > .FromException( new FormatException( $"Expected '{PropertyNames.FeedRange}' for '{nameof(FeedRangeState<ReadFeedState>)}': {cosmosElement}."))); } if (!cosmosObject.TryGetValue(PropertyNames.State, out CosmosElement stateCosmosElement)) { return(TryCatch <FeedRangeState <ReadFeedState> > .FromException( new FormatException( $"Expected '{PropertyNames.State}' for '{nameof(FeedRangeState<ReadFeedState>)}': {cosmosElement}."))); } TryCatch <FeedRangeInternal> monadicFeedRange = FeedRangeCosmosElementSerializer.MonadicCreateFromCosmosElement(feedRangeCosmosElement); if (monadicFeedRange.Failed) { return(TryCatch <FeedRangeState <ReadFeedState> > .FromException( new FormatException( $"Failed to parse '{PropertyNames.FeedRange}' for '{nameof(FeedRangeState<ReadFeedState>)}': {cosmosElement}.", innerException : monadicFeedRange.Exception))); } ReadFeedState readFeedState; if (stateCosmosElement is CosmosNull) { readFeedState = ReadFeedState.Beginning(); } else { readFeedState = ReadFeedState.Continuation(stateCosmosElement); } return(TryCatch <FeedRangeState <ReadFeedState> > .FromResult( new FeedRangeState <ReadFeedState>( monadicFeedRange.Result, readFeedState))); }
public ReadFeedContinuationToken(FeedRangeInternal feedRange, ReadFeedState readFeedState) { this.Range = feedRange ?? throw new ArgumentNullException(nameof(feedRange)); this.State = readFeedState ?? throw new ArgumentNullException(nameof(readFeedState)); }