1
0
mirror of synced 2024-11-05 02:59:16 +00:00
Tapeti/Test/MarcoController.cs
Mark van Renswoude 6779f3a4d0 Added AppSettings ConnectionParams helper
Changed BindingFilters to MessageFilterMiddleware (in preparation for SignalR interaction package)
Start of SqlConnectionFlowRepository
2017-02-08 15:52:24 +01:00

108 lines
3.0 KiB
C#

using System;
using System.Threading.Tasks;
using Tapeti;
using Tapeti.Annotations;
using Tapeti.Flow;
using Tapeti.Flow.Annotations;
namespace Test
{
[MessageController]
[DynamicQueue]
public class MarcoController
{
private readonly IPublisher publisher;
private readonly IFlowProvider flowProvider;
private readonly Visualizer visualizer;
// Public properties are automatically stored and retrieved while in a flow
public Guid StateTestGuid;
public MarcoController(IPublisher publisher, IFlowProvider flowProvider, Visualizer visualizer)
{
this.publisher = publisher;
this.flowProvider = flowProvider;
this.visualizer = visualizer;
}
/**
* The Visualizer could've been injected through the constructor, which is
* the recommended way. Just testing the injection middleware here.
*/
public async Task<IYieldPoint> Marco(MarcoMessage message, Visualizer myVisualizer)
{
Console.WriteLine(">> Marco (yielding with request)");
await myVisualizer.VisualizeMarco();
return flowProvider.YieldWithRequestSync<PoloConfirmationRequestMessage, PoloConfirmationResponseMessage>(
new PoloConfirmationRequestMessage()
{
StoredInState = StateTestGuid
},
HandlePoloConfirmationResponse);
}
[Continuation]
public IYieldPoint HandlePoloConfirmationResponse(PoloConfirmationResponseMessage message)
{
Console.WriteLine(">> HandlePoloConfirmationResponse (ending flow)");
Console.WriteLine(message.ShouldMatchState.Equals(StateTestGuid) ? "Confirmed!" : "Oops! Mismatch!");
return flowProvider.EndWithResponse(new PoloMessage());
}
/**
* For simple request response patterns, the return type can be used.
* This will automatically include the correlationId in the response and
* use the replyTo header of the request if provided.
*/
public PoloConfirmationResponseMessage PoloConfirmation(PoloConfirmationRequestMessage message)
{
Console.WriteLine(">> PoloConfirmation (returning confirmation)");
return new PoloConfirmationResponseMessage
{
ShouldMatchState = message.StoredInState
};
}
public void Polo(PoloMessage message)
{
Console.WriteLine(">> Polo");
StateTestGuid = Guid.NewGuid();
}
}
[Request(Response = typeof(PoloMessage))]
public class MarcoMessage
{
}
public class PoloMessage
{
}
[Request(Response = typeof(PoloConfirmationResponseMessage))]
public class PoloConfirmationRequestMessage
{
public Guid StoredInState { get; set; }
}
public class PoloConfirmationResponseMessage
{
public Guid ShouldMatchState { get; set; }
}
}