public static async Task <TryCatch <IDocumentQueryExecutionComponent> > TryCreateAsync( int offsetCount, CosmosElement continuationToken, Func <CosmosElement, Task <TryCatch <IDocumentQueryExecutionComponent> > > tryCreateSourceAsync) { if (tryCreateSourceAsync == null) { throw new ArgumentNullException(nameof(tryCreateSourceAsync)); } OffsetContinuationToken offsetContinuationToken; if (continuationToken != null) { if (!OffsetContinuationToken.TryParse(continuationToken.ToString(), out offsetContinuationToken)) { return(TryCatch <IDocumentQueryExecutionComponent> .FromException( new MalformedContinuationTokenException($"Invalid {nameof(SkipDocumentQueryExecutionComponent)}: {continuationToken}."))); } } else { offsetContinuationToken = new OffsetContinuationToken(offsetCount, null); } if (offsetContinuationToken.Offset > offsetCount) { return(TryCatch <IDocumentQueryExecutionComponent> .FromException( new MalformedContinuationTokenException("offset count in continuation token can not be greater than the offsetcount in the query."))); } CosmosElement sourceToken; if (offsetContinuationToken.SourceToken != null) { TryCatch <CosmosElement> tryParse = CosmosElement.Monadic.Parse(offsetContinuationToken.SourceToken); if (tryParse.Failed) { return(TryCatch <IDocumentQueryExecutionComponent> .FromException( new MalformedContinuationTokenException( message : $"source token: '{offsetContinuationToken.SourceToken ?? "<null>"}' is not valid.", innerException : tryParse.Exception))); } sourceToken = tryParse.Result; } else { sourceToken = null; } return((await tryCreateSourceAsync(sourceToken)) .Try <IDocumentQueryExecutionComponent>((source) => new ClientSkipDocumentQueryExecutionComponent( source, offsetContinuationToken.Offset))); }
public static TryCatch <IQueryPipelineStage> MonadicCreate( int offsetCount, CosmosElement continuationToken, CancellationToken cancellationToken, MonadicCreatePipelineStage monadicCreatePipelineStage) { if (monadicCreatePipelineStage == null) { throw new ArgumentNullException(nameof(monadicCreatePipelineStage)); } OffsetContinuationToken offsetContinuationToken; if (continuationToken != null) { (bool parsed, OffsetContinuationToken parsedToken) = OffsetContinuationToken.TryParse(continuationToken); if (!parsed) { return(TryCatch <IQueryPipelineStage> .FromException( new MalformedContinuationTokenException($"Invalid {nameof(SkipQueryPipelineStage)}: {continuationToken}."))); } offsetContinuationToken = parsedToken; } else { offsetContinuationToken = new OffsetContinuationToken(offsetCount, null); } if (offsetContinuationToken.Offset > offsetCount) { return(TryCatch <IQueryPipelineStage> .FromException( new MalformedContinuationTokenException( "offset count in continuation token can not be greater than the offsetcount in the query."))); } TryCatch <IQueryPipelineStage> tryCreateSource = monadicCreatePipelineStage(offsetContinuationToken.SourceToken, cancellationToken); if (tryCreateSource.Failed) { return(tryCreateSource); } IQueryPipelineStage stage = new ComputeSkipQueryPipelineStage( tryCreateSource.Result, cancellationToken, offsetContinuationToken.Offset); return(TryCatch <IQueryPipelineStage> .FromResult(stage)); }
public static async Task <TryCatch <IDocumentQueryExecutionComponent> > TryCreateAsync( int offsetCount, CosmosElement continuationToken, Func <CosmosElement, Task <TryCatch <IDocumentQueryExecutionComponent> > > tryCreateSourceAsync) { if (tryCreateSourceAsync == null) { throw new ArgumentNullException(nameof(tryCreateSourceAsync)); } OffsetContinuationToken offsetContinuationToken; if (continuationToken != null) { (bool parsed, OffsetContinuationToken parsedToken) = OffsetContinuationToken.TryParse(continuationToken); if (!parsed) { return(TryCatch <IDocumentQueryExecutionComponent> .FromException( new MalformedContinuationTokenException($"Invalid {nameof(SkipDocumentQueryExecutionComponent)}: {continuationToken}."))); } offsetContinuationToken = parsedToken; } else { offsetContinuationToken = new OffsetContinuationToken(offsetCount, null); } if (offsetContinuationToken.Offset > offsetCount) { return(TryCatch <IDocumentQueryExecutionComponent> .FromException( new MalformedContinuationTokenException("offset count in continuation token can not be greater than the offsetcount in the query."))); } return((await tryCreateSourceAsync(offsetContinuationToken.SourceToken)) .Try <IDocumentQueryExecutionComponent>((source) => new ComputeSkipDocumentQueryExecutionComponent( source, offsetContinuationToken.Offset))); }
public static async Task <TryCatch <IDocumentQueryExecutionComponent> > TryCreateAsync( int offsetCount, string continuationToken, Func <string, Task <TryCatch <IDocumentQueryExecutionComponent> > > tryCreateSourceAsync) { if (tryCreateSourceAsync == null) { throw new ArgumentNullException(nameof(tryCreateSourceAsync)); } OffsetContinuationToken offsetContinuationToken; if (continuationToken != null) { if (!OffsetContinuationToken.TryParse(continuationToken, out offsetContinuationToken)) { return(TryCatch <IDocumentQueryExecutionComponent> .FromException( new Exception($"Invalid {nameof(SkipDocumentQueryExecutionComponent)}: {continuationToken}."))); } } else { offsetContinuationToken = new OffsetContinuationToken(offsetCount, null); } if (offsetContinuationToken.Offset > offsetCount) { return(TryCatch <IDocumentQueryExecutionComponent> .FromException( new Exception("offset count in continuation token can not be greater than the offsetcount in the query."))); } return((await tryCreateSourceAsync(offsetContinuationToken.SourceToken)) .Try <IDocumentQueryExecutionComponent>((source) => new SkipDocumentQueryExecutionComponent( source, offsetContinuationToken.Offset))); }
public static TryCatch <IQueryPipelineStage> MonadicCreate( int offsetCount, CosmosElement continuationToken, CancellationToken cancellationToken, MonadicCreatePipelineStage monadicCreatePipelineStage) { if (monadicCreatePipelineStage == null) { throw new ArgumentNullException(nameof(monadicCreatePipelineStage)); } OffsetContinuationToken offsetContinuationToken; if (continuationToken != null) { if (!OffsetContinuationToken.TryParse(continuationToken.ToString(), out offsetContinuationToken)) { return(TryCatch <IQueryPipelineStage> .FromException( new MalformedContinuationTokenException( $"Invalid {nameof(SkipQueryPipelineStage)}: {continuationToken}."))); } } else { offsetContinuationToken = new OffsetContinuationToken(offsetCount, null); } if (offsetContinuationToken.Offset > offsetCount) { return(TryCatch <IQueryPipelineStage> .FromException( new MalformedContinuationTokenException( "offset count in continuation token can not be greater than the offsetcount in the query."))); } CosmosElement sourceToken; if (offsetContinuationToken.SourceToken != null) { TryCatch <CosmosElement> tryParse = CosmosElement.Monadic.Parse(offsetContinuationToken.SourceToken); if (tryParse.Failed) { return(TryCatch <IQueryPipelineStage> .FromException( new MalformedContinuationTokenException( message : $"source token: '{offsetContinuationToken.SourceToken ?? "<null>"}' is not valid.", innerException : tryParse.Exception))); } sourceToken = tryParse.Result; } else { sourceToken = null; } TryCatch <IQueryPipelineStage> tryCreateSource = monadicCreatePipelineStage(sourceToken, cancellationToken); if (tryCreateSource.Failed) { return(tryCreateSource); } IQueryPipelineStage stage = new ClientSkipQueryPipelineStage( tryCreateSource.Result, cancellationToken, offsetContinuationToken.Offset); return(TryCatch <IQueryPipelineStage> .FromResult(stage)); }