Esempio n. 1
0
            public static TryCatch <IQueryPipelineStage> MonadicCreate(
                CosmosElement requestContinuation,
                CancellationToken cancellationToken,
                MonadicCreatePipelineStage monadicCreatePipelineStage,
                IReadOnlyDictionary <string, AggregateOperator?> groupByAliasToAggregateType,
                IReadOnlyList <string> orderedAliases,
                bool hasSelectValue,
                int pageSize)
            {
                TryCatch <GroupingTable> tryCreateGroupingTable = GroupingTable.TryCreateFromContinuationToken(
                    groupByAliasToAggregateType,
                    orderedAliases,
                    hasSelectValue,
                    continuationToken: null);

                if (tryCreateGroupingTable.Failed)
                {
                    return(TryCatch <IQueryPipelineStage> .FromException(tryCreateGroupingTable.Exception));
                }

                TryCatch <IQueryPipelineStage> tryCreateSource = monadicCreatePipelineStage(requestContinuation, cancellationToken);

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

                IQueryPipelineStage stage = new ClientGroupByQueryPipelineStage(
                    tryCreateSource.Result,
                    cancellationToken,
                    tryCreateGroupingTable.Result,
                    pageSize);

                return(TryCatch <IQueryPipelineStage> .FromResult(stage));
            }
            public static async Task <TryCatch <IDocumentQueryExecutionComponent> > TryCreateAsync(
                CosmosElement requestContinuation,
                Func <CosmosElement, Task <TryCatch <IDocumentQueryExecutionComponent> > > tryCreateSource,
                IReadOnlyDictionary <string, AggregateOperator?> groupByAliasToAggregateType,
                IReadOnlyList <string> orderedAliases,
                bool hasSelectValue)
            {
                TryCatch <GroupingTable> tryCreateGroupingTable = GroupingTable.TryCreateFromContinuationToken(
                    groupByAliasToAggregateType,
                    orderedAliases,
                    hasSelectValue,
                    continuationToken: null);

                if (!tryCreateGroupingTable.Succeeded)
                {
                    return(TryCatch <IDocumentQueryExecutionComponent> .FromException(tryCreateGroupingTable.Exception));
                }

                return((await tryCreateSource(requestContinuation)).Try <IDocumentQueryExecutionComponent>(source =>
                {
                    return new ClientGroupByDocumentQueryExecutionComponent(
                        source,
                        tryCreateGroupingTable.Result);
                }));
            }
            public static async Task <TryCatch <IDocumentQueryExecutionComponent> > TryCreateAsync(
                string requestContinuation,
                Func <string, Task <TryCatch <IDocumentQueryExecutionComponent> > > tryCreateSourceAsync,
                IReadOnlyDictionary <string, AggregateOperator?> groupByAliasToAggregateType,
                IReadOnlyList <string> orderedAliases,
                bool hasSelectValue)
            {
                GroupByContinuationToken groupByContinuationToken;

                if (requestContinuation != null)
                {
                    if (!GroupByContinuationToken.TryParse(requestContinuation, out groupByContinuationToken))
                    {
                        return(TryCatch <IDocumentQueryExecutionComponent> .FromException(
                                   new MalformedContinuationTokenException($"Invalid {nameof(GroupByContinuationToken)}: '{requestContinuation}'")));
                    }
                }
                else
                {
                    groupByContinuationToken = new GroupByContinuationToken(
                        groupingTableContinuationToken: null,
                        sourceContinuationToken: null);
                }

                TryCatch <IDocumentQueryExecutionComponent> tryCreateSource;

                if (groupByContinuationToken.SourceContinuationToken == ComputeGroupByDocumentQueryExecutionComponent.DoneReadingGroupingsContinuationToken)
                {
                    tryCreateSource = TryCatch <IDocumentQueryExecutionComponent> .FromResult(DoneDocumentQueryExecutionComponent.Value);
                }
                else
                {
                    tryCreateSource = await tryCreateSourceAsync(groupByContinuationToken.SourceContinuationToken);
                }

                if (!tryCreateSource.Succeeded)
                {
                    return(TryCatch <IDocumentQueryExecutionComponent> .FromException(tryCreateSource.Exception));
                }

                TryCatch <GroupingTable> tryCreateGroupingTable = GroupingTable.TryCreateFromContinuationToken(
                    groupByAliasToAggregateType,
                    orderedAliases,
                    hasSelectValue,
                    groupByContinuationToken.GroupingTableContinuationToken);

                if (!tryCreateGroupingTable.Succeeded)
                {
                    return(TryCatch <IDocumentQueryExecutionComponent> .FromException(tryCreateGroupingTable.Exception));
                }

                return(TryCatch <IDocumentQueryExecutionComponent> .FromResult(
                           new ComputeGroupByDocumentQueryExecutionComponent(
                               tryCreateSource.Result,
                               tryCreateGroupingTable.Result)));
            }