Skip to content

Instantly share code, notes, and snippets.

@GeertVL-zz
Created June 24, 2015 12:43
Show Gist options
  • Save GeertVL-zz/749f8c5de49bd2fb207b to your computer and use it in GitHub Desktop.
Save GeertVL-zz/749f8c5de49bd2fb207b to your computer and use it in GitHub Desktop.
public class Guest : UntypedActor
{
private IActorRef _receptionist;
public Guest()
{
var receptionist = Context.ActorSelection("/user/Klara");
receptionist.Tell(new Identify("111"), Self);
}
protected override void OnReceive(object message)
{
if (message is ActorIdentity)
{
Console.WriteLine("Actor has an identity: " + message);
_receptionist = ((ActorIdentity)message).Subject;
Context.Watch(_receptionist);
}
else if (message.Equals("enter"))
{
Console.WriteLine("At the reception : {0} ", Self.Path.Name);
var t = Task.Run(async () =>
{
var t1 = _receptionist.Ask<Badge>(new BadgeRequest { Name = Self.Path.Name, LicensePlate = "AAA111" });
await Task.WhenAll(t1);
Console.WriteLine("Result of reception: " + t1.Result);
await Task.WhenAll(t1);
return t1.Result;
});
t.PipeTo(_receptionist, Self);
//t.Wait();
}
}
}
public class Receptionist : UntypedActor
{
protected override void Unhandled(object message)
{
Console.WriteLine("Message received " + message);
}
protected override void OnReceive(object message)
{
Console.WriteLine("Message received " + message);
if (message is ActorIdentity)
{
Console.WriteLine("Actor has an identity");
}
if (message is BadgeRequest)
{
Console.WriteLine("BadgeRequest from " + Sender.ToString());
var badgeRequest = message as BadgeRequest;
var badge = new Badge {
Id = Guid.NewGuid(),
Name = badgeRequest.Name,
ValableOn = DateTime.Now,
DeliveredBy = Self.Path.Name
};
Sender.Tell(badge);
}
}
}
class Program
{
static void Main(string[] args)
{
var system = ActorSystem.Create("MySystem");
//var accountant = system.ActorOf<Employee>("Geert");
//accountant.Tell(true);
//var plumber = system.ActorOf<Guest>("Verspecht");
//plumber.Tell("FixPlumbing");
var receptionist = system.ActorOf<Receptionist>("Klara");
if (receptionist != null) { }
var plumber = system.ActorOf<Guest>("Verspecht");
plumber.Tell("enter");
Console.ReadLine();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment