forked from petabridge/akka-bootcamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConsoleWriterActor.cs
35 lines (31 loc) · 1.1 KB
/
ConsoleWriterActor.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
using System;
using Akka.Actor;
namespace WinTail
{
/// <summary>
/// Actor responsible for serializing message writes to the console.
/// (write one message at a time, champ :)
/// </summary>
class ConsoleWriterActor : UntypedActor
{
protected override void OnReceive(object message)
{
var msg = message as string;
// make sure we got a message
if (string.IsNullOrEmpty(msg))
{
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine("Please provide an input.\n");
Console.ResetColor();
return;
}
// if message has even # characters, display in red; else, green
var even = msg.Length % 2 == 0;
var color = even ? ConsoleColor.Red : ConsoleColor.Green;
var alert = even ? "Your string had an even # of characters.\n" : "Your string had an odd # of characters.\n";
Console.ForegroundColor = color;
Console.WriteLine(alert);
Console.ResetColor();
}
}
}