Example #1
0
        public static TryCatch <CrossPartitionReadFeedAsyncEnumerator> MonadicCreate(
            IDocumentContainer documentContainer,
            QueryRequestOptions queryRequestOptions,
            string continuationToken,
            int pageSize,
            CancellationToken cancellationToken)
        {
            if (documentContainer == null)
            {
                throw new ArgumentNullException(nameof(documentContainer));
            }

            TryCatch <CrossPartitionState <ReadFeedState> > monadicCrossPartitionState = MonadicParseCrossPartitionState(continuationToken);

            if (monadicCrossPartitionState.Failed)
            {
                return(TryCatch <CrossPartitionReadFeedAsyncEnumerator> .FromException(monadicCrossPartitionState.Exception));
            }

            RntbdConstants.RntdbEnumerationDirection rntdbEnumerationDirection = RntbdConstants.RntdbEnumerationDirection.Forward;
            if ((queryRequestOptions?.Properties != null) && queryRequestOptions.Properties.TryGetValue(HttpConstants.HttpHeaders.EnumerationDirection, out object direction))
            {
                rntdbEnumerationDirection = (byte)direction == (byte)RntbdConstants.RntdbEnumerationDirection.Reverse ? RntbdConstants.RntdbEnumerationDirection.Reverse : RntbdConstants.RntdbEnumerationDirection.Forward;
            }

            IComparer <PartitionRangePageAsyncEnumerator <ReadFeedPage, ReadFeedState> > comparer;

            if (rntdbEnumerationDirection == RntbdConstants.RntdbEnumerationDirection.Forward)
            {
                comparer = PartitionRangePageAsyncEnumeratorComparerForward.Singleton;
            }
            else
            {
                comparer = PartitionRangePageAsyncEnumeratorComparerReverse.Singleton;
            }

            CrossPartitionRangePageAsyncEnumerator <ReadFeedPage, ReadFeedState> crossPartitionEnumerator = new CrossPartitionRangePageAsyncEnumerator <ReadFeedPage, ReadFeedState>(
                documentContainer,
                CrossPartitionReadFeedAsyncEnumerator.MakeCreateFunction(
                    documentContainer,
                    queryRequestOptions,
                    pageSize,
                    cancellationToken),
                comparer: comparer,
                maxConcurrency: default,
        public static CrossPartitionReadFeedAsyncEnumerator Create(
            IDocumentContainer documentContainer,
            CrossFeedRangeState <ReadFeedState> crossFeedRangeState,
            ReadFeedPaginationOptions readFeedPaginationOptions,
            CancellationToken cancellationToken)
        {
            if (documentContainer == null)
            {
                throw new ArgumentNullException(nameof(documentContainer));
            }

            if (crossFeedRangeState == null)
            {
                throw new ArgumentNullException(nameof(crossFeedRangeState));
            }

            readFeedPaginationOptions ??= ReadFeedPaginationOptions.Default;

            ReadFeedPaginationOptions.PaginationDirection paginationDirection = readFeedPaginationOptions.Direction.GetValueOrDefault(ReadFeedPaginationOptions.PaginationDirection.Forward);

            IComparer <PartitionRangePageAsyncEnumerator <ReadFeedPage, ReadFeedState> > comparer;

            if (paginationDirection == ReadFeedPaginationOptions.PaginationDirection.Forward)
            {
                comparer = PartitionRangePageAsyncEnumeratorComparerForward.Singleton;
            }
            else
            {
                comparer = PartitionRangePageAsyncEnumeratorComparerReverse.Singleton;
            }

            CrossPartitionRangePageAsyncEnumerator <ReadFeedPage, ReadFeedState> crossPartitionEnumerator = new CrossPartitionRangePageAsyncEnumerator <ReadFeedPage, ReadFeedState>(
                documentContainer,
                CrossPartitionReadFeedAsyncEnumerator.MakeCreateFunction(
                    documentContainer,
                    readFeedPaginationOptions,
                    cancellationToken),
                comparer: comparer,
                maxConcurrency: default,