Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        private void processSeedData(ICollection <IDataProcessor> seedDataProcessors)
        {
            logMessage("Processing seed data", DbContextActionMessageType.Info);

            bool   isSuccess = false;
            string msg       = string.Empty;

            try
            {
                var allBatch   = seedDataProcessors.Select(sp => sp.GetBatchWrite(this)).ToArray();
                var superBatch = new MultiTableBatchWrite(allBatch);
                superBatch.ExecuteAsync().Wait();
                isSuccess = true;
                msg       = "Seed data processed sucessfully";
            }
            catch (Exception ex)
            {
                isSuccess = false;
                msg       = ex.Message;
            }

            logMessage(
                isSuccess ? msg : $"Seed data processing error: {msg}",
                isSuccess ? DbContextActionMessageType.Info : DbContextActionMessageType.Error
                );
        }
        public new async Task CreateAsync(Subscription subscription)
        {
            var EventAggregateBatch = DynamoDBContext.CreateBatchWrite <EventAggregate>();
            var SubscriptionBatch   = DynamoDBContext.CreateBatchWrite <Model.Subscription>();


            subscription.Events.ForEach(e =>
            {
                EventAggregateBatch.AddPutItem(
                    new EventAggregate
                {
                    SubscriptionId = subscription.Id,
                    ApplicationId  = subscription.ApplicationId,
                    EventName      = e.EventName
                }
                    );
            });

            SubscriptionBatch.AddPutItem(subscription);
            MultiTableBatchWrite batch = DynamoDBContext.CreateMultiTableBatchWrite(EventAggregateBatch, SubscriptionBatch);

            await batch.ExecuteAsync();
        }
        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();
        }