forked from petabridge/akkadotnet-code-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSignalRActor.cs
67 lines (54 loc) · 1.69 KB
/
SignalRActor.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
using Akka.Actor;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
using WebCrawler.Messages.Commands;
using WebCrawler.Messages.Commands.V1;
using WebCrawler.Web.Hubs;
namespace WebCrawler.Web.Actors
{
/// <summary>
/// Actor used to wrap a signalr hub
/// </summary>
public class SignalRActor : ReceiveActor
{
#region Messages
public class DebugCluster
{
public DebugCluster(string message)
{
Message = message;
}
public string Message { get; private set; }
}
#endregion
private CrawlHub _hub;
public SignalRActor()
{
Receive<string>(str =>
{
SystemActors.CommandProcessor.Tell(new CommandProcessor.AttemptCrawl(str));
});
Receive<CommandProcessor.BadCrawlAttempt>(bad =>
{
_hub.CrawlFailed(string.Format("COULD NOT CRAWL {0}: {1}", bad.RawStr, bad.Message));
});
Receive<IStatusUpdateV1>(status =>
{
_hub.PushStatus(status);
});
Receive<IStartJobV1>(start =>
{
_hub.WriteRawMessage(string.Format("Starting crawl of {0}", start.Job.Root.ToString()));
});
Receive<DebugCluster>(debug =>
{
_hub.WriteRawMessage(string.Format("DEBUG: {0}", debug.Message));
});
}
protected override void PreStart()
{
var hubManager = new DefaultHubManager(GlobalHost.DependencyResolver);
_hub = hubManager.ResolveHub("crawlHub") as CrawlHub;
}
}
}