public AzureTableStorage(string connectionString, IEnumerable <Type> types) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString); this.client = storageAccount.CreateCloudTableClient(); this.mapper = new ReflectionMapper(types); }
public IEnumerable <T> GetAll <T>(Type type) { string tableName = ReflectionMapper.GetTableName(type); CloudTable table = client.GetTableReference(tableName); TableQuery query = new TableQuery(); EntityResolver <T> resolver = (partitionKey, rowKey, timestamp, properties, eTag) => { return(mapper.Convert <T>(type, partitionKey, rowKey, properties)); }; IEnumerable <T> results = table.ExecuteQuery(query, resolver); // Trigger to get all at once by ToArray() return(results.ToArray()); }
public void TestMonthlyCarSalesDecoding() { ReflectionMapper reflectionMapper = new ReflectionMapper(typeof(MonthlyCountryEVCarSales)); Dictionary <string, EntityProperty> properties = new Dictionary <string, EntityProperty>(); properties["Sources"] = EntityProperty.GeneratePropertyForString( "http://testsource.com, http://anothersource.com" ); properties["SalesPercent"] = EntityProperty.GeneratePropertyForDouble(34.6); MonthlyCountryEVCarSales sales = reflectionMapper.Convert <MonthlyCountryEVCarSales>(typeof(MonthlyCountryEVCarSales), "Norway", "2019_1", properties); Assert.IsNotNull(sales); Assert.AreEqual(sales.Country, "Norway"); Assert.AreEqual(sales.Year, 2019); Assert.AreEqual(sales.Month, 1); Assert.AreEqual(sales.SalesPercent, 34.6m); Assert.AreEqual(sales.Sources, new string[] { "http://testsource.com", "http://anothersource.com" }.ToList()); }