Beispiel #1
0
        public async Task <IEnumerable <Cart> > GetAll()
        {
            var table = Table.LoadTable(dbClient, "carts_id_cid");

            var scanFilter = new ScanFilter();

            var scanOperation = new ScanOperationConfig()
            {
                Filter = scanFilter
            };

            var result = table.Scan(scanOperation);

            var carts = new List <Cart>();

            while (!result.IsDone)
            {
                var querySet = await result.GetNextSetAsync();

                foreach (var document in querySet)
                {
                    Cart cart = CartFromDocument(document);
                    carts.Add(cart);
                }
            }

            return(carts);
        }
Beispiel #2
0
            public async Task <IEnumerable <TEntity> > ExecuteAsync()
            {
                var scan = new ScanOperationConfig();

                foreach (var filterAction in this.collection)
                {
                    filterAction(scan.Filter);
                }

                if (this.limit != null)
                {
                    scan.Limit = this.limit.Value;
                }

                if (this.indexName != null)
                {
                    scan.IndexName = this.indexName;
                }

                if (this.propertiesToGet != null)
                {
                    scan.AttributesToGet = this.propertiesToGet.ToList();
                    scan.Select          = SelectValues.SpecificAttributes;
                }

                var search = this.context.FromScanAsync <TEntity>(scan);

                return(await search.GetRemainingAsync());
            }
        public async Task <List <Author> > GetAuthors()
        {
            ScanOperationConfig scanConfig = new ScanOperationConfig
            {
                Select          = SelectValues.SpecificAttributes,
                AttributesToGet = new List <string> {
                    "id", "name"
                },
                ConsistentRead = true
            };

            var search = authorsTable.Scan(scanConfig);

            // get all async
            var searchResult = await search.GetRemainingAsync();

            var result = new List <Author>();

            foreach (Document document in searchResult)
            {
                Author author = new Author
                {
                    id   = document["id"],
                    name = document["name"]
                };
                result.Add(author);
            }

            return(result);
        }
        private ScanOperationConfig GetScanOperationConfig(List <ScanFilterCondition> scanFilterConditions, bool consistentRead = true, List <string> attributesToGet = null)
        {
            ScanFilter scanFilter = new ScanFilter();

            foreach (var scanFilterCondition in scanFilterConditions)
            {
                if (scanFilterCondition.Type == ScanFilterConditionType.one)
                {
                    scanFilter.AddCondition(scanFilterCondition.AttributeName, scanFilterCondition.Condition);
                }
                if (scanFilterCondition.Type == ScanFilterConditionType.two)
                {
                    scanFilter.AddCondition(scanFilterCondition.AttributeName, scanFilterCondition.ScanOperator, scanFilterCondition.AttributeValues);
                }
                if (scanFilterCondition.Type == ScanFilterConditionType.three)
                {
                    scanFilter.AddCondition(scanFilterCondition.AttributeName, scanFilterCondition.ScanOperator, scanFilterCondition.DynamoDBEntry);
                }
            }

            ScanOperationConfig scanOperationConfig = new ScanOperationConfig()
            {
                ConsistentRead = consistentRead,
                Filter         = scanFilter
            };

            if (attributesToGet != null)
            {
                scanOperationConfig.AttributesToGet = attributesToGet;
            }

            return(scanOperationConfig);
        }
        public async Task <List <Comment> > GetComments()
        {
            ScanOperationConfig scanConfig = new ScanOperationConfig
            {
                Select          = SelectValues.SpecificAttributes,
                AttributesToGet = new List <string> {
                    "id", "content", "author"
                },
                ConsistentRead = true
            };

            var search = commentsTable.Scan(scanConfig);

            // get all async
            var searchResult = await search.GetRemainingAsync();

            var result = new List <Comment>();

            foreach (Document document in searchResult)
            {
                Comment comment = new Comment
                {
                    id      = document["id"],
                    content = document["content"],
                    author  = document["author"]
                };
                result.Add(comment);
            }

            return(result);
        }
Beispiel #6
0
        public async static Task <string> QueryByClientGuid(string key)
        {
            // Function  returns a client "secret" using the ClientGuid as a search
            Table      QTable     = Table.LoadTable(dbClient, clientTableName);
            ScanFilter scanFilter = new ScanFilter();

            scanFilter.AddCondition("ClientGuid", ScanOperator.Equal, key);
            ScanOperationConfig config = new ScanOperationConfig()
            {
                Filter    = scanFilter,
                IndexName = "ClientGuid-index"
            };

            Search search = QTable.Scan(scanFilter);

            List <Document> allItems = await search.GetRemainingAsync();

            string secret = null;

            foreach (Document doc in allItems)
            {
                foreach (string itemkey in doc.Keys)
                {
                    DynamoDBEntry dbEntry = doc[itemkey];
                    string        val     = dbEntry.ToString();
                    if (itemkey == "secret")
                    {
                        secret = val;
                    }
                }
            }
            return(secret);
        }
        public async Task <IEnumerable <Product> > GetAll()
        {
            var table = Table.LoadTable(dbClient, "products_id_sku");

            var scanFilter = new ScanFilter();

            var scanOperation = new ScanOperationConfig()
            {
                Filter = scanFilter
            };

            var result = table.Scan(scanOperation);

            var products = new List <Product>();

            while (!result.IsDone)
            {
                var querySet = await result.GetNextSetAsync();

                foreach (var document in querySet)
                {
                    Product product = ProductFromDocument(document);
                    products.Add(product);
                }
            }

            return(products);
        }
Beispiel #8
0
        /// <summary>
        /// A utility method for cleaning up expired sessions that IIS failed to delete. The method performs a scan on the table
        /// with a condition that the expiration date is in the past and calls delete on all the keys returned. Scans can be costly on performance
        /// so use this method sparingly like a nightly or weekly clean job.
        /// </summary>
        /// <param name="dbClient">The AmazonDynamoDB client used to find a delete expired sessions.</param>
        /// <param name="tableName">The table to search.</param>
        public static void DeleteExpiredSessions(IAmazonDynamoDB dbClient, string tableName)
        {
            Table table = Table.LoadTable(dbClient, tableName, Table.DynamoDBConsumer.SessionStateProvider, DynamoDBEntryConversion.V1);


            ScanFilter filter = new ScanFilter();

            filter.AddCondition(ATTRIBUTE_EXPIRES, ScanOperator.LessThan, DateTime.Now);

            ScanOperationConfig config = new ScanOperationConfig();

            config.AttributesToGet = new List <string> {
                ATTRIBUTE_SESSION_ID
            };
            config.Select = SelectValues.SpecificAttributes;
            config.Filter = filter;

            DocumentBatchWrite batchWrite = table.CreateBatchWrite();
            Search             search     = table.Scan(config);

            do
            {
                List <Document> page = search.GetNextSet();
                foreach (var document in page)
                {
                    batchWrite.AddItemToDelete(document);
                }
            } while (!search.IsDone);

            batchWrite.Execute();
        }
Beispiel #9
0
        private void AddScanFilterCondition(string name, ScanOperator operation, IEnumerable <object> values)
        {
            Primitive primitiveValue = null;

            DynamoDBEntry[] primitiveValues = null;
            if (values != null)
            {
                var valuesArray = values.ToArray();
                if (valuesArray.Length == 1)
                {
                    primitiveValue = converter.ToPrimative(valuesArray.First());
                }
                else
                {
                    primitiveValues = valuesArray.Select(v => (DynamoDBEntry)converter.ToPrimative(v)).ToArray();
                }
            }

            if (queryOperation == null && scanOperation == null)
            {
                scanOperation = new ScanOperationConfig();

                if (indexName != null)
                {
                    scanOperation.IndexName = indexName;
                }
                scanOperation.Filter = new ScanFilter();
            }

            if (queryOperation != null)
            {
                if (primitiveValue != null)
                {
                    queryOperation.Filter.AddCondition(name, operation, primitiveValue);
                }
                else if (primitiveValues != null)
                {
                    queryOperation.Filter.AddCondition(name, operation, primitiveValues);
                }
                else
                {
                    queryOperation.Filter.AddCondition(name, operation, new DynamoDBEntry[] {});
                }
            }
            else
            {
                if (primitiveValue != null)
                {
                    scanOperation.Filter.AddCondition(name, operation, primitiveValue);
                }
                else if (primitiveValues != null)
                {
                    scanOperation.Filter.AddCondition(name, operation, primitiveValues);
                }
                else
                {
                    scanOperation.Filter.AddCondition(name, operation, new DynamoDBEntry[] {});
                }
            }
        }
        public async Task <List <Document> > getData(DateTime startDateTime, DateTime endDateTime)
        {
            AttributeValue startAttr = new AttributeValue();

            startAttr.N = startDateTime.ToString("yyyyMMddHHmmss");
            Condition startCon = new Condition();

            startCon.ComparisonOperator = ComparisonOperator.GE;
            startCon.AttributeValueList.Add(startAttr);

            AttributeValue endAttr = new AttributeValue();

            endAttr.N = endDateTime.ToString("yyyyMMddHHmmss");
            Condition endCon = new Condition();

            endCon.ComparisonOperator = ComparisonOperator.GE;
            endCon.AttributeValueList.Add(endAttr);

            var scanFilter = new ScanFilter();

            scanFilter.AddCondition("timestamp", startCon);
            scanFilter.AddCondition("timestamp", endCon);

            var config = new ScanOperationConfig();

            config.ConsistentRead = true;
            config.Filter         = scanFilter;
            var search = table.Scan(config);
            var list   = await search.GetNextSetAsync();

            list.Reverse();
            return(list);
        }
Beispiel #11
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);
        }
Beispiel #12
0
        private async Task <List <Product> > GetTrendingProductsAsync(string attributeName, CancellationToken cancellationToken)
        {
            var scanOperation = new ScanOperationConfig
            {
                Filter = new ScanFilter()
            };

            var scn = new Condition
            {
                AttributeValueList = new List <AttributeValue>
                {
                    new AttributeValue
                    {
                        N = "0",
                    }
                },
                ComparisonOperator = ComparisonOperator.GT
            };

            scanOperation.Filter.AddCondition(attributeName, scn);

            var scanResult = this.repository.FromScanAsync <Product>(scanOperation);

            return(await this.GetAsyncSearchResult(scanResult, cancellationToken));
        }
Beispiel #13
0
        public async Task List()
        {
            Console.WriteLine("Entering List");
            var description = await DescribeTable();

            Console.WriteLine($"Table name: {description.TableName}" + "  " + $"Table status: {description.TableStatus}");

            Table QTable = Table.LoadTable(client, ClientTableName);
            //get the RequestQ items for the ClientGuid
            ScanFilter scanFilter = new ScanFilter();

            scanFilter.AddCondition("ClientID", ScanOperator.GreaterThan, " ");
            ScanOperationConfig config = new ScanOperationConfig()
            {
                Filter = scanFilter,
            };

            Search          search   = QTable.Scan(scanFilter);
            List <Document> allItems = await search.GetRemainingAsync();

            Console.WriteLine("================================================================================");
            foreach (Document doc in allItems)
            {
                foreach (string itemkey in doc.Keys)
                {
                    DynamoDBEntry dbEntry = doc[itemkey];

                    if (itemkey == "ClientID")
                    {
                        string val = dbEntry.AsString(); Console.WriteLine("ClientID:         " + val);
                    }
                    if (itemkey == "ClientGuid")
                    {
                        string val = dbEntry.AsString(); Console.WriteLine("ClientGuid:       " + val);
                    }
                    if (itemkey == "ActiveStatus")
                    {
                        bool val = dbEntry.AsBoolean(); Console.WriteLine("ActiveStatus:     " + val);
                    }
                    if (itemkey == "secret")
                    {
                        string val = dbEntry.AsString(); Console.WriteLine("secret:           " + val);
                    }
                    if (itemkey == "amazn_link_time")
                    {
                        string val = dbEntry.AsString(); Console.WriteLine("amazn_link_time:  " + val);
                    }
                    if (itemkey == "Appliance")
                    {
                        int i = 0; foreach (string device in dbEntry.AsListOfString())
                        {
                            Console.WriteLine("Appliance(" + i + "):     " + device); i++;
                        }
                    }
                }// end foreach key

                Console.WriteLine("================================================================================");
            }
            return;
        }
        /// <summary>
        /// Executes a Scan operation against DynamoDB, finding items
        /// that match the specified conditions.
        /// </summary>
        /// <typeparam name="T">Type of object.</typeparam>
        /// <param name="scanConfig">Scan request object.</param>
        /// <param name="operationConfig">Config object which can be used to override the table used.</param>
        /// <returns>Lazy-loaded collection of results.</returns>
        public IEnumerable<T> FromScan<T>(ScanOperationConfig scanConfig, DynamoDBOperationConfig operationConfig)
        {
            if (scanConfig == null) throw new ArgumentNullException("scanConfig");

            var scan = ConvertFromScan<T>(scanConfig, operationConfig);
            return FromSearch<T>(scan);
        }
        private Search ConvertFromScan <T>(ScanOperationConfig scanConfig, DynamoDBOperationConfig operationConfig)
        {
            Table  table  = GetTargetTableInternal <T>(operationConfig);
            Search search = table.Scan(scanConfig);

            return(search);
        }
        /// <summary>
        /// Finds any items in the ProductCatalog table using a DynamoDB
        /// conguration object.
        /// </summary>
        /// <param name="client">An initialized DynamoDB client object.</param>
        /// <param name="productCatalogTable">A DynamoDB table object.</param>
        public static async Task FindProductsWithNegativePriceWithConfig(
            IAmazonDynamoDB client,
            Table productCatalogTable)
        {
            // Assume there is a price error. So we scan to find items priced < 0.
            ScanFilter scanFilter = new ScanFilter();

            scanFilter.AddCondition("Price", ScanOperator.LessThan, 0);

            ScanOperationConfig config = new ScanOperationConfig()
            {
                Filter          = scanFilter,
                Select          = SelectValues.SpecificAttributes,
                AttributesToGet = new List <string> {
                    "Title", "Id"
                },
            };

            Search search = productCatalogTable.Scan(config);

            do
            {
                var documentList = await search.GetNextSetAsync();

                Console.WriteLine("\nFindProductsWithNegativePriceWithConfig: printing ............");

                foreach (var document in documentList)
                {
                    PrintDocument(document);
                }
            } while (!search.IsDone);
        }
        /// <summary>
        /// A utility method for cleaning up expired sessions that IIS failed to delete.  The method performs a scan on the table
        /// with a condition that the expiration date is in the past and calls delete on all the keys returned.  Scans can be costly on performance
        /// so use this method sparingly like a nightly or weekly clean job.
        /// </summary>
        /// <param name="dbClient">The AmazonDynamoDB client used to find a delete expired sessions.</param>
        /// <param name="tableName">The table to search.</param>
        public static void DeleteExpiredSessions(AmazonDynamoDB dbClient, string tableName)
        {
            Table table = Table.LoadTable(dbClient, tableName, Table.DynamoDBConsumer.SessionStateProvider);


            ScanFilter filter = new ScanFilter();

            filter.AddCondition(ATTRIBUTE_EXPIRES, ScanOperator.LessThan, DateTime.Now);

            ScanOperationConfig config = new ScanOperationConfig();

            config.AttributesToGet = new List <string>();
            config.AttributesToGet.Add(ATTRIBUTE_SESSION_ID);
            config.Filter = filter;

            Search search = table.Scan(config);

            do
            {
                List <Document> page = search.GetNextSet();
                foreach (var document in page)
                {
                    table.DeleteItem(document);
                }
            } while (!search.IsDone);
        }
Beispiel #18
0
        public async Task <IList <T> > Get <T>(string tableName, QueryFilter queryFilter, string paginationToken = null, bool consistentRead = true, CancellationToken cancellationToken = default) where T : class
        {
            var table   = Table.LoadTable(AmazonDynamoDBClient, tableName);
            var scanOps = new ScanOperationConfig();

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

            QueryOperationConfig config = new QueryOperationConfig()
            {
                Filter          = queryFilter,
                Select          = SelectValues.SpecificAttributes,
                AttributesToGet = new List <string> {
                    AttributeValue
                },
                ConsistentRead = consistentRead
            };

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

            return(TransformData <T>(data));
        }
Beispiel #19
0
        public async Task <IActionResult> Get(string firstName, string lastName, string secondLastName, string curp)
        {
            var credentials = new BasicAWSCredentials(AWSAccessKeyId, AWSSecretAccessKey);
            var client      = new AmazonDynamoDBClient(credentials, RegionEndpoint.USWest2);

            ScanFilter scanFilter = new ScanFilter();

            scanFilter.AddCondition("FirstName", ScanOperator.Equal, firstName);
            scanFilter.AddCondition("LastName", ScanOperator.Equal, lastName);
            scanFilter.AddCondition("SecondLastName", ScanOperator.Equal, secondLastName);
            scanFilter.AddCondition("CURP", ScanOperator.Equal, curp);
            ScanOperationConfig soc = new ScanOperationConfig()
            {
                // AttributesToGet = new List { "Id", "Title", "ISBN", "Price" },
                Filter = scanFilter
            };
            DynamoDBContext            context      = new DynamoDBContext(client);
            AsyncSearch <EmployeesPTU> search       = context.FromScanAsync <EmployeesPTU>(soc, null);
            List <EmployeesPTU>        documentList = new List <EmployeesPTU>();

            do
            {
                documentList = await search.GetNextSetAsync(default(System.Threading.CancellationToken));
            } while (!search.IsDone);

            return(Ok(documentList));
        }
Beispiel #20
0
        public async Task <IActionResult> GetAsync()
        {
            try
            {   // COGNITO SERVICE
                //AWSCredentials credentials = new CognitoAWSCredentials(cognitoID,RegionEndpoint.USEast1);
                //var client = new AmazonDynamoDBClient(credentials,RegionEndpoint.USEast1);

                // IAM SERVICE - Local
                //var credentials = new BasicAWSCredentials(AWSAccessKeyId, AWSSecretAccessKey);
                //var client = new AmazonDynamoDBClient(credentials, RegionEndpoint.USEast1);

                // This approach works when you are depending on a role
                var client = new AmazonDynamoDBClient(RegionEndpoint.USEast1);

                ScanFilter          scanFilter = new ScanFilter();
                ScanOperationConfig soc        = new ScanOperationConfig()
                {
                    Filter = scanFilter
                };
                DynamoDBContext    context      = new DynamoDBContext(client);
                AsyncSearch <lreb> search       = context.FromScanAsync <lreb>(soc, null);
                List <lreb>        documentList = new List <lreb>();
                do
                {
                    documentList = await search.GetNextSetAsync(default(System.Threading.CancellationToken));
                } while (!search.IsDone);

                return(Ok(documentList));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e));
            }
        }
Beispiel #21
0
        public List <Soup> GetSoupsFromPastDays(int days)
        {
            Table ThreadTable = Table.LoadTable(client, tableName);

            ScanFilter scanFilter = new ScanFilter();

            scanFilter.AddCondition("UpdTimeStamp", ScanOperator.GreaterThan, DateTime.UtcNow.AddDays(-days).ToString(AWSSDKUtils.ISO8601DateFormat));


            ScanOperationConfig config = new ScanOperationConfig()
            {
                Filter = scanFilter,
            };

            Search search = ThreadTable.Scan(config);

            List <Document> documentList = new List <Document>();

            do
            {
                var nextSetTask = search.GetNextSetAsync();
                nextSetTask.Wait();

                var nextSet = nextSetTask.Result;
                documentList.AddRange(nextSet);
            } while (!search.IsDone);

            var soups = documentList.Select(arg => JsonConvert.DeserializeObject <Soup>(arg.ToJson())).OrderBy(arg => arg.UpdTimeStamp).ToList();

            return(soups);
        }
Beispiel #22
0
        private ContextSearch ConvertFromScan <T>(ScanOperationConfig scanConfig, DynamoDBOperationConfig operationConfig)
        {
            DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig(operationConfig, Config);
            Table  table  = GetTargetTableInternal <T>(operationConfig);
            Search search = table.Scan(scanConfig);

            return(new ContextSearch(search, flatConfig));
        }
        public async Task <List <string> > GetAllPatientNamesAsync()
        {
            List <string> patientNameList = new List <string>();

            try
            {
                var dynamoConfig = new AmazonDynamoDBConfig();
                dynamoConfig.RegionEndpoint = Amazon.RegionEndpoint.USWest2;
                using (var dynamoClient = new AmazonDynamoDBClient(dynamoConfig))
                {
                    var                 table      = Table.LoadTable(dynamoClient, "Patients");
                    ScanFilter          scanFilter = new ScanFilter();
                    ScanOperationConfig scanConfig = new ScanOperationConfig()
                    {
                        Select          = SelectValues.SpecificAttributes,
                        AttributesToGet = new List <string> {
                            "PatientName"
                        },
                        Filter = scanFilter
                    };
                    Search          search       = table.Scan(scanConfig);
                    List <Document> documentList = new List <Document>();
                    do
                    {
                        documentList = await search.GetNextSetAsync(default(CancellationToken));

                        foreach (var document in documentList)
                        {
                            var patientName = document["PatientName"];
                            patientNameList.Add(patientName);
                        }
                    } while(!search.IsDone);
                }
            }
            catch (AmazonDynamoDBException dEx)
            {
                _log.LogError("Amazon DynamoDB Exception: " + dEx.Message);
                throw new DataAccessException("An Error Occured While Retrieving Patient Names From Database");
            }
            catch (AmazonServiceException sEx)
            {
                _log.LogError("Amazon Service Exception: " + sEx.Message);
                throw new DataAccessException("An Error Occured While Retrieving Patient Names From Database");
            }
            catch (AmazonClientException cEx)
            {
                _log.LogError("Amazon Client Exception: " + cEx.Message);
                throw new DataAccessException("An Error Occured While Retrieving Patient Names From Database");
            }
            catch (Exception uEx)
            {
                _log.LogError("Unhandled Exception:  " + uEx.Message);
                throw new DataAccessException("An Unknown Error Occured");
            }
            return(patientNameList);
        }
Beispiel #24
0
        public async Task <IEnumerable <T> > GetAsync()
        {
            var scan = new ScanOperationConfig
            {
                Limit  = 1,
                Filter = null
            };

            return(await base.FromScanAsync <T>(scan, _config).GetRemainingAsync());
        }
        protected async Task <List <TEntity> > GetByFiltersAsync(IEnumerable <ScanCondition> filter, int limit)
        {
            ScanOperationConfig scanConfig = new ScanOperationConfig()
            {
                Limit = limit
            };

            _config.QueryFilter = filter != null?filter.ToList() : null;

            return(await _context.FromScanAsync <TEntity>(scanConfig, _config).GetNextSetAsync());
        }
        public async Task <List <Coche> > GetCochesAsync()
        {
            var             table       = this.context.GetTargetTable <Coche>();
            var             scanOptions = new ScanOperationConfig();
            var             results     = table.Scan(scanOptions);
            List <Document> data        = await results.GetNextSetAsync();

            IEnumerable <Coche> coches = this.context.FromDocuments <Coche>(data);

            return(coches.ToList());
        }
Beispiel #27
0
        private async Task <IEnumerable <Order> > FetchOrdersAsync()
        {
            var cacheHit = true;
            var sw       = new Stopwatch();

            sw.Start();

            if (!Cache.TryGetValue(ORDERS_CACHE_KEY, out List <Order> orders))
            {
                await cacheSyncRoot.WaitAsync();

                try
                {
                    orders = await Cache.GetOrCreateAsync(ORDERS_CACHE_KEY, async entry =>
                    {
                        cacheHit = false;

                        Table table = Table.LoadTable(Client, TABLE_NAME);

                        var config = new ScanOperationConfig()
                        {
                            Select         = SelectValues.AllAttributes,
                            ConsistentRead = true,
                        };

                        var search = table.Scan(config);

                        var orderDocuments = new List <Document>();

                        do
                        {
                            orderDocuments.AddRange(await search.GetNextSetAsync());
                        } while (!search.IsDone);

                        entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(1);

                        return(orderDocuments
                               .Select(d => JsonConvert.DeserializeObject <Order>(d.ToJson()))
                               .ToList());
                    });
                }
                finally
                {
                    cacheSyncRoot.Release();
                }
            }

            sw.Stop();

            Response.Headers.Add("X-Execution-Time", sw.ElapsedMilliseconds + "ms");
            Response.Headers.Add("X-Cache", cacheHit ? "HIT" : "MISS");

            return(orders);
        }
        /// <summary>
        ///  Configures an async Scan operation against DynamoDB, finding items
        /// that match the specified conditions.
        /// </summary>
        /// <typeparam name="T">Type of object.</typeparam>
        /// <param name="scanConfig">Scan request object.</param>
        /// <param name="operationConfig">Config object which can be used to override the table used.</param>
        /// <returns>AsyncSearch which can be used to retrieve DynamoDB data.</returns>
        public AsyncSearch <T> FromScanAsync <T>(ScanOperationConfig scanConfig, DynamoDBOperationConfig operationConfig)
        {
            if (scanConfig == null)
            {
                throw new ArgumentNullException("scanConfig");
            }

            var scan = ConvertFromScan <T>(scanConfig, operationConfig);

            return(FromSearchAsync <T>(scan));
        }
        /// <summary>
        /// Executes a Scan operation against DynamoDB, finding items
        /// that match the specified conditions.
        /// </summary>
        /// <typeparam name="T">Type of object.</typeparam>
        /// <param name="scanConfig">Scan request object.</param>
        /// <param name="operationConfig">Config object which can be used to override the table used.</param>
        /// <returns>Lazy-loaded collection of results.</returns>
        internal IEnumerable <T> FromScan <T>(ScanOperationConfig scanConfig, DynamoDBOperationConfig operationConfig)
        {
            DynamoDBAsyncExecutor.IsMainThread("FromScanAsync");
            if (scanConfig == null)
            {
                throw new ArgumentNullException("scanConfig");
            }

            var scan = ConvertFromScan <T>(scanConfig, operationConfig);

            return(FromSearch <T>(scan));
        }
        public async Task <Document> getLatest()
        {
            var config = new ScanOperationConfig()
            {
                Limit          = 1,
                ConsistentRead = true
            };
            var search = table.Scan(config);
            var list   = await search.GetNextSetAsync();

            return(list.First());
        }
        /// <summary>
        /// A utility method for cleaning up expired sessions that IIS failed to delete.  The method performs a scan on the table
        /// with a condition that the expiration date is in the past and calls delete on all the keys returned.  Scans can be costly on performance
        /// so use this method sparingly like a nightly or weekly clean job.
        /// </summary>
        /// <param name="dbClient">The AmazonDynamoDB client used to find a delete expired sessions.</param>
        /// <param name="tableName">The table to search.</param>
        public static void DeleteExpiredSessions(AmazonDynamoDB dbClient, string tableName)
        {
            Table table = Table.LoadTable(dbClient, tableName, Table.DynamoDBConsumer.SessionStateProvider);


            ScanFilter filter = new ScanFilter();
            filter.AddCondition(ATTRIBUTE_EXPIRES, ScanOperator.LessThan, DateTime.Now);

            ScanOperationConfig config = new ScanOperationConfig();
            config.AttributesToGet = new List<string>();
            config.AttributesToGet.Add(ATTRIBUTE_SESSION_ID);
            config.Filter = filter;

            Search search = table.Scan(config);

            do
            {
                List<Document> page = search.GetNextSet();
                foreach (var document in page)
                {
                    table.DeleteItem(document);
                }
            } while (!search.IsDone);
        }