2017-07-25 13:50:38 +00:00
|
|
|
|
using System;
|
|
|
|
|
using Tapeti.Annotations;
|
|
|
|
|
using Tapeti.Flow;
|
2017-09-07 07:55:26 +00:00
|
|
|
|
using Tapeti.Flow.Annotations;
|
2017-07-25 13:50:38 +00:00
|
|
|
|
|
2018-12-19 19:50:56 +00:00
|
|
|
|
// ReSharper disable UnusedMember.Global
|
|
|
|
|
|
2017-07-25 13:50:38 +00:00
|
|
|
|
namespace Test
|
|
|
|
|
{
|
|
|
|
|
[MessageController]
|
|
|
|
|
[DynamicQueue]
|
|
|
|
|
public class FlowEndController
|
|
|
|
|
{
|
|
|
|
|
private readonly IFlowProvider flowProvider;
|
|
|
|
|
|
|
|
|
|
public FlowEndController(IFlowProvider flowProvider)
|
|
|
|
|
{
|
|
|
|
|
this.flowProvider = flowProvider;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 18:48:40 +00:00
|
|
|
|
|
|
|
|
|
[Start]
|
2017-07-25 13:50:38 +00:00
|
|
|
|
public IYieldPoint StartFlow(PingMessage message)
|
|
|
|
|
{
|
2017-09-07 07:55:26 +00:00
|
|
|
|
Console.WriteLine("PingMessage received, calling flowProvider.End() directly");
|
|
|
|
|
|
|
|
|
|
if (DateTime.Now < new DateTime(2000, 1, 1))
|
|
|
|
|
{
|
|
|
|
|
//never true
|
|
|
|
|
return flowProvider
|
|
|
|
|
.YieldWithRequestSync<PingConfirmationRequestMessage, PingConfirmationResponseMessage>
|
|
|
|
|
(new PingConfirmationRequestMessage() { StoredInState = "Ping:" },
|
|
|
|
|
HandlePingConfirmationResponse);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Finish();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Continuation]
|
|
|
|
|
public IYieldPoint HandlePingConfirmationResponse(PingConfirmationResponseMessage msg)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Ending ping flow: " + msg.Answer);
|
2017-07-25 13:50:38 +00:00
|
|
|
|
return Finish();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private IYieldPoint Finish()
|
|
|
|
|
{
|
|
|
|
|
return flowProvider.End();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class PingMessage
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-07 07:55:26 +00:00
|
|
|
|
[Request(Response = typeof(PingConfirmationResponseMessage))]
|
|
|
|
|
public class PingConfirmationRequestMessage
|
|
|
|
|
{
|
|
|
|
|
public string StoredInState { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class PingConfirmationResponseMessage
|
|
|
|
|
{
|
|
|
|
|
public string Answer { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PingConfirmationResponseMessage PingConfirmation(PingConfirmationRequestMessage message)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(">> receive Ping (returning pong)");
|
|
|
|
|
|
|
|
|
|
return new PingConfirmationResponseMessage
|
|
|
|
|
{
|
|
|
|
|
Answer = message.StoredInState + " Pong!"
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-07-25 13:50:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|