2016-12-07 09:19:16 +00:00
|
|
|
|
using System;
|
2017-01-31 11:01:08 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2016-12-07 09:19:16 +00:00
|
|
|
|
using Tapeti;
|
|
|
|
|
using Tapeti.Annotations;
|
2017-01-31 11:01:08 +00:00
|
|
|
|
using Tapeti.Flow;
|
|
|
|
|
using Tapeti.Flow.Annotations;
|
2016-12-07 09:19:16 +00:00
|
|
|
|
|
|
|
|
|
namespace Test
|
|
|
|
|
{
|
|
|
|
|
[DynamicQueue]
|
|
|
|
|
public class MarcoController : MessageController
|
|
|
|
|
{
|
|
|
|
|
private readonly IPublisher publisher;
|
2017-01-31 11:01:08 +00:00
|
|
|
|
private readonly IFlowProvider flowProvider;
|
|
|
|
|
private readonly Visualizer visualizer;
|
2016-12-07 09:19:16 +00:00
|
|
|
|
|
2017-01-31 11:01:08 +00:00
|
|
|
|
// Public properties are automatically stored and retrieved while in a flow
|
|
|
|
|
public Guid StateTestGuid;
|
2016-12-07 09:19:16 +00:00
|
|
|
|
|
2017-01-31 11:01:08 +00:00
|
|
|
|
|
|
|
|
|
public MarcoController(IPublisher publisher, IFlowProvider flowProvider, Visualizer visualizer)
|
2016-12-07 09:19:16 +00:00
|
|
|
|
{
|
|
|
|
|
this.publisher = publisher;
|
2017-01-31 11:01:08 +00:00
|
|
|
|
this.flowProvider = flowProvider;
|
|
|
|
|
this.visualizer = visualizer;
|
2016-12-07 09:19:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-01-31 11:01:08 +00:00
|
|
|
|
/**
|
|
|
|
|
* The Visualizer could've been injected through the constructor, which is
|
|
|
|
|
* the recommended way. Just testing the injection middleware here.
|
|
|
|
|
*/
|
|
|
|
|
public async Task Marco(MarcoMessage message, Visualizer myVisualizer)
|
2016-12-07 09:19:16 +00:00
|
|
|
|
{
|
2017-01-31 11:01:08 +00:00
|
|
|
|
await myVisualizer.VisualizeMarco();
|
|
|
|
|
await publisher.Publish(new PoloMessage());
|
2016-12-07 09:19:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-01-31 11:01:08 +00:00
|
|
|
|
public IYieldPoint Polo(PoloMessage message)
|
2016-12-07 09:19:16 +00:00
|
|
|
|
{
|
2017-01-31 11:01:08 +00:00
|
|
|
|
StateTestGuid = Guid.NewGuid();
|
|
|
|
|
|
|
|
|
|
return flowProvider.YieldWithRequest<PoloConfirmationRequestMessage, PoloConfirmationResponseMessage>(
|
|
|
|
|
new PoloConfirmationRequestMessage()
|
|
|
|
|
{
|
|
|
|
|
StoredInState = StateTestGuid
|
|
|
|
|
},
|
|
|
|
|
HandlePoloConfirmationResponse);
|
|
|
|
|
}
|
2016-12-07 09:19:16 +00:00
|
|
|
|
|
|
|
|
|
|
2017-01-31 11:01:08 +00:00
|
|
|
|
public async Task<IYieldPoint> HandlePoloConfirmationResponse(PoloConfirmationResponseMessage message)
|
|
|
|
|
{
|
|
|
|
|
await visualizer.VisualizePolo(message.ShouldMatchState.Equals(StateTestGuid));
|
|
|
|
|
return flowProvider.End();
|
|
|
|
|
}
|
2016-12-07 09:19:16 +00:00
|
|
|
|
|
|
|
|
|
|
2017-01-31 11:01:08 +00:00
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2016-12-07 09:19:16 +00:00
|
|
|
|
|
2017-01-31 11:01:08 +00:00
|
|
|
|
public PoloConfirmationResponseMessage PoloConfirmation(PoloConfirmationRequestMessage message)
|
2016-12-07 09:19:16 +00:00
|
|
|
|
{
|
2017-01-31 11:01:08 +00:00
|
|
|
|
return new PoloConfirmationResponseMessage
|
|
|
|
|
{
|
|
|
|
|
ShouldMatchState = message.StoredInState
|
|
|
|
|
};
|
2016-12-07 09:19:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class MarcoMessage
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class PoloMessage
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-01-31 11:01:08 +00:00
|
|
|
|
[Request(Response = typeof(PoloConfirmationResponseMessage))]
|
|
|
|
|
public class PoloConfirmationRequestMessage
|
2016-12-07 09:19:16 +00:00
|
|
|
|
{
|
2017-01-31 11:01:08 +00:00
|
|
|
|
public Guid StoredInState { get; set; }
|
2016-12-07 09:19:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-01-31 11:01:08 +00:00
|
|
|
|
public class PoloConfirmationResponseMessage
|
|
|
|
|
{
|
|
|
|
|
public Guid ShouldMatchState { get; set; }
|
2016-12-07 09:19:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|