Line data Source code
1 : using System;
2 : using Akka.Actor;
3 : using Cqrs.Akka.Domain;
4 : using Cqrs.Akka.Tests.Unit.Events;
5 : using Cqrs.Domain;
6 : using Cqrs.Events;
7 :
8 : namespace Cqrs.Akka.Tests.Unit.Sagas
9 : {
10 : /// <summary>
11 : /// An <see cref="IEventHandler"/> that passes the <see cref="IEvent{TAuthenticationToken}"/> instances it receives to <see cref="ConversationReportProcessManager"/>
12 : /// </summary>
13 : public class ConversationReportProcessManagerEventHandlers
14 : : IEventHandler<Guid, HelloWorldSaid>
15 : , IEventHandler<Guid, HelloWorldRepliedTo>
16 : , IEventHandler<Guid, ConversationEnded>
17 1 : {
18 : /// <summary>
19 : /// Instantiates the <see cref="ConversationReportProcessManagerEventHandlers"/> class registering any <see cref="ReceiveActor.Receive{T}(System.Func{T,System.Threading.Tasks.Task})"/> required.
20 : /// </summary>
21 1 : public ConversationReportProcessManagerEventHandlers(IAkkaSagaResolver sagaResolver)
22 : {
23 : SagaResolver = sagaResolver;
24 : }
25 :
26 : /// <summary>
27 : /// Resolves Akka.Net actor based <see cref="ISaga{TAuthenticationToken}"/>
28 : /// </summary>
29 : protected IAkkaSagaResolver SagaResolver { get; private set; }
30 :
31 : #region Implementation of IMessageHandler<in HelloWorldRepliedTo>
32 :
33 : /// <summary>
34 : /// Responds to the provided <paramref name="message"/>.
35 : /// </summary>
36 : /// <param name="message">The <see cref="IEvent{TAuthenticationToken}"/> to respond to or "handle"</param>
37 1 : protected virtual void HandleEvent(IEvent<Guid> message)
38 : {
39 : // Resolve and locate the instance of the Saga to pass the message to
40 : IActorRef item = SagaResolver.ResolveActor<ConversationReportProcessManager, Guid>(message.Id);
41 : // Pass the message to it (and wait?)
42 : bool result = item.Ask<bool>(message).Result;
43 : // item.Tell(message);
44 : }
45 :
46 : /// <summary>
47 : /// Responds to the provided <paramref name="message"/>.
48 : /// </summary>
49 : /// <param name="message">The <see cref="HelloWorldRepliedTo"/> to respond to or "handle"</param>
50 1 : public void Handle(HelloWorldRepliedTo message)
51 : {
52 : HandleEvent(message);
53 : }
54 :
55 : #endregion
56 :
57 : #region Implementation of IMessageHandler<in HelloWorldSaid>
58 :
59 : /// <summary>
60 : /// Responds to the provided <paramref name="message"/>.
61 : /// </summary>
62 : /// <param name="message">The <see cref="HelloWorldSaid"/> to respond to or "handle"</param>
63 1 : public void Handle(HelloWorldSaid message)
64 : {
65 : HandleEvent(message);
66 : }
67 :
68 : #endregion
69 :
70 : #region Implementation of IMessageHandler<in ConversationEnded>
71 :
72 : /// <summary>
73 : /// Responds to the provided <paramref name="message"/>.
74 : /// </summary>
75 : /// <param name="message">The <see cref="ConversationEnded"/> to respond to or "handle"</param>
76 1 : public void Handle(ConversationEnded message)
77 : {
78 : HandleEvent(message);
79 : }
80 :
81 : #endregion
82 : }
83 : }
|