-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathSmartCacheDemo.cs
63 lines (57 loc) · 1.82 KB
/
SmartCacheDemo.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
using System;
using System.Linq;
using System.Threading.Tasks;
using Demo.SmartCache.GrainInterfaces;
using Demo.SmartCache.GrainInterfaces.State;
using Orleans;
using Patterns.DevBreadboard;
namespace Patterns.SmartCache.Host
{
//internal class StateMachineDemo
//{
// public static void Run()
// {
// InitializeStateMachine()
// .ContinueWith(_ => ReadItems())
// .ContinueWith(_ => DevelopmentSiloHost.WaitForInteraction())
// .Wait();
// }
//}
internal class SmartCacheDemo
{
public static async Task CreateCatalogItem(Guid id, int index)
{
var grainId = id;
var grainState =
new CatalogItem
{
DisplayName = $"Item {index}",
SKU = id.ToString(),
ShortDescription = $"This is the {index}th item"
};
var grain = GrainClient.GrainFactory.GetGrain<ICatalogItemGrain>(grainId);
await grain.SetItem(grainState);
}
public static Task InitializeItems()
{
var createTasks = Constants.ItemIds.Select(CreateCatalogItem);
return Task.WhenAll(createTasks.ToArray());
}
public static async Task ReadItems()
{
foreach (var itemId in Constants.ItemIds)
{
var grain = GrainClient.GrainFactory.GetGrain<ICatalogItemGrain>(itemId);
var state = await grain.GetItem();
Console.WriteLine(state);
}
}
public static void Run()
{
InitializeItems()
.ContinueWith(_ => ReadItems())
.ContinueWith(_ => DevelopmentSiloHost.WaitForInteraction())
.Wait();
}
}
}