Exemple #1
0
    public async static Task Run(CancellationToken cancellation)
    {
        var engines = Configuration.Value.GetSection($"{nameof(PollerOptions)}").Get <Collection <PollerOptions> >();
        var hosts   = new List <IHost>()
        {
            Host.CreateDefaultBuilder().ConfigureHealthCheck()
        };

        foreach (var engine in Engine.ToList(engines?.Select(e => e.Engine)))
        {
            var host = EngineHostBuilder.ResolveAndBuild(engine);

            hosts.Add(host);
        }

        var tasks =
            hosts.Select(host =>
        {
            var childSource = CancellationTokenSource.CreateLinkedTokenSource(cancellation);

            return(RunHost(host, childSource.Token));
        });

        await Task.WhenAll(tasks);
    }
        public void Should_build_supported_hosts(string engineName, string hostName)
        {
            var engine = Engine.FromName(engineName);

            var host    = EngineHostBuilder.ResolveAndBuild(engine);
            var appHost = host.Services.GetService(typeof(IHostedService));

            Assert.NotNull(appHost);
            Assert.Equal(hostName, appHost.GetType().Name);

            host.Dispose();
        }
 public void Should_throw_NotSupportedEngineException_when_creating_host()
 {
     Assert.Throws <NotSupportedEngineException>(() => EngineHostBuilder.ResolveAndBuild(Engine.Unsupported));
 }