Exemplo n.º 1
0
        public List <T> GetPage <T>(string TableName, int pageSize, bool sort)
        {
            TableName = TableName != null ? TableName : tableName;
            //List<ScanCondition> cond = new List<ScanCondition>();
            //cond.Add(new ScanCondition("Name", ScanOperator.IsNotNull));
            Table animeTable           = Table.LoadTable(dynamoDBClient, TableName);
            ScanOperationConfig config = new ScanOperationConfig();

            if (token != string.Empty)
            {
                config.Limit           = pageSize;
                config.Select          = SelectValues.AllAttributes;
                config.PaginationToken = token;
            }
            else
            {
                config = new ScanOperationConfig()
                {
                    Limit = pageSize, Select = SelectValues.AllAttributes
                };
            }
            var search = animeTable.Scan(config);
            var items  = search.GetNextSetAsync().Result;

            token = search.PaginationToken;
            List <T> result = _dynamoDBContext.FromDocuments <T>(items).ToList();

            return(result);
        }
Exemplo n.º 2
0
        public async Task <ICollection <ZipCode> > Search()
        {
            using (var dynamoDbContext = new DynamoDBContext(dbClientFactory.Value, new DynamoDBContextConfig {
                Conversion = DynamoDBEntryConversion.V2
            }))
            {
                var zipCodeTable = dynamoDbContext.GetTargetTable <ZipCode>();

                var randZip = rand.Next(10).ToString("D5");

                var keyExpr = new Expression();
                keyExpr.ExpressionStatement       = "Code = :v_code";
                keyExpr.ExpressionAttributeValues = new Dictionary <string, DynamoDBEntry>
                {
                    [":v_code"] = new Primitive(randZip)
                };

                var pageSize = 25;

                var query = zipCodeTable.Query(new QueryOperationConfig()
                {
                    IndexName       = "Code-index",
                    KeyExpression   = keyExpr,
                    PaginationToken = "{}",
                    Limit           = 5 // let's limit this to cause more GetNextSetAsync calls, this is artificial ...
                });

                var bucket = new List <ZipCode>(pageSize); // 25 is our bucket or page size. After we fill it, we are good...

                var i = 0;
                do
                {
                    i++;

                    var docs = await query.GetNextSetAsync();

                    IEnumerable <ZipCode> zipCodes = dynamoDbContext.FromDocuments <ZipCode>(docs);

                    bucket.AddRange(zipCodes);

                    if (query.PaginationToken == "{}" || query.IsDone)
                    {
                        break; // BREAK!!! there are no more records
                    }
                } while (bucket.Count < pageSize);

                return(bucket);
            }
        }
Exemplo n.º 3
0
        public async Task <IList <T> > Get(string paginationToken = null, CancellationToken cancellationToken = default)
        {
            var table   = DynamoDBContext.GetTargetTable <T>();
            var scanOps = new ScanOperationConfig();

            if (!string.IsNullOrEmpty(paginationToken))
            {
                scanOps.PaginationToken = paginationToken;
            }

            var             results = table.Scan(scanOps);
            List <Document> data    = await results.GetNextSetAsync(cancellationToken).ConfigureAwait(false);

            return(DynamoDBContext.FromDocuments <T>(data).ToList());
        }
Exemplo n.º 4
0
        private List <TEntity> GetElements(FilterRequest request, Table table, DynamoDBContext context, out Search search, out TEntity lastElement)
        {
            var requestElement = (FilterRequest)request.Clone();

            requestElement.GetTotal = false;
            requestElement.Limit    = 0;
            search = GetSearch(table, requestElement);

            List <TEntity> totalElements = new List <TEntity>();
            int            missingItem   = request.Limit; //Si quiero que traiga un máximo (limite) de 100 registros que cumplen con el filtro

            //y apenas lleva 30 registros, entonces faltan 70 registros (misingItems).

            do
            {
                List <Document> items           = search.GetNextSetAsync().GetAwaiter().GetResult();
                List <TEntity>  partialElements = context.FromDocuments <TEntity>(items).ToList();

                if (partialElements.Any())
                {
                    if (request.Limit == 0)
                    {
                        totalElements.AddRange(partialElements);
                    }
                    else
                    {
                        if (partialElements.Count <= missingItem)
                        {
                            totalElements.AddRange(partialElements);
                            missingItem -= partialElements.Count;
                        }
                        else
                        {
                            totalElements.AddRange(partialElements.Take(missingItem));
                        }
                    }
                }

                lastElement = partialElements.LastOrDefault();
            } while (!search.IsDone && (request.Limit == 0 || totalElements.Count < request.Limit));

            return(totalElements);
        }
Exemplo n.º 5
0
        public async Task <WriterOutputModel> All(string paginationToken = "")
        {
            // Get the Table ref from the Model
            var table = _context.GetTargetTable <Writer>();

            // If there's a PaginationToken
            // Use it in the Scan options
            // to fetch the next set
            var scanOps = new ScanOperationConfig();

            if (!string.IsNullOrEmpty(paginationToken))
            {
                scanOps.PaginationToken = paginationToken;
            }

            // returns the set of Document objects
            // for the supplied ScanOptions
            var             results = table.Scan(scanOps);
            List <Document> data    = await results.GetNextSetAsync();

            // transform the generic Document objects
            // into our Entity Model
            IEnumerable <Writer> Writers = _context.FromDocuments <Writer>(data);

            // Pass the PaginationToken
            // if available from the Results
            // along with the Result set
            return(new WriterOutputModel
            {
                PaginationToken = results.PaginationToken,
                Writers = Writers,
                ResultsType = ResultsType.List
            });

            /* The Non-Pagination approach */
            //var scanConditions = new List<ScanCondition>() { new ScanCondition("Id", ScanOperator.IsNotNull) };
            //var searchResults = _context.ScanAsync<Writer>(scanConditions, null);
            //return await searchResults.GetNextSetAsync();
        }
Exemplo n.º 6
0
        public async Task <QuoteCollection> GetQuotes(string paginationToken = "")
        {
            var table = _context.GetTargetTable <Quote>();

            var scanOps = new ScanOperationConfig();

            if (!string.IsNullOrEmpty(paginationToken))
            {
                scanOps.PaginationToken = paginationToken;
            }

            var             results = table.Scan(scanOps);
            List <Document> data    = await results.GetNextSetAsync();

            IEnumerable <Quote> quotes = _context.FromDocuments <Quote>(data);

            return(new QuoteCollection
            {
                PaginationToken = results.PaginationToken,
                Quotes = quotes
            });
        }