示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool SeedItems()
        {
            if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development")
            {
                AWSXRayRecorder.Instance.BeginSegment("dynamo db call");
            }
            try
            {
                var brBatch = _ddbContext.CreateBatchWrite <Break>();
                brBatch.AddPutItems(DefaultData.GetDefaultBreaks());


                var config    = new DynamoDBOperationConfig();
                var commBatch = _ddbContext.CreateBatchWrite <Commercial>(config);
                commBatch.AddPutItems(DefaultData.GetDefaultCommercials());

                var superBatch = new MultiTableBatchWrite(brBatch, commBatch);
                var result     = superBatch.ExecuteAsync().Status;
                return(result != TaskStatus.Faulted && result != TaskStatus.Canceled);
            }
            catch (Exception)
            {
                if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development")
                {
                    AWSXRayRecorder.Instance.EndSegment(DateTime.Now);
                }
                return(false);
            }
        }
        public async static void SingleTableBatchWrite(IDynamoDBContext context)
        {
            Book book1 = new Book
            {
                Id              = 902,
                InPublication   = true,
                Isbn            = "902-11-11-1111",
                PageCount       = "100",
                Price           = 10,
                ProductCategory = "Book",
                Title           = "My book3 in batch write"
            };
            Book book2 = new Book
            {
                Id              = 903,
                InPublication   = true,
                Isbn            = "903-11-11-1111",
                PageCount       = "200",
                Price           = 10,
                ProductCategory = "Book",
                Title           = "My book4 in batch write"
            };

            var bookBatch = context.CreateBatchWrite <Book>();

            bookBatch.AddPutItems(new List <Book> {
                book1, book2
            });

            Console.WriteLine("Adding two books to ProductCatalog table.");
            await bookBatch.ExecuteAsync();
        }
        public async Task BatchWriteAsync(List <Music> list)
        {
            var writer = DDBContext.CreateBatchWrite <Music>();

            writer.AddPutItems(list);
            await writer.ExecuteAsync();
        }
示例#4
0
        public async Task <int> RecordMeasurements(string serialNumber, List <Measurement> measurements)
        {
            //if carbom monoxide is above 9PPM, trigger an alarm
            _alarmRecorder.RecordAlarms(serialNumber, measurements);

            //force apply the serial number from the device in the URI
            measurements.ForEach(m => m.DeviceSerialNumber = serialNumber);

            var batchWrite = _dbContext.CreateBatchWrite <Measurement>();
            int counter    = 0;

            for (int i = 0; i < measurements.Count; i += 25)
            {
                int range = i + 25;
                range = range > measurements.Count ? measurements.Count - i : 25;
                batchWrite.AddPutItems(measurements.GetRange(i, range));

                try
                {
                    await batchWrite.ExecuteAsync();

                    counter += range;
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "Error occured saving measurements");
                    throw ex;
                }
            }

            return(counter);
        }
        /// <inheritdoc />.
        public async Task AddRangeAsync(IEnumerable <TEntity> items)
        {
            var enumerable = items.ToList();

            while (enumerable.Any())
            {
                var batchWrite = _context.CreateBatchWrite <TEntity>();

                batchWrite.AddPutItems(enumerable.Take(25));

                await batchWrite.ExecuteAsync();

                items = enumerable.Skip(25);
            }
            ;
        }
示例#6
0
        public void DeleteMemoresForBaby(string id)
        {
            var memories = _context.Query <Memory>(id, new DynamoDBOperationConfig {
                IndexName = "BabyIdIndex"
            });
            var writeMemoryBatch = _context.CreateBatchWrite <Memory>();

            writeMemoryBatch.AddDeleteItems(memories);
            writeMemoryBatch.Execute();
        }
        private async Task <bool> AddManyItems(List <T> items)
        {
            _ = UpdateTableTracker();
            BatchWrite <T> batch = _context.CreateBatchWrite <T>();

            batch.AddPutItems(items);
            await batch.ExecuteAsync();

            return(true);
        }
        /// <summary>
        /// Storing last 15 feedbacks during some seconds time periods
        /// A random unique key as main key
        /// </summary>
        /// <param name="feedbacks"></param>
        /// <returns></returns>
        public Task StoreLastFeedbacks(IEnumerable <UserFeedbackBO> feedbacks)
        {
            if (feedbacks.Count() < 1)
            {
                return(Task.CompletedTask);
            }
            var bookBatch = _context.CreateBatchWrite <UserFeedbackDataModel>();

            bookBatch.AddPutItems(feedbacks.Select(item => UserFeedbackDataModel.GenerateFromUserFeedbackBO(item, LastFeedbacksWriterService.NumberOfLastFeedbacks)));
            return(bookBatch.ExecuteAsync());
        }
        public static async Task DeleteEventsAsync <TSaga>(this IDynamoDBContext context, TSaga instance, DynamoDbEventStoreOptions options) where TSaga : class, IV2EventSourcedSaga
        {
            var events = await context.GetEventsAsync(instance.CorrelationId, options);

            var writer = context.CreateBatchWrite <V2EventStoreModel>(new DynamoDBOperationConfig {
                OverrideTableName = options.StoreName
            });

            writer.AddDeleteItems(events);

            await writer.ExecuteAsync();
        }
        public static async Task SaveEventsAsync <TSaga>(this IDynamoDBContext context, TSaga instance, DynamoDbEventStoreOptions options) where TSaga : class, IV2EventSourcedSaga
        {
            var writer = context.CreateBatchWrite <V2EventStoreModel>(new DynamoDBOperationConfig {
                OverrideTableName = options.StoreName
            });

            var changes = instance.GetChanges();

            writer.AddPutItems(changes);

            await writer.ExecuteAsync();
        }
示例#11
0
        public async Task <APIGatewayProxyResponse> HandleAsync(APIGatewayProxyRequest input, ILambdaContext context)
        {
            context.Logger.Log($"Got items table name: {_config.ItemsTableName}");
            context.Logger.Log($"Got loans table name: {_config.LoansTableName}");

            var loanBatch = _context.CreateBatchWrite <Loan>(new DynamoDBOperationConfig()
            {
                OverrideTableName = _config.LoansTableName
            });

            loanBatch.AddPutItems(_testData.Loans);
            await loanBatch.ExecuteAsync();

            var itemBatch = _context.CreateBatchWrite <Item>(new DynamoDBOperationConfig()
            {
                OverrideTableName = _config.ItemsTableName
            });

            itemBatch.AddPutItems(_testData.Items);
            await itemBatch.ExecuteAsync();

            return(_response.Create().WithStatusCode(200).Build());
        }
        public async static void MultiTableBatchWrite(IDynamoDBContext context)
        {
            // 1. New Forum item.
            Forum newForum = new Forum
            {
                Name    = "Test BatchWrite Forum",
                Threads = 0
            };
            var forumBatch = context.CreateBatchWrite <Forum>();

            forumBatch.AddPutItem(newForum);

            // 2. New Thread item.
            Thread newThread = new Thread
            {
                ForumName   = "S3 forum",
                Subject     = "My sample question",
                KeywordTags = new List <string> {
                    "S3", "Bucket"
                },
                Message = "Message text"
            };

            DynamoDBOperationConfig config = new DynamoDBOperationConfig();

            config.SkipVersionCheck = true;
            var threadBatch = context.CreateBatchWrite <Thread>(config);

            threadBatch.AddPutItem(newThread);
            threadBatch.AddDeleteKey("some partition key value", "some sort key value");

            var superBatch = new MultiTableBatchWrite(forumBatch, threadBatch);

            Console.WriteLine("Performing batch write in MultiTableBatchWrite().");
            await superBatch.ExecuteAsync();
        }