Exemplo n.º 1
0
        public DynamoDBFlatConfig(DynamoDBOperationConfig operationConfig, DynamoDBContextConfig contextConfig)
        {
            if (operationConfig == null)
            {
                operationConfig = _emptyOperationConfig;
            }
            if (contextConfig == null)
            {
                contextConfig = _emptyContextConfig;
            }

            bool   consistentRead    = operationConfig.ConsistentRead ?? contextConfig.ConsistentRead ?? false;
            bool   skipVersionCheck  = operationConfig.SkipVersionCheck ?? contextConfig.SkipVersionCheck ?? false;
            bool   ignoreNullValues  = operationConfig.IgnoreNullValues ?? contextConfig.IgnoreNullValues ?? false;
            string overrideTableName =
                !string.IsNullOrEmpty(operationConfig.OverrideTableName) ? operationConfig.OverrideTableName : string.Empty;
            string tableNamePrefix =
                !string.IsNullOrEmpty(operationConfig.TableNamePrefix) ? operationConfig.TableNamePrefix :
                !string.IsNullOrEmpty(contextConfig.TableNamePrefix) ? contextConfig.TableNamePrefix : string.Empty;
            bool backwardQuery = operationConfig.BackwardQuery ?? false;

            ConsistentRead    = consistentRead;
            SkipVersionCheck  = skipVersionCheck;
            IgnoreNullValues  = ignoreNullValues;
            OverrideTableName = overrideTableName;
            TableNamePrefix   = tableNamePrefix;
            BackwardQuery     = backwardQuery;
        }
Exemplo n.º 2
0
        public async Task GetDynamoDbUser(string environment, string email)
        {
            if (dynamoDbClient == null)
            {
                dynamoDbClient = new AmazonDynamoDBClient();
            }

            DynamoDBContextConfig config = new DynamoDBContextConfig()
            {
                TableNamePrefix = environment + "-"
            };
            DynamoDBContext context = new DynamoDBContext(dynamoDbClient, config);

            log  = "Looking for user(" + email + ") within dynamodb table " + environment + "-User.";
            user = await context.LoadAsync <User>(email);

            if (user != null)
            {
                log += "*** Found that user ***";
            }
            else
            {
                log += "*** Did not find that user";
            }
        }
Exemplo n.º 3
0
        static AWSConfigsDynamoDB()
        {
            try
            {
#if BCL || AWSSDK_UNITY
                var root    = new RootConfig();
                var section = root.GetServiceSection(dynamoDBKey);
                if (section == null)
                {
                    return;
                }

                var rootSection = new DynamoDBSectionRoot(section);
                if (rootSection.DynamoDB != null)
                {
                    AWSConfigsDynamoDB.Configure(rootSection.DynamoDB);
                }
#endif
            }
            finally
            {
                // If no configuration exist at least
                // configure the context config to the default.
                if (Context == null)
                {
                    Context          = new DynamoDBContextConfig();
                    ConversionSchema = ConversionSchema.V1;;
                }
            }
        }
Exemplo n.º 4
0
        public static void ConfigureDynamoDb(this IServiceCollection services, bool isDebug)
        {
            var tableName = Environment.GetEnvironmentVariable("LinkTable");

            AWSConfigsDynamoDB.Context.TypeMappings[typeof(LinkDto)] =
                new Amazon.Util.TypeMapping(typeof(LinkDto), tableName);

            var dbConfig = new AmazonDynamoDBConfig();

            if (isDebug)
            {
                //TODO parametrize
                dbConfig = new AmazonDynamoDBConfig
                {
                    RegionEndpoint = RegionEndpoint.APSoutheast2,
                    ServiceURL     = "http://localhost:8000"
                };
            }

            var client = new AmazonDynamoDBClient(dbConfig);
            var config = new DynamoDBContextConfig {
                Conversion = DynamoDBEntryConversion.V2
            };
            var ddbContext = new DynamoDBContext(client, config);

            services.AddSingleton <IDynamoDBContext>(ddbContext);
        }
Exemplo n.º 5
0
        public async Task SaveAsync(User userProperties)
        {
            userProperties.Tags = CleanTags(userProperties.Tags);
            CleanFieldDescriptors(userProperties.FieldDescriptors);

            try
            {
                var config = new DynamoDBContextConfig {
                    TableNamePrefix = TablePrefix
                };
                var context = new DynamoDBContext(Client, config);

                await context.SaveAsync(userProperties);
            }
            catch (ProvisionedThroughputExceededException ex)
            {
                _logger.LogError("ProvisionedThroughputExceededException writing user properties to DynamoDB: " + ex.Message);
                throw;
            }
            catch (ConditionalCheckFailedException ex)
            {
                _logger.LogError("Conditional check failed for save user properties: " + userProperties.UserId);
                throw;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Exception writing user properties to DynamoDB: " + ex.Message);
                throw;
            }
        }
Exemplo n.º 6
0
        public async Task <User> LoadAsync(Guid accountId, Guid userId)
        {
            var stopwatch = Stopwatch.StartNew();

            try
            {
                var config = new DynamoDBContextConfig
                {
                    TableNamePrefix = TablePrefix,
                };
                var context = new DynamoDBContext(Client, config);

                return(await context.LoadAsync <User>(accountId, userId));
            }
            catch (ProvisionedThroughputExceededException ex)
            {
                _logger.LogError(ex, "ProvisionedThroughputExceededException LoadAsync for user properties from DynamoDB: " + ex.Message);
                throw;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Exception loading user properties by Id: " + ex);
                throw;
            }
            finally
            {
                stopwatch.Stop();
                _logger.LogInformation("Load user properties by Id took: {0}ms for {1}", stopwatch.ElapsedMilliseconds, userId);
            }
        }
        public void Save(Checkpoint checkpoint)
        {
            try
            {
                var config = new DynamoDBContextConfig {
                    TableNamePrefix = TablePrefix, SkipVersionCheck = true
                };
                var context = new DynamoDBContext(Client, config);

                _logger.LogTrace("Saving checkpoint: {0}", checkpoint);
                context.SaveAsync(checkpoint);
            }
            catch (ProvisionedThroughputExceededException ex)
            {
                _logger.LogError(ex,
                                 "ProvisionedThroughputExceededException writing measurement to DynamoDB: " + ex.Message);
                throw;
            }
            catch (ConditionalCheckFailedException ex)
            {
                _logger.LogError(ex, "Conditional check failed for save measurement - ignoring");
                // Safe to ignore as measurement is not likely to be being updated.
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Exception writing measurement to DynamoDB: " + ex.Message);
                throw;
            }
        }
        public static IServiceCollection AddDynamoDb(this IServiceCollection services)
        {
            // ReSharper disable once InconsistentNaming
            const string TABLENAME_ENVIRONMENT_VARIABLE_LOOKUP = "RidesTable";

            // Check to see if a table name was passed in through environment variables and if so
            // add the table mapping.
            var tableName = Environment.GetEnvironmentVariable(TABLENAME_ENVIRONMENT_VARIABLE_LOOKUP);

            if (!string.IsNullOrEmpty(tableName))
            {
                AWSConfigsDynamoDB.Context.TypeMappings[typeof(Ride)] = new Amazon.Util.TypeMapping(typeof(Ride), tableName);
            }

            services.AddSingleton <IAmazonDynamoDB, AmazonDynamoDBClient>();
            services.AddSingleton(sp => new DynamoDBContextConfig {
                Conversion = DynamoDBEntryConversion.V2
            });
            var config = new DynamoDBContextConfig {
                Conversion = DynamoDBEntryConversion.V2
            };

            // TODO: singleton ??
            services.AddTransient <IDynamoDBContext>(sp => new DynamoDBContext(new AmazonDynamoDBClient(), config));

            return(services);
        }
        public override void LoadUnitTestData(DataContainer dataContainer)
        {
            Console.WriteLine($"Using connection string {dataContainer.ConnectionString}");
            using (var client = new DynamoDBClientBuilder(dataContainer.ConnectionString).GetClient()) {
                client.CreateTableAsync("CONTACTS_AUDIT",
                                        new List <KeySchemaElement>()
                {
                    new KeySchemaElement("ID", KeyType.HASH)
                },
                                        new List <AttributeDefinition>()
                {
                    new AttributeDefinition("ID", ScalarAttributeType.S)
                }, new ProvisionedThroughput(10, 10)
                                        ).Wait();
                client.CreateTableAsync("EMAILS",
                                        new List <KeySchemaElement>()
                {
                    new KeySchemaElement("ID", KeyType.HASH)
                },
                                        new List <AttributeDefinition>()
                {
                    new AttributeDefinition("ID", ScalarAttributeType.S)
                }, new ProvisionedThroughput(10, 10)
                                        ).Wait();
                client.CreateTableAsync("LEADS",
                                        new List <KeySchemaElement>()
                {
                    new KeySchemaElement("ID", KeyType.HASH)
                },
                                        new List <AttributeDefinition>()
                {
                    new AttributeDefinition("ID", ScalarAttributeType.S)
                }, new ProvisionedThroughput(10, 10)
                                        ).Wait();
                client.CreateTableAsync("PEOPLE",
                                        new List <KeySchemaElement>()
                {
                    new KeySchemaElement("Id", KeyType.HASH)
                },
                                        new List <AttributeDefinition>()
                {
                    new AttributeDefinition("Id", ScalarAttributeType.S)
                }, new ProvisionedThroughput(10, 10)
                                        ).Wait();


                var contextConfig = new DynamoDBContextConfig()
                {
                    TableNamePrefix = ""
                };
                var context = new DynamoDBContext(client, contextConfig);

                var people = GetPeople(200);

                var contactsBatch = context.CreateBatchWrite <Person>();
                contactsBatch.AddPutItems(people);
                contactsBatch.ExecuteAsync().GetAwaiter().GetResult();
            }
        }
Exemplo n.º 10
0
        private static DynamoDBContext GetContext()
        {
            AWSCredentials credentials   = new StoredProfileAWSCredentials("rli-dev", "C:/Users/pnpham/.aws/credentials");
            var            Client        = new AmazonDynamoDBClient(credentials, Amazon.RegionEndpoint.USEast1);
            var            contextConfig = new DynamoDBContextConfig();

            return(new DynamoDBContext(Client, contextConfig));
        }
Exemplo n.º 11
0
        public static IDynamoDBContext GetDbContext()
        {
            var config = new DynamoDBContextConfig {
                Conversion = DynamoDBEntryConversion.V2
            };

            return(new DynamoDBContext(new AmazonDynamoDBClient(Environment.AccessKey, Environment.SecretKey), config));
        }
Exemplo n.º 12
0
        protected void InitRepository()
        {
            var config = new DynamoDBContextConfig { Conversion = DynamoDBEntryConversion.V2 };

            AWSConfigsDynamoDB.Context.TypeMappings[typeof(T)] = new Amazon.Util.TypeMapping(typeof(T), DynamoTableName);

            DDBContext = new DynamoDBContext(new AmazonDynamoDBClient(), config);
        }
Exemplo n.º 13
0
        public DynamoCrudRepository()
        {
            var config = new DynamoDBContextConfig {
                Conversion = DynamoDBEntryConversion.V2
            };

            client    = new AmazonDynamoDBClient();
            dbContext = new DynamoDBContext(client, config);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Default constructor that Lambda will invoke.
        /// </summary>
        public ShoppingCartRepository()
        {
            AWSConfigsDynamoDB.Context.TypeMappings[typeof(Item)] = new Amazon.Util.TypeMapping(typeof(Item), TABLENAME);
            var config = new DynamoDBContextConfig {
                Conversion = DynamoDBEntryConversion.V2
            };

            this._dDBContext = new DynamoDBContext(new AmazonDynamoDBClient(), config);
        }
Exemplo n.º 15
0
        public DataService()
        {
            AWSConfigsDynamoDB.Context.TypeMappings[typeof(Todo)] = new Amazon.Util.TypeMapping(typeof(Todo), "todo");

            Config = new DynamoDBContextConfig {
                Conversion = DynamoDBEntryConversion.V2
            };
            Context = new DynamoDBContext(new AmazonDynamoDBClient(RegionEndpoint.EUWest1), Config);
        }
        public BlogsController(IAmazonDynamoDB dynamoDb, ILogger <BlogsController> logger)
        {
            var config = new DynamoDBContextConfig {
                Conversion = DynamoDBEntryConversion.V2
            };

            this.context = new DynamoDBContext(dynamoDb, config);
            this.logger  = logger;
        }
Exemplo n.º 17
0
        public void SetContext()
        {
            DynamoDBContextConfig config = new DynamoDBContextConfig()
            {
                TableNamePrefix = SkillMetadata.DbTablePrefix
            };

            DbContext = new DynamoDBContext(Client, config);
        }
        public ClientService(IDynamoDBSettings settings)
        {
            _dynamoDBClient = new AmazonDynamoDBClient(RegionEndpoint.USEast2);
            var config = new DynamoDBContextConfig {
                TableNamePrefix = settings.Prefix
            };

            _context = new DynamoDBContext(_dynamoDBClient, config);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Default constructor that Lambda will invoke.
        /// </summary>
        public Functions()
        {
            ApiDefine.Initialize();
            var config = new DynamoDBContextConfig {
                Conversion = DynamoDBEntryConversion.V2
            };

            this.DDBContext = new DynamoDBContext(new AmazonDynamoDBClient(), config);
        }
Exemplo n.º 20
0
        public GetTodo()
        {
            AWSConfigsDynamoDB.Context.TypeMappings[typeof(TodoItem)] = new Amazon.Util.TypeMapping(typeof(TodoItem), Functions.Table);
            var config = new DynamoDBContextConfig {
                Conversion = DynamoDBEntryConversion.V2
            };

            _dbContext = new DynamoDBContext(new AmazonDynamoDBClient(), config);
        }
        ///<SUMMMARY>
        /// A Function that will load customer database
        ///</---->
        public void LoadDatabase()
        {
            AWSConfigsDynamoDB.Context.TypeMappings[typeof(Customers)] = new Amazon.Util.TypeMapping(typeof(Customers), "MaoProduce-Stack-CustomerTable-OZ2X2B0G09V6");
            var config = new DynamoDBContextConfig {
                Conversion = DynamoDBEntryConversion.V2
            };

            this.DDBContext2 = new DynamoDBContext(new AmazonDynamoDBClient(), config);
        }
Exemplo n.º 22
0
        public DbDataService(IAmazonDynamoDB dynamoDbClient)
        {
            AWSConfigsDynamoDB.Context.TypeMappings[typeof(T)] = new Amazon.Util.TypeMapping(typeof(T), typeof(T).Name);
            var conf = new DynamoDBContextConfig {
                Conversion = DynamoDBEntryConversion.V2
            };

            _ddbContext = new DynamoDBContext(dynamoDbClient, conf);
        }
Exemplo n.º 23
0
        // Constructor used for testing
        public ServerlessHelloWorld(IAmazonDynamoDB client)
        {
            AWSConfigsDynamoDB.Context.TypeMappings[typeof(Greeting)] = new Amazon.Util.TypeMapping(typeof(Greeting), GREETINGS_TABLE_NAME);

            var config = new DynamoDBContextConfig {
                Conversion = DynamoDBEntryConversion.V2
            };

            this.dbContext = new DynamoDBContext(client, config);
        }
Exemplo n.º 24
0
        public AttractionRepository()
        {
            AWSConfigsDynamoDB.Context.TypeMappings[typeof(Attraction)] = new Amazon.Util.TypeMapping(typeof(Attraction), TableName);

            var config = new DynamoDBContextConfig {
                Conversion = DynamoDBEntryConversion.V2
            };

            _dbContext = new DynamoDBContext(new AmazonDynamoDBClient(RegionEndpoint.USWest2), config);
        }
        public DynamoDBContext GetContext(string connectionString)
        {
            var contextConfig = new DynamoDBContextConfig()
            {
                TableNamePrefix = ""
            };
            var context = new DynamoDBContext(GetClient(), contextConfig);

            return(context);
        }
Exemplo n.º 26
0
        public TODOListDataAccess(IAmazonDynamoDB ddbClient)
        {
            var config = new DynamoDBContextConfig
            {
                Conversion     = DynamoDBEntryConversion.V2,
                ConsistentRead = true
            };

            this.Context = new DynamoDBContext(ddbClient);
        }
Exemplo n.º 27
0
        public DynamoService()
        {
            _client = new AmazonDynamoDBClient();

            _conf = new DynamoDBContextConfig
            {
                ConsistentRead = true,
                Conversion     = DynamoDBEntryConversion.V2
            };
        }
Exemplo n.º 28
0
        public void CreateContext(DynamoDBEntryConversion conversion)
        {
            var config = new DynamoDBContextConfig
            {
                //IgnoreNullValues = true
                Conversion = conversion
            };

            Context = new DynamoDBContext(Client, config);
        }
Exemplo n.º 29
0
        public DynamoDbCityService(string environment)
        {
            this.environment = environment;
            DynamoDBContextConfig config = new DynamoDBContextConfig()
            {
                TableNamePrefix = environment + "-"
            };

            dynamoDbContext = new DynamoDBContext(DynamoDbClientService.getDynamoDBClient(environment), config);
            tableName       = environment + "-City";
        }
        public DynamoDbService(IAmazonDynamoDB ddbClient)
        {
            MapEntities();

            var config = new DynamoDBContextConfig
            {
                Conversion = DynamoDBEntryConversion.V2
            };

            _ddbContext = new DynamoDBContext(ddbClient, config);
        }
Exemplo n.º 31
0
        public DynamoDBFlatConfig(DynamoDBOperationConfig operationConfig, DynamoDBContextConfig contextConfig)
        {
            if (operationConfig == null)
                operationConfig = _emptyOperationConfig;
            if (contextConfig == null)
                contextConfig = _emptyContextConfig;

            bool consistentRead = operationConfig.ConsistentRead ?? contextConfig.ConsistentRead ?? false;
            bool skipVersionCheck = operationConfig.SkipVersionCheck ?? contextConfig.SkipVersionCheck ?? false;
            bool ignoreNullValues = operationConfig.IgnoreNullValues ?? contextConfig.IgnoreNullValues ?? false;
            string overrideTableName =
                !string.IsNullOrEmpty(operationConfig.OverrideTableName) ? operationConfig.OverrideTableName : string.Empty;
            string tableNamePrefix =
                !string.IsNullOrEmpty(operationConfig.TableNamePrefix) ? operationConfig.TableNamePrefix :
                !string.IsNullOrEmpty(contextConfig.TableNamePrefix) ? contextConfig.TableNamePrefix : string.Empty;
            bool backwardQuery = operationConfig.BackwardQuery ?? false;
            string indexName =
                !string.IsNullOrEmpty(operationConfig.IndexName) ? operationConfig.IndexName : DefaultIndexName;
            List<ScanCondition> queryFilter = operationConfig.QueryFilter ?? new List<ScanCondition>();
            ConditionalOperatorValues conditionalOperator = operationConfig.ConditionalOperator;
            DynamoDBEntryConversion conversion = operationConfig.Conversion ?? contextConfig.Conversion ?? DynamoDBEntryConversion.CurrentConversion;

            ConsistentRead = consistentRead;
            SkipVersionCheck = skipVersionCheck;
            IgnoreNullValues = ignoreNullValues;
            OverrideTableName = overrideTableName;
            TableNamePrefix = tableNamePrefix;
            BackwardQuery = backwardQuery;
            IndexName = indexName;
            QueryFilter = queryFilter;
            ConditionalOperator = conditionalOperator;
            Conversion = conversion;

            State = new OperationState();
        }
Exemplo n.º 32
0
 internal DynamoDBConfig()
 {
     Context = new DynamoDBContextConfig();
     ConversionSchema = ConversionSchema.V1;
 }