2016-12-07 10:19:16 +01:00
|
|
|
|
using System;
|
2017-02-12 21:43:30 +01:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2017-01-31 12:01:08 +01:00
|
|
|
|
using System.Threading.Tasks;
|
2016-12-07 10:19:16 +01:00
|
|
|
|
using Tapeti.Annotations;
|
2017-01-31 12:01:08 +01:00
|
|
|
|
using Tapeti.Flow;
|
|
|
|
|
using Tapeti.Flow.Annotations;
|
2016-12-07 10:19:16 +01:00
|
|
|
|
|
2018-12-19 20:50:56 +01:00
|
|
|
|
// ReSharper disable UnusedMember.Global
|
|
|
|
|
|
2016-12-07 10:19:16 +01:00
|
|
|
|
namespace Test
|
|
|
|
|
{
|
2017-02-08 15:52:24 +01:00
|
|
|
|
[MessageController]
|
2016-12-07 10:19:16 +01:00
|
|
|
|
[DynamicQueue]
|
2017-02-08 15:52:24 +01:00
|
|
|
|
public class MarcoController
|
2016-12-07 10:19:16 +01:00
|
|
|
|
{
|
2018-12-19 20:50:56 +01:00
|
|
|
|
//private readonly IPublisher publisher;
|
2017-01-31 12:01:08 +01:00
|
|
|
|
private readonly IFlowProvider flowProvider;
|
2018-12-19 20:50:56 +01:00
|
|
|
|
//private readonly Visualizer visualizer;
|
2016-12-07 10:19:16 +01:00
|
|
|
|
|
2017-01-31 12:01:08 +01:00
|
|
|
|
// Public properties are automatically stored and retrieved while in a flow
|
2017-07-24 10:21:34 +02:00
|
|
|
|
public Guid StateTestGuid { get; set; }
|
2016-12-07 10:19:16 +01:00
|
|
|
|
|
2017-10-17 10:34:07 +02:00
|
|
|
|
public int Phase;
|
2017-01-31 12:01:08 +01:00
|
|
|
|
|
2018-12-19 20:50:56 +01:00
|
|
|
|
public MarcoController(/*IPublisher publisher, */IFlowProvider flowProvider/*, Visualizer visualizer*/)
|
2016-12-07 10:19:16 +01:00
|
|
|
|
{
|
2018-12-19 20:50:56 +01:00
|
|
|
|
//this.publisher = publisher;
|
2017-01-31 12:01:08 +01:00
|
|
|
|
this.flowProvider = flowProvider;
|
2018-12-19 20:50:56 +01:00
|
|
|
|
//this.visualizer = visualizer;
|
2016-12-07 10:19:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-02-15 22:05:01 +01:00
|
|
|
|
[Start]
|
2017-09-22 11:19:49 +02:00
|
|
|
|
public async Task<IYieldPoint> StartFlow(bool go)
|
2017-02-15 22:05:01 +01:00
|
|
|
|
{
|
2017-10-17 10:34:07 +02:00
|
|
|
|
Console.WriteLine("Phase = " + Phase + " Starting stand-alone flow");
|
|
|
|
|
await Task.Delay(10);
|
|
|
|
|
|
|
|
|
|
Phase = 1;
|
2017-02-15 22:05:01 +01:00
|
|
|
|
|
2017-09-22 11:19:49 +02:00
|
|
|
|
if (go)
|
|
|
|
|
return flowProvider.YieldWithRequestSync<PoloConfirmationRequestMessage, PoloConfirmationResponseMessage>
|
|
|
|
|
(new PoloConfirmationRequestMessage(),
|
|
|
|
|
HandlePoloConfirmationResponse);
|
|
|
|
|
|
2017-10-17 10:34:07 +02:00
|
|
|
|
Console.WriteLine("Phase = " + Phase + " Ending stand-alone flow prematurely");
|
2017-09-22 11:19:49 +02:00
|
|
|
|
return flowProvider.End();
|
2017-02-15 22:05:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Continuation]
|
|
|
|
|
public IYieldPoint HandlePoloConfirmationResponse(PoloConfirmationResponseMessage msg)
|
|
|
|
|
{
|
2017-10-17 10:34:07 +02:00
|
|
|
|
Console.WriteLine("Phase = " + Phase + " Handling the first response and sending the second...");
|
|
|
|
|
|
|
|
|
|
Phase = 2;
|
|
|
|
|
|
|
|
|
|
return flowProvider.YieldWithRequestSync<PoloConfirmationRequestMessage, PoloConfirmationResponseMessage>
|
|
|
|
|
(new PoloConfirmationRequestMessage(),
|
|
|
|
|
HandlePoloConfirmationResponseEnd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Continuation]
|
|
|
|
|
public IYieldPoint HandlePoloConfirmationResponseEnd(PoloConfirmationResponseMessage msg)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Phase = " + Phase + " Handling the second response and Ending stand-alone flow");
|
2017-02-15 22:05:01 +01:00
|
|
|
|
return flowProvider.End();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-12-19 20:20:08 +01:00
|
|
|
|
[Start]
|
|
|
|
|
public IYieldPoint TestParallelRequest()
|
2016-12-07 10:19:16 +01:00
|
|
|
|
{
|
2017-02-05 23:22:34 +01:00
|
|
|
|
Console.WriteLine(">> Marco (yielding with request)");
|
2016-12-07 10:19:16 +01:00
|
|
|
|
|
2017-02-12 19:04:26 +01:00
|
|
|
|
StateTestGuid = Guid.NewGuid();
|
2018-12-19 20:20:08 +01:00
|
|
|
|
Console.WriteLine($"Starting parallel request with StateTestGuid {StateTestGuid}");
|
2017-02-12 19:04:26 +01:00
|
|
|
|
|
|
|
|
|
return flowProvider.YieldWithParallelRequest()
|
|
|
|
|
.AddRequestSync<PoloConfirmationRequestMessage, PoloConfirmationResponseMessage>(new PoloConfirmationRequestMessage
|
|
|
|
|
{
|
|
|
|
|
StoredInState = StateTestGuid
|
|
|
|
|
}, HandlePoloConfirmationResponse1)
|
2016-12-07 10:19:16 +01:00
|
|
|
|
|
2017-02-12 19:04:26 +01:00
|
|
|
|
.AddRequestSync<PoloConfirmationRequestMessage, PoloConfirmationResponseMessage>(new PoloConfirmationRequestMessage
|
2017-01-31 12:01:08 +01:00
|
|
|
|
{
|
|
|
|
|
StoredInState = StateTestGuid
|
2017-02-12 19:04:26 +01:00
|
|
|
|
}, HandlePoloConfirmationResponse2)
|
|
|
|
|
|
|
|
|
|
.YieldSync(ContinuePoloConfirmation);
|
2017-01-31 12:01:08 +01:00
|
|
|
|
}
|
2016-12-07 10:19:16 +01:00
|
|
|
|
|
|
|
|
|
|
2017-02-05 23:22:34 +01:00
|
|
|
|
[Continuation]
|
2017-02-12 19:04:26 +01:00
|
|
|
|
public void HandlePoloConfirmationResponse1(PoloConfirmationResponseMessage message)
|
2017-01-31 12:01:08 +01:00
|
|
|
|
{
|
2017-02-12 19:04:26 +01:00
|
|
|
|
Console.WriteLine(">> HandlePoloConfirmationResponse1");
|
|
|
|
|
Console.WriteLine(message.ShouldMatchState.Equals(StateTestGuid) ? "Confirmed!" : "Oops! Mismatch!");
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-05 23:22:34 +01:00
|
|
|
|
|
2017-02-12 19:04:26 +01:00
|
|
|
|
[Continuation]
|
|
|
|
|
public void HandlePoloConfirmationResponse2(PoloConfirmationResponseMessage message)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(">> HandlePoloConfirmationResponse2");
|
2017-02-05 23:22:34 +01:00
|
|
|
|
Console.WriteLine(message.ShouldMatchState.Equals(StateTestGuid) ? "Confirmed!" : "Oops! Mismatch!");
|
2017-02-12 19:04:26 +01:00
|
|
|
|
}
|
2017-02-05 23:22:34 +01:00
|
|
|
|
|
2017-02-12 19:04:26 +01:00
|
|
|
|
|
|
|
|
|
private IYieldPoint ContinuePoloConfirmation()
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("> ConvergePoloConfirmation (ending flow)");
|
2018-12-19 20:20:08 +01:00
|
|
|
|
return flowProvider.End();
|
2017-01-31 12:01:08 +01:00
|
|
|
|
}
|
2016-12-07 10:19:16 +01:00
|
|
|
|
|
|
|
|
|
|
2017-01-31 12:01:08 +01: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.
|
|
|
|
|
*/
|
2018-12-21 10:49:30 +01:00
|
|
|
|
public async Task<PoloConfirmationResponseMessage> PoloConfirmation(PoloConfirmationRequestMessage message)
|
2016-12-07 10:19:16 +01:00
|
|
|
|
{
|
2017-02-05 23:22:34 +01:00
|
|
|
|
Console.WriteLine(">> PoloConfirmation (returning confirmation)");
|
2018-12-21 10:49:30 +01:00
|
|
|
|
await Task.Delay(100);
|
2017-02-05 23:22:34 +01:00
|
|
|
|
|
2017-01-31 12:01:08 +01:00
|
|
|
|
return new PoloConfirmationResponseMessage
|
|
|
|
|
{
|
|
|
|
|
ShouldMatchState = message.StoredInState
|
|
|
|
|
};
|
2016-12-07 10:19:16 +01:00
|
|
|
|
}
|
2017-02-05 23:22:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-08-31 19:17:56 +02:00
|
|
|
|
[DynamicQueue("custom.prefix")]
|
2017-02-05 23:22:34 +01:00
|
|
|
|
public void Polo(PoloMessage message)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(">> Polo");
|
|
|
|
|
}
|
2016-12-07 10:19:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-02-05 23:22:34 +01:00
|
|
|
|
[Request(Response = typeof(PoloMessage))]
|
2016-12-07 10:19:16 +01:00
|
|
|
|
public class MarcoMessage
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class PoloMessage
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-01-31 12:01:08 +01:00
|
|
|
|
[Request(Response = typeof(PoloConfirmationResponseMessage))]
|
|
|
|
|
public class PoloConfirmationRequestMessage
|
2016-12-07 10:19:16 +01:00
|
|
|
|
{
|
2017-02-12 21:43:30 +01:00
|
|
|
|
[Required]
|
2017-01-31 12:01:08 +01:00
|
|
|
|
public Guid StoredInState { get; set; }
|
2016-12-07 10:19:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-01-31 12:01:08 +01:00
|
|
|
|
public class PoloConfirmationResponseMessage
|
|
|
|
|
{
|
2017-02-12 21:43:30 +01:00
|
|
|
|
[Required]
|
2017-01-31 12:01:08 +01:00
|
|
|
|
public Guid ShouldMatchState { get; set; }
|
2016-12-07 10:19:16 +01:00
|
|
|
|
}
|
|
|
|
|
}
|