private static void CreateTablesIfTheyDoNotExist()
        {
            var ctx = new DataContext(DynamoDbClient, string.Empty);

            ctx.OnLog += ExternalLoggingRoutine.Log;

            ctx.CreateTableIfNotExists
            (
                new CreateTableArgs <Genre>
                (
                    1, 1,
                    g => g.Title,
                    null, null,
                    Genre.GetInitialEntities
                    // Do not implement this via an anonymous method! Because it's called within static constructor, the call will block indefinitely!
                )
            );

            ctx.CreateTableIfNotExists
            (
                new CreateTableArgs <Movie>
                (
                    m => m.Genre,
                    m => m.Title,
                    m => m.Director,
                    m => m.Year,
                    m => m.Budget
                )
            );

            ctx.CreateTableIfNotExists
            (
                new CreateTableArgs <Review>
                (
                    10, 10,
                    r => r.MovieId,
                    r => r.Reviewer
                )
            );

            ctx.CreateTableIfNotExists
            (
                new CreateTableArgs <Reviewers>
                (
                    r => r.Login
                )
            );
        }
        private static void CreateTablesIfTheyDoNotExist()
        {
            var ctx = new DataContext(DynamoDbClient, string.Empty);

            ctx.OnLog += ExternalLoggingRoutine.Log;

            ctx.CreateTableIfNotExists
                (
                    new CreateTableArgs<Genre>
                        (
                        1, 1,
                        g => g.Title,
                        null, null,
                        Genre.GetInitialEntities
                        // Do not implement this via an anonymous method! Because it's called within static constructor, the call will block indefinitely!
                        )
                );

            ctx.CreateTableIfNotExists
                (
                    new CreateTableArgs<Movie>
                        (
                        m => m.Genre,
                        m => m.Title,
                        m => m.Director,
                        m => m.Year,
                        m => m.Budget
                        )
                );

            ctx.CreateTableIfNotExists
                (
                    new CreateTableArgs<Review>
                        (
                        10, 10,
                        r => r.MovieId,
                        r => r.Reviewer
                        )
                );

            ctx.CreateTableIfNotExists
                (
                    new CreateTableArgs<Reviewers>
                        (
                        r => r.Login
                        )
                );
        }
        private void SetupHealthCheck()
        {
            var record = new HealthCheckEntity()
            {
                Id = "1", CreatedAt = DateTime.Now, ExpiresAt = DateTime.Now.AddYears(10)
            };

            _context.CreateTableIfNotExists(new CreateTableArgs <HealthCheckEntity>(typeof(HealthCheckEntity).Name, typeof(string), g => g.Id));
            var table  = _context.GetTable <HealthCheckEntity>();
            var entity = table.FirstOrDefault(x => (string)x.Id == "1");

            if (entity == null)
            {
                table.InsertOnSubmit(record);
                _context.SubmitChanges();
            }
            Logger.Trace($"{nameof(DynamoStore)}.{nameof(SetupHealthCheck)}",
                         new LogItem("Event", "Insert health check entity"),
                         new LogItem("Type", typeof(HealthCheckEntity).ToString),
                         new LogItem("Entity", record.ToString));
        }
 private static void CreateTablesIfTheyDoNotExist()
 {
     var ctx = new DataContext(DynamoDbClient, string.Empty);
     ctx.CreateTableIfNotExists
     (
         new CreateTableArgs<Note>
         (
             // hash key
             "UserId", typeof(string), 
             // range key
             g => g.ID, 
             // secondary index
             (Expression<Func<Note, object>>)(g => g.TimeCreated)
         )
     );
 }
        private static void CreateTablesIfTheyDoNotExist()
        {
            var ctx = new DataContext(DynamoDbClient, string.Empty);

            ctx.CreateTableIfNotExists
            (
                new CreateTableArgs <Note>
                (
                    // hash key
                    "UserId", typeof(string),
                    // range key
                    g => g.ID,
                    // secondary index
                    (Expression <Func <Note, object> >)(g => g.TimeCreated)
                )
            );
        }
Example #6
0
        public void DataContext()
        {
            var client = TestConfiguration.GetDynamoDbClient();
            var ctx    = new DataContext(client);

            ctx.CreateTableIfNotExists(
                new CreateTableArgs <Book>(
                    1,
                    1,
                    r => r.Name,
                    r => r.PublishYear,
                    null,
                    null,
                    () =>
                    new[]
            {
                new Book
                {
                    Name               = "TestBook" + Guid.NewGuid(),
                    PublishYear        = 2016,
                    Author             = "foo",
                    NumPages           = 25,
                    PopularityRating   = default(Book.Popularity),
                    UserFeedbackRating = default(Book.Stars),
                    RentingHistory     = default(List <string>),
                    FilmsBasedOnBook   = default(IDictionary <string, TimeSpan>),
                    LastRentTime       = default(DateTime),
                    Publisher          = default(Book.PublisherDto),
                    ReviewsList        = default(List <Book.ReviewDto>)
                }
            }));

            var table = ctx.GetTable <Book>();

            //TODO: figure out a way to directly prove that the tablename prefix is getting applied, rather than this indirect approach
            var result = table.FirstOrDefault();

            Assert.IsNotNull(result);
        }
        public bool CreateDatabaseAndTablesIfNotExists()
        {
            var models = from prop in context.GetType().GetProperties()
                         where prop.GetMethod.ReturnType.Name.BeginsWith("Table`") &&                                   // look for Table<> return types.
                         !prop.IsDefined(typeof(ViewAttribute))
                         select new
            {
                Property = prop,
            };

            // Get the generic type returned by the method in the context and create the table if missing.
            models.ForEach(m =>
            {
                PropertyInfo p = m.Property;
                Type t         = p.GetMethod.ReturnType;
                Type gt        = t.GenericTypeArguments[0].UnderlyingSystemType;
                context.CreateTableIfNotExists(gt);
            });

            // TODO: Determine whether tables exist!
            // TODO: Even better, figure out the migrations based on the current schema vs. the model schema!
            return(false);
        }
        public void DataContext()
        {
            var client = TestConfiguration.GetDynamoDbClient();
            var ctx = new DataContext(client);
            ctx.CreateTableIfNotExists(
                new CreateTableArgs<Book>(
                    1,
                    1,
                    r => r.Name,
                    r => r.PublishYear,
                    null,
                    null,
                    () =>
                        new[]
                        {
                            new Book
                            {
                                Name = "TestBook" + Guid.NewGuid(),
                                PublishYear = 2016,
                                Author = "foo",
                                NumPages = 25,
                                PopularityRating = default(Book.Popularity),
                                UserFeedbackRating = default(Book.Stars),
                                RentingHistory = default(List<string>),
                                FilmsBasedOnBook = default(IDictionary<string, TimeSpan>),
                                LastRentTime = default(DateTime),
                                Publisher = default(Book.PublisherDto),
                                ReviewsList = default(List<Book.ReviewDto>)
                            }
                        }));

            var table = ctx.GetTable<Book>();

            //TODO: figure out a way to directly prove that the tablename prefix is getting applied, rather than this indirect approach
            var result = table.FirstOrDefault();
            Assert.IsNotNull(result);
        }
        public static void CreateTableIfNotExists <T>(this DataContext context) where T : IEntity
        {
            Type type = typeof(T);

            context.CreateTableIfNotExists(type);
        }