示例#1
0
        public async Task <List <T> > BatchGetAsync <T>(IEnumerable <T> items) where T : class
        {
            var itemBatch = DbContext.CreateBatchGet <T>();

            foreach (var item in items)
            {
                itemBatch.AddKey(item);
            }

            await itemBatch.ExecuteAsync();

            return(itemBatch.Results);
        }
示例#2
0
        public List <TEntity> Get(List <TEntity> keys)
        {
            using DynamoDBContext context = GetContext();
            var batch = context.CreateBatchGet <TEntity>();

            keys.ForEach(item => batch.AddKey(item));
            batch.ExecuteAsync().Wait();
            return(batch.Results);
        }
示例#3
0
        public ICollection <T> Read <T>(IEnumerable <object> keys, DynamoDBOperationConfig operationConfig)
        {
            var batch = _context.CreateBatchGet <T>(operationConfig);

            keys.ToList().ForEach(batch.AddKey);

            batch.Execute();

            return(batch.Results);
        }
        /// <summary>
        /// BatchGetAsync retrieves an IList of IPersistent objects by their ids from DynamoDB
        /// </summary>
        /// <param name="ids"></param>
        /// <returns>A Task of IList of type TItem</returns>
        public virtual async Task <IList <TItem> > BatchGetAsync(IEnumerable <TKey> ids)
        {
            var batchGet = _dbContext.CreateBatchGet <TItem>();

            foreach (var id in ids)
            {
                batchGet.AddKey(id);
            }
            await batchGet.ExecuteAsync().ConfigureAwait(false);

            return(batchGet.Results);
        }
        public MarcaController()
        {
            AmazonDynamoDBClient client = new AmazonDynamoDBClient();
            DynamoDBContext      contex = new DynamoDBContext(client);

            var marcas = contex.CreateBatchGet <Marca>();

            marcas.AddKey(1);
            marcas.AddKey(2);
            marcas.Execute();
            this.lstMarcas.Add(marcas.Results[0]);
            this.lstMarcas.Add(marcas.Results[1]);
        }
示例#6
0
        public List <TEntity> Get(Dictionary <object, object> keys)
        {
            using DynamoDBContext context = GetContext();
            var batch = context.CreateBatchGet <TEntity>();

            foreach (var keyPairs in keys)
            {
                batch.AddKey(keyPairs.Key, keyPairs.Value);
            }

            batch.ExecuteAsync().Wait();
            return(batch.Results);
        }
        public async Task <Player> GetPlayerById(string playerId)
        {
            var ddb     = GetDdbClient();
            var context = new DynamoDBContext(ddb);
            var config  = new DynamoDBOperationConfig {
                OverrideTableName = "wvufootball.Players"
            };
            var get = context.CreateBatchGet <Player>(config);

            get.AddKey(playerId);
            await get.ExecuteAsync();

            return(get.Results.FirstOrDefault());
        }
示例#8
0
        /// <summary>
        /// Batch Read using Object Persistence Model
        /// </summary>
        /// <returns></returns>
        public async Task <List <Widget> > GetWidgetsByBatchUsingOP()
        {
            List <string> ids = new List <string> {
                "WDGT1", "WDGT2", "WDGT3"
            };
            var widgets = _context.CreateBatchGet <Widget>();

            foreach (var key in ids)
            {
                widgets.AddKey(key);
            }
            await widgets.ExecuteAsync();

            return(widgets.Results);
        }
 public List <Widget> GetAll(List <string> ids)
 {
     if (ids.Count > 0)
     {
         var widgets = _context.CreateBatchGet <Widget>();
         foreach (var key in ids)
         {
             widgets.AddKey(key);
         }
         widgets.Execute();
         if (widgets.Results.Count > 0)
         {
             return(widgets.Results);
         }
     }
     return(new List <Widget>());
 }
示例#10
0
 public List <Type> GetAll(List <string> ids)
 {
     if (ids.Count > 0)
     {
         var types = _context.CreateBatchGet <Type>();
         foreach (var key in ids)
         {
             types.AddKey(key);
         }
         types.Execute();
         if (types.Results.Count > 0)
         {
             return(types.Results);
         }
     }
     return(new List <Type>());
 }
示例#11
0
        public List <Tweet> GetTweetsFromFollowedUsers(string userName)
        {
            var userTweets = db.Query <UserTweet>(userName,
                                                  QueryOperator.GreaterThanOrEqual,
                                                  new List <object> {
                DateTime.Now.AddDays(-3).Ticks
            },                                                          // get newer than 3 days
                                                  new DynamoDBOperationConfig {
                BackwardQuery = true
            });                                                         // order desc on RK

            var tweetsBatch = db.CreateBatchGet <Tweet>();

            foreach (var userTweet in userTweets)
            {
                tweetsBatch.AddKey(userTweet.AuthorName, userTweet.Timestamp);
            }
            tweetsBatch.Execute();
            return(tweetsBatch.Results);
        }
        public List <DocumentEntity> GetAllUserDocuments(string username)
        {
            List <DocumentEntity> documents = null;

            SetDynamoDBClient();

            try
            {
                DynamoDBContext context = new DynamoDBContext(DynamoClient);

                //List<QueryFilter> query = new List<QueryFilter>() { new QueryFilter("", QueryOperator.Equal, username) };
                List <ScanCondition> conditions = new List <ScanCondition>()
                {
                    new ScanCondition("DocumentOwner", ScanOperator.Equal, username)
                };


                DynamoDBOperationConfig operation = new DynamoDBOperationConfig()
                {
                    IndexName   = "DocumentOwner-index",
                    QueryFilter = conditions
                };

                BatchGet <DocumentEntity> results = context.CreateBatchGet <DocumentEntity>(operation);
                results.Execute();

                if (results.Results != null && results.Results.Count > 0)
                {
                    foreach (DocumentEntity document in results.Results)
                    {
                        documents.Add(document);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(documents);
        }
示例#13
0
            public async Task <int> GetItemCount <T>()
            {
                int totalItems = 0;

                if (dynamoDBContext == null)
                {
                    dynamoDBContext = new DynamoDBContext(dynamoDBClient);
                }

                try
                {   //try to re-write to avoid doing full table scan as performance costs are extensive. Atomic counter table maintaining one additional table on dynamodb? NK
                    var itemBatch = dynamoDBContext.CreateBatchGet <T>();
                    await itemBatch.ExecuteAsync();

                    totalItems = itemBatch.Results.Count;
                }
                catch (AmazonDynamoDBException dbException) { Console.WriteLine(dbException.Message); }
                catch (AmazonServiceException dbSvcException) { Console.WriteLine(dbSvcException.Message); }

                return(totalItems);
            }
示例#14
0
        public async Task <IActionResult> Index()
        {
            if (!await DoesTableExist())
            {
                await CreateTable();
            }

            var model = new ShortLinkListViewModel();

            var batchLinkGet = _dbContext.CreateBatchGet <ShortLink>();
            var search       = _dbContext.ScanAsync <ShortLink>(new List <ScanCondition>());

            foreach (var task in await search.GetRemainingAsync())
            {
                batchLinkGet.AddKey(task.Key);
            }

            await batchLinkGet.ExecuteAsync();

            model.Links = batchLinkGet.Results;

            return(View(model));
        }
 // POST: api/Solicitud
 public void Post([FromBody] string value)
 {
     AmazonDynamoDBClient client = new AmazonDynamoDBClient();
     DynamoDBContext      contex = new DynamoDBContext(client);
     var solicitud = contex.CreateBatchGet <Solicitud>();
 }