Пример #1
0
        static void TestAutoCreateTableGermanCloud(string storageKey, string storageSecret, string storageEndpointSuffix)
        {
            // create a new user
            var user = new UserModel()
            {
                FirstName = "Egon", LastName = "Mueller", Contact = "*****@*****.**"
            };

            using (var storageContext = new StorageContext(storageKey, storageSecret, storageEndpointSuffix))
            {
                // generate tablename
                var tableName = "T" + Guid.NewGuid().ToString();
                tableName = tableName.Replace("-", "");

                // ensure we are using the attributes
                storageContext.AddEntityMapper(typeof(UserModel), new DynamicTableEntityMapper()
                {
                    TableName = tableName, PartitionKeyFormat = "Contact", RowKeyFormat = "Contact"
                });

                // inser the model
                storageContext.EnableAutoCreateTable().MergeOrInsert <UserModel>(user);

                // query all
                var result = storageContext.Query <UserModel>();

                foreach (var r in result)
                {
                    Console.WriteLine(r.LastName);
                }
            }
        }
Пример #2
0
        private async Task AutoCreateDuringRead(string storageKey, string storageSecret, string endpointSuffix = null)
        {
            using (var storageContext = new StorageContext(storageKey, storageSecret, endpointSuffix))
            {
                // create a new user
                var user = new UserModel()
                {
                    FirstName = "Egon", LastName = "Mueller", Contact = "*****@*****.**"
                };

                // generate tablename
                Console.WriteLine("Generating Tablename");
                var tableName = "T" + Guid.NewGuid().ToString();
                tableName = tableName.Replace("-", "");

                // ensure we are using the attributes
                Console.WriteLine("Configuring Entity Mappers");
                storageContext.AddEntityMapper(typeof(UserModel), new DynamicTableEntityMapper()
                {
                    TableName = tableName, PartitionKeyFormat = "Contact", RowKeyFormat = "Contact"
                });

                // query all
                Console.WriteLine("Query all Models");
                var result = await storageContext.EnableAutoCreateTable().QueryAsync <UserModel>();

                Console.WriteLine($"Result is {result.Count()}");
            }
        }
Пример #3
0
        static void StorageWithStaticEntityMapper(string storageKey, string storageSecret)
        {
            // create a new user
            var user = new UserModel()
            {
                FirstName = "Egon", LastName = "Mueller", Contact = "*****@*****.**"
            };

            user.Contact = user.Contact + Guid.NewGuid().ToString();

            var vpmodel = new VirtualPartitionKeyDemoModelPOCO()
            {
                Value1 = "abc", Value2 = "def", Value3 = "ghi"
            };

            using (var storageContextParent = new StorageContext(storageKey, storageSecret))
            {
                // configure the entity mapper
                storageContextParent.AddEntityMapper(typeof(UserModel), new DynamicTableEntityMapper()
                {
                    TableName = "UserProfiles", PartitionKeyFormat = "Contact", RowKeyFormat = "Contact"
                });
                storageContextParent.AddEntityMapper(typeof(VirtualPartitionKeyDemoModelPOCO), new DynamicTableEntityMapper()
                {
                    TableName = "VirtualPartitionKeyDemoModelPOCO", PartitionKeyFormat = "{{Value1}}-{{Value2}}", RowKeyFormat = "{{Value2}}-{{Value3}}"
                });

                using (var storageContext = new StorageContext(storageContextParent))
                {
                    // ensure the table exists
                    storageContext.CreateTable <UserModel>();
                    storageContext.CreateTable <VirtualPartitionKeyDemoModelPOCO>();

                    // inser the model
                    storageContext.MergeOrInsert <UserModel>(user);
                    storageContext.MergeOrInsert <VirtualPartitionKeyDemoModelPOCO>(vpmodel);
                }

                // query all
                var result = storageContextParent.Query <UserModel>();

                foreach (var r in result)
                {
                    Console.WriteLine(r.FirstName);
                }
            }
        }
Пример #4
0
        private async Task AutoCreateDuringStore(string storageKey, string storageSecret, string endpointSuffix = null)
        {
            using (var storageContext = new StorageContext(storageKey, storageSecret, endpointSuffix))
            {
                // set the delegate
                var stats = new DemoCaseStatsDelegate();
                storageContext.SetDelegate(stats);

                // create a new user
                var user = new UserModel()
                {
                    FirstName = "Egon", LastName = "Mueller", Contact = "*****@*****.**"
                };

                // generate tablename
                Console.WriteLine("Generating Tablename");
                var tableName = "T" + Guid.NewGuid().ToString();
                tableName = tableName.Replace("-", "");

                // ensure we are using the attributes
                Console.WriteLine("Configuring Entity Mappers");
                storageContext.AddEntityMapper(typeof(UserModel), new DynamicTableEntityMapper()
                {
                    TableName = tableName, PartitionKeyFormat = "Contact", RowKeyFormat = "Contact"
                });

                // inser the model
                Console.WriteLine("Insert Models with auto table creation");
                await storageContext.EnableAutoCreateTable().MergeOrInsertAsync <UserModel>(user);

                // query all
                Console.WriteLine("Query all Models");
                var result = await storageContext.QueryAsync <UserModel>();

                foreach (var r in result)
                {
                    Console.WriteLine(r.LastName);
                }

                // Clean up
                Console.WriteLine("Removing all entries");
                await storageContext.DeleteAsync <UserModel>(result);

                // dump the stats
                stats.DumpStats();
            }
        }
        public async Task InsertResults(ElectionStatistics electionStatistics)
        {
            using (var storageContext = new StorageContext(FunctionSettings.AzureStorageConnectionString))
            {
                storageContext.EnableAutoCreateTable();
                storageContext.AddAttributeMapper();
                storageContext.AddEntityMapper(typeof(ElectionStatistics), new DynamicTableEntityMapper
                {
                    PartitionKeyFormat = "Location",
                    RowKeyFormat       = "Id",
                    TableName          = FunctionSettings.AzureTableName
                });
                await storageContext.CreateTableAsync(typeof(ElectionStatistics));

                await storageContext.MergeOrInsertAsync(electionStatistics);
            }
        }
Пример #6
0
        public async Task Execute(string storageKey, string storageSecret, string endpointSuffix = null)
        {
            Console.WriteLine("");
            Console.WriteLine(this.GetType().FullName);

            using (var storageContextParent = new StorageContext(storageKey, storageSecret, endpointSuffix))
            {
                // set the delegate
                var stats = new DemoCaseStatsDelegate();
                storageContextParent.SetDelegate(stats);

                // create a new user
                var user = new UserModel()
                {
                    FirstName = "Egon", LastName = "Mueller", Contact = "*****@*****.**"
                };
                user.Contact = user.Contact + Guid.NewGuid().ToString();

                var vpmodel = new VirtualPartitionKeyDemoModelPOCO()
                {
                    Value1 = "abc", Value2 = "def", Value3 = "ghi"
                };

                // configure the entity mapper
                Console.WriteLine("Configuring Entity Mappers");
                storageContextParent.AddEntityMapper(typeof(UserModel), new DynamicTableEntityMapper()
                {
                    TableName = "UserProfiles", PartitionKeyFormat = "Contact", RowKeyFormat = "Contact"
                });
                storageContextParent.AddEntityMapper(typeof(VirtualPartitionKeyDemoModelPOCO), new DynamicTableEntityMapper()
                {
                    TableName = "VirtualPartitionKeyDemoModelPOCO", PartitionKeyFormat = "{{Value1}}-{{Value2}}", RowKeyFormat = "{{Value2}}-{{Value3}}"
                });

                using (var storageContext = new StorageContext(storageContextParent))
                {
                    // ensure the table exists
                    Console.WriteLine("Create Tables");
                    await storageContext.CreateTableAsync <UserModel>();

                    await storageContext.CreateTableAsync <VirtualPartitionKeyDemoModelPOCO>();

                    // inser the model
                    Console.WriteLine("Insert Models");
                    await storageContext.MergeOrInsertAsync <UserModel>(user);

                    await storageContext.MergeOrInsertAsync <VirtualPartitionKeyDemoModelPOCO>(vpmodel);
                }

                // query all
                Console.WriteLine("Query all Models");
                var result = await storageContextParent.QueryAsync <UserModel>();

                var resultVP = await storageContextParent.QueryAsync <VirtualPartitionKeyDemoModelPOCO>();

                foreach (var r in result)
                {
                    Console.WriteLine(r.FirstName);
                }

                // Clean up
                Console.WriteLine("Removing all entries");
                await storageContextParent.DeleteAsync <UserModel>(result);

                await storageContextParent.DeleteAsync <VirtualPartitionKeyDemoModelPOCO>(resultVP);

                // dump the stats
                stats.DumpStats();
            }
        }