-
Notifications
You must be signed in to change notification settings - Fork 76
/
Program.cs
70 lines (52 loc) · 1.93 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
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using Orleankka;
using Orleankka.Cluster;
using Orleankka.Meta;
namespace Example
{
public static class Program
{
public static async Task Main()
{
Console.WriteLine("Running example. Booting cluster might take some time ...\n");
var host = await new HostBuilder()
.UseOrleankka()
.StartServer();
await Run(host.ActorSystem());
Console.WriteLine("\nPress any key to terminate ...");
Console.ReadKey(true);
host.Dispose();
Environment.Exit(0);
}
static async Task Run(IActorSystem system)
{
var item = system.ActorOf<IInventoryItem>("12345");
await item.Tell(new Create("XBOX1"));
await Print(item);
await item.Tell(new CheckIn(10));
await Print(item);
await item.Tell(new CheckOut(5));
await Print(item);
await item.Tell(new Rename("XBOX360"));
await Print(item);
await item.Tell(new DeactivateItem());
await Print(item);
var inventory = system.ActorOf<IInventory>("#");
var items = await inventory.Ask(new GetInventoryItems());
Console.WriteLine($"\n# of items in inventory: {items.Length}");
Array.ForEach(items, Print);
var total = await inventory.Ask(new GetInventoryItemsTotal());
Console.WriteLine($"\nTotal of all items inventory: {total}");
}
static async Task Print(ActorRef item) => Print(await item.Ask(new GetDetails()));
static void Print(InventoryItemDetails details)
{
Console.WriteLine("{0}: {1} {2}",
details.Name,
details.Total,
details.Active ? "" : "(deactivated)");
}
}
}