示例#1
0
        static void StorageWithAttributeMapperManualRegistration(string storageKey, string storageSecret)
        {
            // create a new user
            var user = new UserModel2()
            {
                FirstName = "Egon", LastName = "Mueller", Contact = "*****@*****.**"
            };
            var vpmodel = new VirtualPartKeyDemoModel()
            {
                Value1 = "abc", Value2 = "def", Value3 = "ghi"
            };

            using (var storageContext = new StorageContext(storageKey, storageSecret))
            {
                // ensure we are using the attributes
                storageContext.AddAttributeMapper(typeof(UserModel2));
                storageContext.AddAttributeMapper(typeof(VirtualPartKeyDemoModel));

                // ensure the table exists
                storageContext.CreateTable <UserModel2>();
                storageContext.CreateTable <VirtualPartKeyDemoModel>();

                // inser the model
                storageContext.MergeOrInsert <UserModel2>(user);
                storageContext.MergeOrInsert <VirtualPartKeyDemoModel>(vpmodel);

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

                foreach (var r in result)
                {
                    Console.WriteLine(r.FirstName);
                }
            }
        }
示例#2
0
        public async Task Execute(string storageKey, string storageSecret, string endpointSuffix = null)
        {
            Console.WriteLine("");
            Console.WriteLine(this.GetType().FullName);

            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 UserModel2()
                {
                    FirstName = "Egon", LastName = "Mueller", Contact = "*****@*****.**"
                };
                var vpmodel = new VirtualPartKeyDemoModel()
                {
                    Value1 = "abc", Value2 = "def", Value3 = "ghi"
                };

                // ensure we are using the attributes
                Console.WriteLine("Configuring Entity Mappers");
                storageContext.AddAttributeMapper(typeof(UserModel2));
                storageContext.AddAttributeMapper(typeof(VirtualPartKeyDemoModel));

                // ensure the table exists
                Console.WriteLine("Create Tables");
                await storageContext.CreateTableAsync <UserModel2>();

                await storageContext.CreateTableAsync <VirtualPartKeyDemoModel>();

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

                await storageContext.MergeOrInsertAsync <VirtualPartKeyDemoModel>(vpmodel);

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

                var resultVP = await storageContext.QueryAsync <VirtualPartKeyDemoModel>();

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

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

                await storageContext.DeleteAsync <VirtualPartKeyDemoModel>(resultVP);

                // dump the stats
                stats.DumpStats();
            }
        }
		public async Task Execute(string storageKey, string storageSecret, string endpointSuffix = null)
		{
			Console.WriteLine("");
			Console.WriteLine(this.GetType().FullName);
			
			using (var storageContext = new StorageContext(storageKey, storageSecret, endpointSuffix))
			{
				// set our delegate 
				var stats = new DemoCaseStatsDelegate();
				storageContext.SetDelegate(stats);
				
				// ensure we are using the attributes
				storageContext.AddAttributeMapper(typeof(HugeDemoEntry));

				// create 2000 items
				var data = new List<HugeDemoEntry>();
				for (int i = 0; i < 2000; i++)
					data.Add(new HugeDemoEntry());

				await storageContext.EnableAutoCreateTable().MergeOrInsertAsync<HugeDemoEntry>(data);
				
				// query all entries
				var items = await storageContext.QueryAsync<HugeDemoEntry>();

				// remove all entries
				await storageContext.DeleteAsync<HugeDemoEntry>(items);

				// dump stats				
				stats.DumpStats();
			}
		}
示例#4
0
        static void CreateModelsPaged(string storageKey, string storageSecret)
        {
            using (var storageContext = new StorageContext(storageKey, storageSecret))
            {
                storageContext.AddAttributeMapper(typeof(UserModel2), "DemoUserModel2");
                storageContext.CreateTable <UserModel2>(true);

                var startDate = DateTime.Now;

                using (var pagedWriter = new PagedTableEntityWriter <UserModel2>(storageContext, nStoreOperation.insertOrReplaceOperation, 100))
                {
                    for (var i = 0; i < 1000; i++)
                    {
                        var user = new UserModel2()
                        {
                            FirstName = "Egon", LastName = "Mueller", Contact = string.Format("em-{0}@acme.org", i)
                        };
                        pagedWriter.StoreAsync(user).ConfigureAwait(false).GetAwaiter().GetResult();
                    }
                }

                var endDate = DateTime.Now;

                Console.WriteLine("Took {0} seconds", (endDate - startDate).TotalSeconds);
            }
        }
示例#5
0
        static void StoreAsJson(string storageKey, string storageSecret)
        {
            var model = new JObjectModel()
            {
                UUID = "112233"
            };

            model.Data.Add("HEllo", "world");
            model.Data2.Value = "Hello 23";

            using (var storageContext = new StorageContext(storageKey, storageSecret))
            {
                // ensure we are using the attributes
                storageContext.AddAttributeMapper(typeof(JObjectModel));

                // ensure the table exists
                storageContext.CreateTable <JObjectModel>();

                // inser the model
                storageContext.MergeOrInsert <JObjectModel>(model);

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

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

                    foreach (var e in r.Data)
                    {
                        Console.WriteLine(e.Key + "-" + e.Value);
                    }
                }
            }
        }
示例#6
0
        public async Task Execute(string storageKey, string storageSecret, string endpointSuffix = null)
        {
            Console.WriteLine("");
            Console.WriteLine(this.GetType().FullName);

            using (var storageContext = new StorageContext(storageKey, storageSecret, endpointSuffix))
            {
                // create model with data in list
                var model = new DemoMeterModel()
                {
                    ExtendedCosts = new List <Double>()
                };
                model.ExtendedCosts.Add(5.5);
                model.ExtendedCosts.Add(6.0);

                var model2 = new DemoMeterModel()
                {
                    R = "R2"
                };

                // ensure we are using the attributes
                Console.WriteLine("Configuring Entity Mappers");
                storageContext.AddAttributeMapper(typeof(DemoMeterModel));

                // ensure the table exists
                Console.WriteLine("Create Tables");
                await storageContext.CreateTableAsync <DemoMeterModel>();

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

                await storageContext.MergeOrInsertAsync <DemoMeterModel>(model2);

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

                foreach (var item in result)
                {
                    if (item.ExtendedCosts != null)
                    {
                        foreach (var dc in item.ExtendedCosts)
                        {
                            Console.Write(dc);
                        }

                        Console.WriteLine("");
                    }
                    else
                    {
                        Console.WriteLine("No Extended Costs");
                    }
                }

                // Clean up
                Console.WriteLine("Removing all entries");
                await storageContext.DeleteAsync <DemoMeterModel>(result);
            }
        }
示例#7
0
        static void StorageWithAttributeMapper(string storageKey, string storageSecret)
        {
            // create a new user
            var user = new UserModel2()
            {
                FirstName = "Egon", LastName = "Mueller", Contact = "*****@*****.**"
            };

            using (var storageContext = new StorageContext(storageKey, storageSecret))
            {
                // ensure we are using the attributes
                storageContext.AddAttributeMapper();

                // ensure the table exists
                storageContext.CreateTable <UserModel2>();

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

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

                foreach (var r in result)
                {
                    Console.WriteLine(r.FirstName);
                }
            }
        }
示例#8
0
        public async Task Execute(string storageKey, string storageSecret, string endpointSuffix = null)
        {
            Console.WriteLine("");
            Console.WriteLine(this.GetType().FullName);

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

                // create a virtual array model
                var model = new VArrayModel()
                {
                    UUID = "112233"
                };
                model.DataElements.Add(2);
                model.DataElements.Add(3);
                model.DataElements.Add(4);

                // ensure we are using the attributes
                Console.WriteLine("Configuring Entity Mappers");
                storageContext.AddAttributeMapper(typeof(VArrayModel));

                // ensure the table exists
                Console.WriteLine("Create Tables");
                await storageContext.CreateTableAsync <VArrayModel>();

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

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

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

                    foreach (var e in r.DataElements)
                    {
                        Console.WriteLine(e);
                    }
                }

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

                // dump the stats
                stats.DumpStats();
            }
        }
        public async Task Execute(string storageKey, string storageSecret, string endpointSuffix = null)
        {
            Console.WriteLine("");
            Console.WriteLine(this.GetType().FullName);

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

                // create a new user
                Console.WriteLine("Build Models");
                var user01 = new UserModel3()
                {
                    FirstName = "Egon", LastName = "Mueller", Contact = "*****@*****.**"
                };
                var user02 = new UserModel3()
                {
                    FirstName = "Egon", LastName = "Mueller", Contact = "*****@*****.**"
                };
                user02.Codes.Add(new Code()
                {
                    CodeType = "x1", CodeValue = "x2"
                });
                user02.Codes.Add(new Code()
                {
                    CodeType = "x3", CodeValue = "x4"
                });

                Console.WriteLine("Configuring Entity Mappers");
                storageContext.AddAttributeMapper(typeof(UserModel3));

                Console.WriteLine("InsertData");
                await storageContext.EnableAutoCreateTable().MergeOrInsertAsync <UserModel3>(user01);

                await storageContext.EnableAutoCreateTable().MergeOrInsertAsync <UserModel3>(user02);

                Console.WriteLine("Query Data");
                var result = await storageContext.QueryAsync <UserModel3>();

                foreach (var r in result)
                {
                    Console.WriteLine("{0}: {1}", r.LastName, r.Codes.Count());
                }

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

                // dump the stats
                stats.DumpStats();
            }
        }
示例#10
0
        static void CheckMaxItems(string storageKey, string storageSecret)
        {
            using (var storageContext = new StorageContext(storageKey, storageSecret))
            {
                storageContext.AddAttributeMapper(typeof(UserModel2), "DemoUserModel2");
                storageContext.CreateTable <UserModel2>(true);

                var items = storageContext.Query <UserModel2>(5).AsEnumerable();
                Console.WriteLine("Found {0} items", items.Count());
                if (items.Count() != 5)
                {
                    throw new Exception("Wrong Item Count");
                }
            }
        }
        public async Task Execute(string storageKey, string storageSecret, string endpointSuffix = null)
        {
            Console.WriteLine("");
            Console.WriteLine(this.GetType().FullName);

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

                // ensure we are using the attributes
                storageContext.AddAttributeMapper(typeof(HugeDemoEntry));

                // create 4000 items
                Console.WriteLine("Creating 4200 demos items");
                var data = new List <HugeDemoEntry>();
                for (int i = 0; i < 4200; i++)
                {
                    data.Add(new HugeDemoEntry());
                }

                await storageContext.EnableAutoCreateTable().MergeOrInsertAsync <HugeDemoEntry>(data);

                // query items page by page
                Console.WriteLine("Reading page by page");

                var items = new List <HugeDemoEntry>();

                using (var queryCursor = storageContext.QueryPaged <HugeDemoEntry>(null, null))
                {
                    while (await queryCursor.LoadNextPageAsync())
                    {
                        Console.WriteLine("Reading Page #{0} with #{1} items", queryCursor.Page, queryCursor.Items.Count());
                        items.AddRange(queryCursor.Items);
                    }
                }

                // remove all entries
                Console.WriteLine("Removing all entries");
                await storageContext.DeleteAsync <HugeDemoEntry>(items);

                // dump 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);
            }
        }
        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))
            {
                using (var storageContext = new StorageContext(storageContextParent))
                {
                    // create model with data in list
                    var model = new DemoModel2()
                    {
                        P = "1", R = "2"
                    };

                    // ensure we are using the attributes
                    Console.WriteLine("Configuring Entity Mappers");
                    storageContext.AddAttributeMapper(typeof(DemoModel2), "MT1");

                    // inser the model
                    Console.WriteLine("Insert Models");
                    await storageContext.EnableAutoCreateTable().MergeOrInsertAsync <DemoModel2>(new List <DemoModel2>()
                    {
                        model
                    });

                    // change table name
                    Console.WriteLine("Update Table Name");
                    storageContext.OverrideTableName <DemoModel2>("MT2");

                    // inser the model
                    Console.WriteLine("Insert Models");
                    await storageContext.EnableAutoCreateTable().MergeOrInsertAsync <DemoModel2>(new List <DemoModel2>()
                    {
                        model
                    });

                    // cear table
                    await storageContext.DropTableAsync <DemoModel2>();

                    storageContext.OverrideTableName <DemoModel2>("MT1");
                    await storageContext.DropTableAsync <DemoModel2>();
                }
            }
        }
        public async Task Execute(string storageKey, string storageSecret, string endpointSuffix = null)
        {
            Console.WriteLine("");
            Console.WriteLine(this.GetType().FullName);

            using (var storageContext = new StorageContext(storageKey, storageSecret, endpointSuffix))
            {
                // create model with data in list
                var model = new NullListModel();

                // ensure we are using the attributes
                Console.WriteLine("Configuring Entity Mappers");
                storageContext.AddAttributeMapper(typeof(NullListModel));

                // ensure the table exists
                Console.WriteLine("Create Tables");
                await storageContext.CreateTableAsync <NullListModel>();

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

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

                foreach (var item in result)
                {
                    if (item.Items == null)
                    {
                        Console.WriteLine("Items are null");
                    }
                    else
                    {
                        Console.WriteLine("Items are not null");
                    }
                }

                // Clean up
                Console.WriteLine("Removing all entries");
                await storageContext.DeleteAsync <NullListModel>(result);
            }
        }
        public async Task Execute(string storageKey, string storageSecret, string endpointSuffix = null)
        {
            // Import from Blob
            using (var storageContext = new StorageContext(storageKey, storageSecret, endpointSuffix))
            {
                // create the model
                var model = new DatetimeModel()
                {
                    ActivatedAt = DateTime.Now.ToUniversalTime()
                };

                // save the time
                var dt = model.ActivatedAt;

                // ensure we are using the attributes
                Console.WriteLine("Configuring Entity Mappers");
                storageContext.AddAttributeMapper(typeof(DatetimeModel));

                // ensure the table exists
                Console.WriteLine("Create Tables");
                await storageContext.CreateTableAsync <DatetimeModel>();

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

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

                // get the first
                if (result.First().ActivatedAt != dt)
                {
                    Console.WriteLine("Oh NO");
                }

                // Clean up
                Console.WriteLine("Removing all entries");
                await storageContext.DeleteAsync <DatetimeModel>(result);
            }
        }
示例#16
0
        static void TestReadInterfaceValues(string storageKey, string storageSecret)
        {
            // create a new user
            var user01 = new UserModel3()
            {
                FirstName = "Egon", LastName = "Mueller", Contact = "*****@*****.**"
            };
            var user02 = new UserModel3()
            {
                FirstName = "Egon", LastName = "Mueller", Contact = "*****@*****.**"
            };

            user02.Codes.Add(new Code()
            {
                CodeType = "x1", CodeValue = "x2"
            });
            user02.Codes.Add(new Code()
            {
                CodeType = "x3", CodeValue = "x4"
            });


            using (var storageContext = new StorageContext(storageKey, storageSecret))
            {
                // ensure we are using the attributes
                storageContext.AddAttributeMapper(typeof(UserModel3));

                // insert the model
                storageContext.EnableAutoCreateTable().MergeOrInsert <UserModel3>(user01);
                storageContext.EnableAutoCreateTable().MergeOrInsert <UserModel3>(user02);

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

                foreach (var r in result)
                {
                    Console.WriteLine("{0}: {1}", r.LastName, r.Codes.Count());
                }
            }
        }
示例#17
0
        static void GetVirtualArray(string storageKey, string storageSecret)
        {
            var model = new VArrayModel()
            {
                UUID = "112233"
            };

            model.DataElements.Add(2);
            model.DataElements.Add(3);
            model.DataElements.Add(4);

            using (var storageContext = new StorageContext(storageKey, storageSecret))
            {
                // ensure we are using the attributes
                storageContext.AddAttributeMapper(typeof(VArrayModel));

                // ensure the table exists
                storageContext.CreateTable <VArrayModel>();

                // inser the model
                storageContext.MergeOrInsert <VArrayModel>(model);

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

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

                    foreach (var e in r.DataElements)
                    {
                        Console.WriteLine(e);
                    }
                }
            }
        }
        public async Task Execute(string storageKey, string storageSecret, string endpointSuffix = null)
        {
            Console.WriteLine("");
            Console.WriteLine(this.GetType().FullName);

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

                // ensure we are using the attributes
                Console.WriteLine("Configuring Entity Mappers");
                storageContext.AddAttributeMapper(typeof(UserModel2), "DemoUserModel2");

                // create tables
                Console.WriteLine("Create Tables");
                await storageContext.CreateTableAsync <UserModel2>(true);

                // write data pages
                Console.WriteLine("Writing Models Paged");
                var startDate = DateTime.Now;


                using (var pagedWriter = new PagedTableEntityWriter <UserModel2>(storageContext, nStoreOperation.insertOrReplaceOperation, 100))
                {
                    var t1 = Task.Run(async() =>
                    {
                        for (var i = 0; i < 500; i++)
                        {
                            var user = new UserModel2()
                            {
                                FirstName = "Egon", LastName = "Mueller", Contact = string.Format("em-{0}@acme.org", i)
                            };
                            await pagedWriter.StoreAsync(user);
                        }
                    });

                    var t2 = Task.Run(async() =>
                    {
                        for (var i = 500; i < 1000; i++)
                        {
                            var user = new UserModel2()
                            {
                                FirstName = "Egon", LastName = "Mueller", Contact = string.Format("em-{0}@acme.org", i)
                            };
                            await pagedWriter.StoreAsync(user);
                        }
                    });

                    Task.WaitAll(new Task[] { t1, t2 });
                }

                var endDate = DateTime.Now;

                Console.WriteLine("Took {0} seconds", (endDate - startDate).TotalSeconds);

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

                Console.WriteLine("Found {0} models", result.Count());

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

                // dump the stats
                stats.DumpStats();
            }
        }
示例#19
0
        public async Task Execute(string storageKey, string storageSecret, string endpointSuffix = null)
        {
            // Import from Blob
            using (var storageContext = new StorageContext(storageKey, storageSecret, endpointSuffix))
            {
                // create the model
                var models = new List <DemoEntityQuery>()
                {
                    new DemoEntityQuery()
                    {
                        R = "E1", DataElement = "Demo01"
                    },
                    new DemoEntityQuery()
                    {
                        R = "E2", DataElement = "Demo02"
                    },
                    new DemoEntityQuery()
                    {
                        R = "E3", DataElement = "Demo02"
                    },
                    new DemoEntityQuery()
                    {
                        R = "E4", DataElement = "Demo03"
                    }
                };

                // ensure we are using the attributes
                Console.WriteLine("Configuring Entity Mappers");
                storageContext.AddAttributeMapper(typeof(DemoEntityQuery));

                // ensure the table exists
                Console.WriteLine("Create Tables");
                await storageContext.CreateTableAsync <DemoEntityQuery>();

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

                // buidl a filter
                var queryFilter = new List <QueryFilter>()
                {
                    new QueryFilter()
                    {
                        FilterType = QueryFilterType.Where, Property = "DataElement", Value = "Demo02", Operator = QueryFilterOperator.Equal
                    },
                    new QueryFilter()
                    {
                        FilterType = QueryFilterType.Or, Property = "DataElement", Value = "Demo03", Operator = QueryFilterOperator.Equal
                    }
                };

                // query all
                Console.WriteLine("Query all Models");
                var result = (await storageContext.QueryAsync <DemoEntityQuery>(null, queryFilter)).ToList();

                if (result.Count != 3)
                {
                    Console.WriteLine("Oh no");
                }

                result = (await storageContext.QueryAsync <DemoEntityQuery>("P1", queryFilter)).ToList();

                if (result.Count != 3)
                {
                    Console.WriteLine("Oh no");
                }

                // Clean up
                Console.WriteLine("Removing all entries");
                var all = await storageContext.QueryAsync <DemoEntityQuery>();

                await storageContext.DeleteAsync <DemoEntityQuery>(all);
            }
        }
示例#20
0
        public async Task Execute(string storageKey, string storageSecret, string endpointSuffix = null)
        {
            Console.WriteLine("");
            Console.WriteLine(this.GetType().FullName);

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

                Console.WriteLine("Configuring Entity Mappers");
                storageContext.AddAttributeMapper(typeof(UserModel2), "DemoUserModel2");

                Console.WriteLine("Create Tables");
                storageContext.CreateTable <UserModel2>(true);

                Console.WriteLine("InsertData");
                var data = new List <UserModel2>()
                {
                    new UserModel2()
                    {
                        FirstName = "Egon", LastName = "Mueller", Contact = "*****@*****.**"
                    },
                    new UserModel2()
                    {
                        FirstName = "Egon", LastName = "Mueller", Contact = "*****@*****.**"
                    },
                    new UserModel2()
                    {
                        FirstName = "Egon", LastName = "Mueller", Contact = "*****@*****.**"
                    },
                    new UserModel2()
                    {
                        FirstName = "Egon", LastName = "Mueller", Contact = "*****@*****.**"
                    },
                    new UserModel2()
                    {
                        FirstName = "Egon", LastName = "Mueller", Contact = "*****@*****.**"
                    },
                    new UserModel2()
                    {
                        FirstName = "Egon", LastName = "Mueller", Contact = "*****@*****.**"
                    },
                    new UserModel2()
                    {
                        FirstName = "Egon", LastName = "Mueller", Contact = "*****@*****.**"
                    },
                    new UserModel2()
                    {
                        FirstName = "Egon", LastName = "Mueller", Contact = "*****@*****.**"
                    },
                    new UserModel2()
                    {
                        FirstName = "Egon", LastName = "Mueller", Contact = "*****@*****.**"
                    },
                    new UserModel2()
                    {
                        FirstName = "Egon", LastName = "Mueller", Contact = "*****@*****.**"
                    }
                };

                await storageContext.StoreAsync(nStoreOperation.mergeOrInserOperation, data);


                Console.WriteLine("Query max Item Models");
                var items = (await storageContext.QueryAsync <UserModel2>(5)).AsEnumerable();
                Console.WriteLine("Found {0} items", items.Count());
                if (items.Count() != 5)
                {
                    Console.WriteLine("OHOH should be 5");
                }

                Console.WriteLine("Query all items");
                var allitems = await storageContext.QueryAsync <UserModel2>();

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

                // dump the stats
                stats.DumpStats();
            }
        }
示例#21
0
        public async Task Execute(string storageKey, string storageSecret, string endpointSuffix = null)
        {
            Console.WriteLine("");
            Console.WriteLine(this.GetType().FullName);

            using (var storageContext = new StorageContext(storageKey, storageSecret, endpointSuffix))
            {
                // create a new user
                var model = new DemoEntryWithOptionalValues()
                {
                    Identifier = "X"
                };

                // ensure we are using the attributes
                Console.WriteLine("Configuring Entity Mappers");
                storageContext.AddAttributeMapper();

                // ensure the table exists
                Console.WriteLine("Create Tables");
                await storageContext.CreateTableAsync <DemoEntryWithOptionalValues>();

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

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

                // check
                if (result.Name != null)
                {
                    Console.WriteLine("OhOh should be null");
                }

                if (result.Costs.HasValue)
                {
                    Console.WriteLine("OhOh should have no value");
                }


                // update the model
                Console.WriteLine("Insert Models");
                result.Costs = 5.4;
                await storageContext.MergeOrInsertAsync <DemoEntryWithOptionalValues>(result);

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

                // check
                if (result.Name != null)
                {
                    Console.WriteLine("OhOh should be null");
                }

                if (!result.Costs.HasValue)
                {
                    Console.WriteLine("OhOh should have a value");
                }
                else
                {
                    Console.WriteLine($"Value: {result.Costs.Value}");
                }

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