forked from yevhen/Streamstone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
S07_Custom_stream_metadata.cs
91 lines (70 loc) · 3.1 KB
/
S07_Custom_stream_metadata.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
82
83
84
85
86
87
88
89
90
91
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.Storage.Table;
using Streamstone;
namespace Example.Scenarios
{
public class S07_Custom_stream_metadata : Scenario
{
public override async Task RunAsync()
{
await SpecifyingForExistingStream();
await SpecifyingDuringWritingToNewStream();
await UpdatingForExistingStream();
}
async Task SpecifyingForExistingStream()
{
var partition = new Partition(Table, Id + ".a");
var properties = new Dictionary<string, EntityProperty>
{
{"Created", new EntityProperty(DateTimeOffset.Now)},
{"Active", new EntityProperty(true)}
};
await Stream.ProvisionAsync(partition, StreamProperties.From(properties));
Console.WriteLine("Stream metadata specified during provisioning in partition '{0}'",
partition);
var stream = await Stream.OpenAsync(partition);
Print(stream.Properties);
}
async Task SpecifyingDuringWritingToNewStream()
{
var partition = new Partition(Table, Id + ".b");
var properties = new Dictionary<string, EntityProperty>
{
{"Created", new EntityProperty(DateTimeOffset.Now)},
{"Active", new EntityProperty(true)}
};
var stream = new Stream(partition, StreamProperties.From(properties));
await Stream.WriteAsync(stream, new EventData());
Console.WriteLine("Stream metadata specified during writing to new stream in partition '{0}'",
partition);
stream = await Stream.OpenAsync(partition);
Print(stream.Properties);
}
async Task UpdatingForExistingStream()
{
var partition = new Partition(Table, Id + ".c");
var properties = new Dictionary<string, EntityProperty>
{
{"Created", new EntityProperty(DateTimeOffset.Now)},
{"Active", new EntityProperty(true)}
};
await Stream.ProvisionAsync(partition, StreamProperties.From(properties));
Console.WriteLine("Stream metadata specified for stream in partition '{0}'",
partition);
var stream = await Stream.OpenAsync(partition);
Print(stream.Properties);
properties["Active"] = new EntityProperty(false);
await Stream.SetPropertiesAsync(stream, StreamProperties.From(properties));
Console.WriteLine("Updated stream metadata in partition '{0}'", partition);
stream = await Stream.OpenAsync(partition);
Print(stream.Properties);
}
static void Print(IEnumerable<KeyValuePair<string, EntityProperty>> properties)
{
foreach (var property in properties)
Console.WriteLine("\t{0}={1}", property.Key, property.Value.PropertyAsObject);
}
}
}