private async Task <CosmosClientQueryResult <Activity> > FetchPageOfActivities(Expression <Func <Activity, bool> > selection, string continuationToken)
        {
            var collectionUri = GetCollectionUri(CollectionName);

            var options = new FeedOptions
            {
                MaxItemCount        = 1000,
                RequestContinuation = continuationToken
            };

            var query = _client.Value
                        .CreateDocumentQuery <Activity>(collectionUri, options)
                        .Where(selection)
                        .OrderBy(activity => activity.At)
                        .AsDocumentQuery();

            Stopwatch sw = new Stopwatch();

            sw.Start();
            var page = await query.ExecuteNextAsync <Activity>();

            sw.Stop();
            var pageResult = new CosmosClientQueryResult <Activity>(
                query.HasMoreResults ? page.ResponseContinuation : null,
                page.ToArray())
            {
                Cost = new OperationCost(query.ToString(), page.RequestCharge, sw.ElapsedTicks)
            };

            return(pageResult);
        }
        private async Task FetchAllMatchingActivities(Expression <Func <Activity, bool> > selection, GroupOperationCost groupOperationCost)
        {
            CosmosClientQueryResult <Activity> page = null;

            do
            {
                page = await FetchPageOfActivities(selection, page?.ContinuationToken);

                groupOperationCost.StepCosts.Add(page.Cost);
            }while (page.ContinuationToken != null);
        }