-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
81 lines (72 loc) · 3.05 KB
/
Program.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using Azure;
using Azure.Core;
using Azure.Data.Tables;
using Azure.Identity;
namespace SubmitBatchManagedIdentity
{
class Program
{
private static TableClient TableClient;
private const string stringValue = "This is a string";
private const string PartitionKey = "performance";
private const string TableName = "perftest";
private const string StorageUri = "https://[nameofstorageaccount].table.core.windows.net";
private static readonly string UAIClientId = "GUID to User Assigned Identity";
static async Task Main(string[] args)
{
Console.WriteLine("Creating TableClient");
TokenCredential tokenCredential = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID")) // Check if running local
? new DefaultAzureCredential()
: new ManagedIdentityCredential(UAIClientId);
TableClient = new TableClient(new Uri(StorageUri), TableName, tokenCredential);
var entities = GenerateEntities<SimplePerfEntity>(21);
try
{
var addEntitiesBatch = new List<TableTransactionAction>(100);
foreach (var entity in entities)
{
addEntitiesBatch.Add(new TableTransactionAction(TableTransactionActionType.Add, entity));
}
var response = await TableClient.SubmitTransactionAsync(addEntitiesBatch).ConfigureAwait(false);
}
catch (Exception)
{
throw;
}
}
private static IEnumerable<T> GenerateEntities<T>(int count) where T : class, ITableEntity, new()
{
return (IEnumerable<T>)Enumerable.Range(1, count)
.Select(n =>
{
string number = n.ToString();
return new SimplePerfEntity
{
PartitionKey = PartitionKey,
RowKey = Guid.NewGuid().ToString(),
StringTypeProperty1 = stringValue,
StringTypeProperty2 = stringValue,
StringTypeProperty3 = stringValue,
StringTypeProperty4 = stringValue,
StringTypeProperty5 = stringValue,
DoubleTypeProperty = n * 0.3,
DateTimeTypeProperty = DateTime.Now,
};
});
}
}
public record SimplePerfEntity : ITableEntity
{
public string StringTypeProperty1 { get; set; }
public string StringTypeProperty2 { get; set; }
public string StringTypeProperty3 { get; set; }
public string StringTypeProperty4 { get; set; }
public string StringTypeProperty5 { get; set; }
public double DoubleTypeProperty { get; set; }
public DateTime DateTimeTypeProperty { get; set; }
public string PartitionKey { get; set; }
public string RowKey { get; set; }
public DateTimeOffset? Timestamp { get; set; }
public ETag ETag { get; set; }
}
}