forked from OrleansContrib/Orleankka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
112 lines (87 loc) · 3.06 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Orleankka;
using Orleankka.Embedded;
using Orleankka.Meta;
using Orleankka.Playground;
using Microsoft.WindowsAzure.Storage;
namespace Example
{
public static class Program
{
static bool resume;
static EmbeddedActorSystem system;
public static void Main(string[] args)
{
resume = args.Length == 1 && args[0] == "resume";
Console.WriteLine("Make sure you've started Azure storage emulator using \".\\Nake.bat run\"!");
Console.WriteLine("Running example. Booting cluster might take some time ...\n");
var account = CloudStorageAccount.DevelopmentStorageAccount;
SetupTable(account);
system = ActorSystem.Configure()
.Playground()
.Cluster(x => x.Bootstrapper<SS.Bootstrap>(new SS.Properties
{
StorageAccount = account.ToString(true),
TableName = "ssexample"
}))
.Assemblies(Assembly.GetExecutingAssembly())
.Done();
system.Start().Wait();
try
{
(resume ? Resume() : Run()).Wait();
}
catch (AggregateException e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(e.InnerException.Message);
}
Console.WriteLine("\nPress any key to terminate ...");
Console.ReadKey(true);
system.Dispose();
Environment.Exit(0);
}
static void SetupTable(CloudStorageAccount account)
{
var table = account
.CreateCloudTableClient()
.GetTableReference("ssexample");
if (!resume)
table.DeleteIfExists();
table.CreateIfNotExists();
}
static async Task Run()
{
var item = system.ActorOf<InventoryItem>("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);
}
static async Task Resume()
{
var item = system.ActorOf<InventoryItem>("12345");
await item.Tell(new CheckIn(100));
await Print(item);
await item.Tell(new CheckOut(50));
await Print(item);
await item.Tell(new CheckOut(45));
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)");
}
}
}