2019-08-16 11:47:57 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using ExampleLib;
|
|
|
|
|
using SimpleInjector;
|
|
|
|
|
using Tapeti;
|
|
|
|
|
using Tapeti.DataAnnotations;
|
|
|
|
|
using Tapeti.Default;
|
|
|
|
|
using Tapeti.Flow;
|
|
|
|
|
using Tapeti.SimpleInjector;
|
|
|
|
|
|
|
|
|
|
namespace _03_FlowRequestResponse
|
|
|
|
|
{
|
|
|
|
|
public class Program
|
|
|
|
|
{
|
2022-02-09 09:19:56 +01:00
|
|
|
|
public static void Main()
|
2019-08-16 11:47:57 +02:00
|
|
|
|
{
|
|
|
|
|
var container = new Container();
|
|
|
|
|
var dependencyResolver = new SimpleInjectorDependencyResolver(container);
|
|
|
|
|
|
|
|
|
|
container.Register<ILogger, ConsoleLogger>();
|
|
|
|
|
|
2021-03-16 10:54:15 +01:00
|
|
|
|
var helper = new ExampleConsoleApp(dependencyResolver, 2);
|
2019-08-16 11:47:57 +02:00
|
|
|
|
helper.Run(MainAsync);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal static async Task MainAsync(IDependencyResolver dependencyResolver, Func<Task> waitForDone)
|
|
|
|
|
{
|
|
|
|
|
var config = new TapetiConfig(dependencyResolver)
|
|
|
|
|
.WithDataAnnotations()
|
|
|
|
|
.WithFlow()
|
|
|
|
|
.RegisterAllControllers()
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
|
2022-02-09 09:19:56 +01:00
|
|
|
|
await using var connection = new TapetiConnection(config);
|
|
|
|
|
|
|
|
|
|
// Must be called before using any flow. When using a persistent repository like the
|
|
|
|
|
// SQL server implementation, you can run any required update scripts (for example, using DbUp)
|
|
|
|
|
// before calling this Load method.
|
|
|
|
|
// Call after creating the TapetiConnection, as it modifies the container to inject IPublisher.
|
|
|
|
|
await dependencyResolver.Resolve<IFlowStore>().Load();
|
2019-08-16 11:47:57 +02:00
|
|
|
|
|
|
|
|
|
|
2022-02-09 09:19:56 +01:00
|
|
|
|
await connection.Subscribe();
|
2019-08-16 11:47:57 +02:00
|
|
|
|
|
|
|
|
|
|
2022-02-09 09:19:56 +01:00
|
|
|
|
var flowStarter = dependencyResolver.Resolve<IFlowStarter>();
|
2019-08-16 11:47:57 +02:00
|
|
|
|
|
2022-02-09 09:19:56 +01:00
|
|
|
|
var startData = new SimpleFlowController.StartData
|
|
|
|
|
{
|
|
|
|
|
RequestStartTime = DateTime.Now,
|
|
|
|
|
Amount = 1
|
|
|
|
|
};
|
2019-08-16 11:47:57 +02:00
|
|
|
|
|
|
|
|
|
|
2022-02-09 09:19:56 +01:00
|
|
|
|
await flowStarter.Start<SimpleFlowController, SimpleFlowController.StartData>(c => c.StartFlow, startData);
|
|
|
|
|
await flowStarter.Start<ParallelFlowController>(c => c.StartFlow);
|
2019-08-16 11:47:57 +02:00
|
|
|
|
|
|
|
|
|
|
2022-02-09 09:19:56 +01:00
|
|
|
|
// Wait for the controller to signal that the message has been received
|
|
|
|
|
await waitForDone();
|
2019-08-16 11:47:57 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|