Line data Source code
1 : #region Copyright
2 : // // -----------------------------------------------------------------------
3 : // // <copyright company="Chinchilla Software Limited">
4 : // // Copyright Chinchilla Software Limited. All rights reserved.
5 : // // </copyright>
6 : // // -----------------------------------------------------------------------
7 : #endregion
8 :
9 : using System;
10 : using Akka.Actor;
11 : using cdmdotnet.Logging;
12 : using Cqrs.Akka.Domain;
13 : using Cqrs.Akka.Events;
14 : using Cqrs.Authentication;
15 : using Cqrs.Domain;
16 : using Cqrs.Events;
17 :
18 : namespace Cqrs.Akka.Tests.Unit.Events.Handlers
19 : {
20 : /// <summary>
21 : /// Handles the <see cref="HelloWorldRepliedTo"/>.
22 : /// </summary>
23 : public class HelloWorldRepliedToEventHandler
24 : : IEventHandler<Guid, HelloWorldRepliedTo>
25 1 : {
26 : /// <summary>
27 : /// Instantiates the <see cref="HelloWorldRepliedToEventHandler"/> class registering any <see cref="ReceiveActor.Receive{T}(System.Func{T,System.Threading.Tasks.Task})"/> required.
28 : /// </summary>
29 1 : public HelloWorldRepliedToEventHandler(IAkkaAggregateResolver aggregateResolver)
30 : {
31 : AggregateResolver = aggregateResolver;
32 : }
33 :
34 : /// <summary>
35 : /// Resolves Akka.Net actor based <see cref="IAggregateRoot{TAuthenticationToken}"/>
36 : /// </summary>
37 : protected IAkkaAggregateResolver AggregateResolver { get; private set; }
38 :
39 : #region Implementation of IMessageHandler<in HelloWorldRepliedTo>
40 :
41 : /// <summary>
42 : /// Responds to the provided <paramref name="message"/> passing the <paramref name="message"/> to an Akka.Net actor.
43 : /// </summary>
44 : /// <param name="message">The <see cref="HelloWorldRepliedTo"/> to respond to or "handle"</param>
45 1 : public void Handle(HelloWorldRepliedTo message)
46 : {
47 : IActorRef item = AggregateResolver.ResolveActor<HelloWorldRepliedToEventHandlerActor>();
48 : bool result = item.Ask<bool>(message).Result;
49 : // item.Tell(message);
50 : }
51 :
52 : #endregion
53 : }
54 :
55 : /// <summary>
56 : /// An Akka.Net based <see cref="IEventHandler"/> that handles the <see cref="HelloWorldRepliedTo"/>.
57 : /// </summary>
58 : public class HelloWorldRepliedToEventHandlerActor
59 : : AkkaEventHandler<Guid>
60 1 : {
61 : #region Implementation of IMessageHandler<in HelloWorldRepliedTo>
62 :
63 : /// <summary>
64 : /// Responds to the provided <paramref name="message"/>.
65 : /// </summary>
66 : /// <param name="message">The <see cref="HelloWorldRepliedTo"/> to respond to or "handle"</param>
67 1 : public void Handle(HelloWorldRepliedTo message)
68 : {
69 : AkkaUnitTests.Step2Reached[message.CorrelationId] = true;
70 : }
71 :
72 : #endregion
73 :
74 : /// <summary>
75 : /// Instantiates a new instance of <see cref="HelloWorldRepliedToEventHandlerActor"/>.
76 : /// </summary>
77 1 : public HelloWorldRepliedToEventHandlerActor(ILogger logger, ICorrelationIdHelper correlationIdHelper, IAuthenticationTokenHelper<Guid> authenticationTokenHelper)
78 : : base(logger, correlationIdHelper, authenticationTokenHelper)
79 : {
80 : Receive<HelloWorldRepliedTo>(@event => Execute(Handle, @event));
81 : }
82 : }
83 : }
|