-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemoMutatingActors.cs
More file actions
75 lines (62 loc) · 1.84 KB
/
Copy pathDemoMutatingActors.cs
File metadata and controls
75 lines (62 loc) · 1.84 KB
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.Windows.Forms;
using SynchronousMessageSystem;
namespace DemoApplication;
public partial class DemoMutatingActors : Form
{
private ActorSystem ActorSystem { get; }
public DemoMutatingActors()
{
InitializeComponent();
// 1. Create the actor system.
ActorSystem = new ActorSystem();
}
private void DemoMutatingActors_Load(object sender, EventArgs e)
{
// 2. Create the actors.
ActorSystem.AddActor(new Actor1F("First Actor"));
ActorSystem.AddActor(new Actor2Fa("Second Actor"));
}
private void button1_Click(object sender, EventArgs e)
{
// 3. Tell the first actor to talk to the second actor. You could keep a reference in the form.
// Less type safe way to do this:
// ((Actor1F?)ActorSystem.GetActor("First Actor"))!.SendMessage();
// More type safe way to do this:
ActorSystem.GetActor<Actor1F>()!.SendMessage();
}
}
public class Actor1F : Actor
{
public Actor1F(string actorName) : base(actorName, null)
{
}
public void SendMessage()
{
// 4. Talk to aktor 2 by name.
Talk("Second Actor", "Hello!");
}
public override void Other(Actor sender, ActorMatch? address, object message)
{
}
}
public class Actor2Fa : Actor
{
public Actor2Fa(string actorName) : base(actorName, null)
{
}
public override void Other(Actor sender, ActorMatch? address, object message)
{
// 5. Confirm message and mutate.
MessageBox.Show(@"Yes, I got the message!");
Become(new Actor2Fb());
}
}
public class Actor2Fb : Actor
{
public override void Other(Actor sender, ActorMatch? address, object message)
{
// 6. The second time, this object will receive the message.
MessageBox.Show(@"Now I got the message!");
}
}