public static TryCatch <SingleGroupAggregator> TryCreate( IReadOnlyDictionary <string, AggregateOperator?> aggregateAliasToAggregateType, IReadOnlyList <string> orderedAliases, string continuationToken) { CosmosObject aliasToContinuationToken; if (continuationToken != null) { if (!CosmosElement.TryParse(continuationToken, out aliasToContinuationToken)) { return(TryCatch <SingleGroupAggregator> .FromException( new MalformedContinuationTokenException( $"{nameof(SelectListAggregateValues)} continuation token is malformed: {continuationToken}."))); } } else { aliasToContinuationToken = null; } Dictionary <string, AggregateValue> groupingTable = new Dictionary <string, AggregateValue>(); foreach (KeyValuePair <string, AggregateOperator?> aliasToAggregate in aggregateAliasToAggregateType) { string alias = aliasToAggregate.Key; AggregateOperator?aggregateOperator = aliasToAggregate.Value; string aliasContinuationToken; if (aliasToContinuationToken != null) { if (!(aliasToContinuationToken[alias] is CosmosString parsedAliasContinuationToken)) { return(TryCatch <SingleGroupAggregator> .FromException( new MalformedContinuationTokenException( $"{nameof(SelectListAggregateValues)} continuation token is malformed: {continuationToken}."))); } aliasContinuationToken = parsedAliasContinuationToken.Value; } else { aliasContinuationToken = null; } TryCatch <AggregateValue> tryCreateAggregateValue = AggregateValue.TryCreate( aggregateOperator, aliasContinuationToken); if (tryCreateAggregateValue.Succeeded) { groupingTable[alias] = tryCreateAggregateValue.Result; } else { return(TryCatch <SingleGroupAggregator> .FromException(tryCreateAggregateValue.Exception)); } } return(TryCatch <SingleGroupAggregator> .FromResult(new SelectListAggregateValues(groupingTable, orderedAliases))); }
public static TryCatch <SingleGroupAggregator> TryCreate(AggregateOperator?aggregateOperator, CosmosElement continuationToken) { return(AggregateValue.TryCreate(aggregateOperator, continuationToken) .Try((aggregateValue) => (SingleGroupAggregator) new SelectValueAggregateValues(aggregateValue))); }