예제 #1
0
 public static TryCatch <IQueryPipelineStage> MonadicCreateTopStage(
     int takeCount,
     CosmosElement requestContinuationToken,
     CancellationToken cancellationToken,
     MonadicCreatePipelineStage monadicCreatePipelineStage) => ComputeTakeQueryPipelineStage.MonadicCreate(
     takeCount,
     requestContinuationToken,
     cancellationToken,
     monadicCreatePipelineStage);
예제 #2
0
            private static TryCatch <IQueryPipelineStage> MonadicCreate(
                int takeCount,
                CosmosElement requestContinuationToken,
                CancellationToken cancellationToken,
                MonadicCreatePipelineStage monadicCreatePipelineStage)
            {
                if (takeCount < 0)
                {
                    throw new ArgumentException($"{nameof(takeCount)}: {takeCount} must be a non negative number.");
                }

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

                TakeContinuationToken takeContinuationToken;

                if (requestContinuationToken != null)
                {
                    if (!TakeContinuationToken.TryParse(requestContinuationToken, out takeContinuationToken))
                    {
                        return(TryCatch <IQueryPipelineStage> .FromException(
                                   new MalformedContinuationTokenException(
                                       $"Malformed {nameof(TakeContinuationToken)}: {requestContinuationToken}.")));
                    }
                }
                else
                {
                    takeContinuationToken = new TakeContinuationToken(takeCount, sourceToken: null);
                }

                if (takeContinuationToken.TakeCount > takeCount)
                {
                    return(TryCatch <IQueryPipelineStage> .FromException(
                               new MalformedContinuationTokenException(
                                   $"{nameof(TakeContinuationToken.TakeCount)} in {nameof(TakeContinuationToken)}: {requestContinuationToken}: {takeContinuationToken.TakeCount} can not be greater than the limit count in the query: {takeCount}.")));
                }

                TryCatch <IQueryPipelineStage> tryCreateSource = monadicCreatePipelineStage(takeContinuationToken.SourceToken, cancellationToken);

                if (tryCreateSource.Failed)
                {
                    return(tryCreateSource);
                }

                IQueryPipelineStage stage = new ComputeTakeQueryPipelineStage(
                    tryCreateSource.Result,
                    cancellationToken,
                    takeContinuationToken.TakeCount);

                return(TryCatch <IQueryPipelineStage> .FromResult(stage));
            }