Exemple #1
0
        internal async Task <List <Document> > GetNextSetHelperAsync(CancellationToken cancellationToken)
        {
            List <Document> ret = new List <Document>();

            if (!IsDone)
            {
                switch (SearchMethod)
                {
                case SearchType.Scan:
                    ScanRequest scanReq = new ScanRequest
                    {
                        ExclusiveStartKey = NextKey,
                        Limit             = Limit,
                        TableName         = TableName,
                        AttributesToGet   = AttributesToGet,
                        ScanFilter        = Filter.ToConditions(SourceTable),
                        Select            = EnumMapper.Convert(Select),
                        ConsistentRead    = IsConsistentRead
                    };
                    if (!string.IsNullOrEmpty(this.IndexName))
                    {
                        scanReq.IndexName = this.IndexName;
                    }
                    if (this.FilterExpression != null && this.FilterExpression.IsSet)
                    {
                        this.FilterExpression.ApplyExpression(scanReq, SourceTable);
                    }
                    if (scanReq.ScanFilter != null && scanReq.ScanFilter.Count > 1)
                    {
                        scanReq.ConditionalOperator = EnumMapper.Convert(ConditionalOperator);
                    }
                    Common.ConvertAttributesToGetToProjectionExpression(scanReq);

                    if (this.TotalSegments != 0)
                    {
                        scanReq.TotalSegments = this.TotalSegments;
                        scanReq.Segment       = this.Segment;
                    }

                    SourceTable.AddRequestHandler(scanReq, isAsync: true);

                    var scanResult = await SourceTable.DDBClient.ScanAsync(scanReq, cancellationToken).ConfigureAwait(false);

                    foreach (var item in scanResult.Items)
                    {
                        Document doc = SourceTable.FromAttributeMap(item);
                        ret.Add(doc);
                        if (CollectResults)
                        {
                            Matches.Add(doc);
                        }
                    }
                    NextKey = scanResult.LastEvaluatedKey;
                    if (NextKey == null || NextKey.Count == 0)
                    {
                        IsDone = true;
                    }
                    return(ret);

                case SearchType.Query:
                    QueryRequest queryReq = new QueryRequest
                    {
                        TableName         = TableName,
                        ConsistentRead    = IsConsistentRead,
                        Select            = EnumMapper.Convert(Select),
                        ExclusiveStartKey = NextKey,
                        Limit             = Limit,
                        ScanIndexForward  = !IsBackwardSearch,
                        AttributesToGet   = AttributesToGet,
                        IndexName         = IndexName,
                    };

                    Expression.ApplyExpression(queryReq, SourceTable, KeyExpression, FilterExpression);

                    Dictionary <string, Condition> keyConditions, filterConditions;
                    SplitQueryFilter(Filter, SourceTable, queryReq.IndexName, out keyConditions, out filterConditions);
                    queryReq.KeyConditions = keyConditions;
                    queryReq.QueryFilter   = filterConditions;
                    Common.ConvertAttributesToGetToProjectionExpression(queryReq);

                    if (queryReq.QueryFilter != null && queryReq.QueryFilter.Count > 1)
                    {
                        queryReq.ConditionalOperator = EnumMapper.Convert(ConditionalOperator);
                    }

                    SourceTable.AddRequestHandler(queryReq, isAsync: true);

                    var queryResult = await SourceTable.DDBClient.QueryAsync(queryReq, cancellationToken).ConfigureAwait(false);

                    foreach (var item in queryResult.Items)
                    {
                        Document doc = SourceTable.FromAttributeMap(item);
                        ret.Add(doc);
                        if (CollectResults)
                        {
                            Matches.Add(doc);
                        }
                    }
                    NextKey = queryResult.LastEvaluatedKey;
                    if (NextKey == null || NextKey.Count == 0)
                    {
                        IsDone = true;
                    }
                    return(ret);

                default:
                    throw new InvalidOperationException("Unknown Search Method");
                }
            }

            return(ret);
        }