Exemple #1
0
        private static async Task Run(WaitHandle done, CancellationToken cancellationToken)
        {
            // Run
            var tasks = new List <Task>();

            using (var host = CreateWebHost())
            {
                Metrics.Instance = host.Services.GetRequiredService <IMetrics>();

                // Dependencies
                var connectionStringBuilder = new SqlConnectionStringBuilder(
                    "Server=(local);Initial Catalog=EventStore;Integrated Security=SSPI;Connection Timeout=60;");
                var connectionProvider = new ConnectionProvider(connectionStringBuilder);
                var dbStore            = new DbStore(connectionProvider);

                // Init
                await dbStore.PrepareDatabaseAsync(cancellationToken);

                await dbStore.ClearEventsAsync(cancellationToken);

                foreach (var appConfig in CreateApplications())
                {
                    var app = new Application(dbStore, appConfig);
                    Task.Run(() => app.Start(cancellationToken));
                }

                tasks.Add(host.StartAsync(cancellationToken));

                done.WaitOne();
            }

            await Task.WhenAll(tasks);
        }