forked from OrleansContrib/Orleankka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
75 lines (58 loc) · 2.08 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
using System;
using System.Net;
using System.Reflection;
using System.Threading.Tasks;
using EventStore.ClientAPI;
using Orleankka;
using Orleankka.Client;
using Orleankka.Cluster;
using Orleankka.Meta;
using Orleans;
using Orleans.Hosting;
namespace Example
{
public static class Program
{
public static async Task Main()
{
Console.WriteLine("Make sure you've started local GES node using \".\\Nake.bat run\"!");
Console.WriteLine("Running example. Booting cluster might take some time ...\n");
ES.Connection = EventStoreConnection.Create(new IPEndPoint(IPAddress.Loopback, 1113));
await ES.Connection.ConnectAsync();
var host = await new SiloHostBuilder()
.ConfigureApplicationParts(x => x
.AddApplicationPart(Assembly.GetExecutingAssembly())
.WithCodeGeneration())
.UseOrleankka()
.Start();
var client = await host.Connect();
await Run(client.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);
}
static async Task Print(ActorRef item)
{
var details = await item.Ask(new GetDetails());
Console.WriteLine("{0}: {1} {2}",
details.Name,
details.Total,
details.Active ? "" : "(deactivated)");
}
}
}