-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTableExample.cs
58 lines (44 loc) · 1.83 KB
/
TableExample.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using Microsoft.Azure.Cosmos.Table;
using Rgd.AzureAbstractions.CloudStructures;
using System.Threading.Tasks;
namespace Rgd.AzureAbstractions.Tests
{
class Program
{
static void Main(string[] args)
{
new Tester().UsingAzureTable().GetAwaiter().GetResult();
}
class Tester
{
public async Task UsingAzureTable()
{
//Using the environment variable 'AzureWebJobsStorage' for storage authentication
AzureTable<EntityExample> table = new AzureTable<EntityExample>(tableName: "sampletable", log: null);
//Using literal connection string for authentication
//AzureTable<EntityExample> table = new AzureTable<EntityExample>("sampletable", "my_connection_string", null);
//Creating "sampletable". Loading it if already exists.
table.CreateOrLoadStructure();
//Set this true to deactivate inner logs.
table.LoggingDisabled = false;
//Inserting 200 random items
for (int i = 0; i <= 200; i++)
table.Insert(new EntityExample("partitionkey", i.ToString(), 10));
//Uploading table modifications to the cloud
await table.CommitAsync();
}
}
//Entity capable to be inserted in an AzureTable
class EntityExample : TableEntity
{
public int FooProperty { get; set; }
public EntityExample() { }
public EntityExample(string partitionKey, string rowKey, int foo)
{
PartitionKey = partitionKey;
RowKey = rowKey;
FooProperty = foo;
}
}
}
}