public static TryCatch <ChangeFeedContinuationToken> MonadicConvertFromCosmosElement(CosmosElement cosmosElement) { if (cosmosElement == null) { throw new ArgumentNullException(nameof(cosmosElement)); } if (!(cosmosElement is CosmosObject cosmosObject)) { return(TryCatch <ChangeFeedContinuationToken> .FromException( new FormatException( $"Expected object for ChangeFeed Continuation: {cosmosElement}."))); } if (!cosmosObject.TryGetValue(PropertyNames.FeedRange, out CosmosElement feedRangeCosmosElement)) { return(TryCatch <ChangeFeedContinuationToken> .FromException( new FormatException( $"Expected '{PropertyNames.FeedRange}' for '{nameof(ChangeFeedContinuationToken)}': {cosmosElement}."))); } if (!cosmosObject.TryGetValue(PropertyNames.State, out CosmosElement stateCosmosElement)) { return(TryCatch <ChangeFeedContinuationToken> .FromException( new FormatException( $"Expected '{PropertyNames.State}' for '{nameof(ChangeFeedContinuationToken)}': {cosmosElement}."))); } TryCatch <FeedRangeInternal> monadicFeedRange = FeedRangeCosmosElementSerializer.MonadicCreateFromCosmosElement(feedRangeCosmosElement); if (monadicFeedRange.Failed) { return(TryCatch <ChangeFeedContinuationToken> .FromException( new FormatException( $"Failed to parse '{PropertyNames.FeedRange}' for '{nameof(ChangeFeedContinuationToken)}': {cosmosElement}.", innerException : monadicFeedRange.Exception))); } TryCatch <ChangeFeedState> monadicChangeFeedState = ChangeFeedStateCosmosElementSerializer.MonadicFromCosmosElement(stateCosmosElement); if (monadicChangeFeedState.Failed) { return(TryCatch <ChangeFeedContinuationToken> .FromException( new FormatException( $"Failed to parse '{PropertyNames.State}' for '{nameof(ChangeFeedContinuationToken)}': {cosmosElement}.", innerException : monadicChangeFeedState.Exception))); } return(TryCatch <ChangeFeedContinuationToken> .FromResult( new ChangeFeedContinuationToken( monadicFeedRange.Result, monadicChangeFeedState.Result))); }
public static CosmosElement ToCosmosElement(ChangeFeedContinuationToken changeFeedContinuationToken) { return(CosmosObject.Create(new Dictionary <string, CosmosElement>() { { PropertyNames.FeedRange, FeedRangeCosmosElementSerializer.ToCosmosElement(changeFeedContinuationToken.Range) }, { PropertyNames.State, ChangeFeedStateCosmosElementSerializer.ToCosmosElement(changeFeedContinuationToken.State) } })); }
public static CosmosElement ToCosmosElement(FeedRangeState <ChangeFeedState> feedRangeState) { return(CosmosObject.Create(new Dictionary <string, CosmosElement>() { { PropertyNames.FeedRange, FeedRangeCosmosElementSerializer.ToCosmosElement(feedRangeState.FeedRange) }, { PropertyNames.State, ChangeFeedStateCosmosElementSerializer.ToCosmosElement(feedRangeState.State) } })); }