Ejemplo n.º 1
0
 public Engine(
     ILogger <Engine> logger,
     ITwitchBot twitchBot,
     IGameManager gameManager,
     IGameData gameData,
     IReplayProvider replayProvider,
     CancellationTokenProvider consoleTokenProvider)
 {
     this.logger               = logger ?? throw new ArgumentNullException(nameof(logger));
     this.twitchBot            = twitchBot ?? throw new ArgumentNullException(nameof(twitchBot));
     this.gameManager          = gameManager ?? throw new ArgumentNullException(nameof(gameManager));
     this.gameData             = gameData ?? throw new ArgumentNullException(nameof(gameData));
     this.replayProvider       = replayProvider ?? throw new ArgumentNullException(nameof(replayProvider));
     this.consoleTokenProvider = consoleTokenProvider ?? throw new ArgumentNullException(nameof(consoleTokenProvider));
 }
Ejemplo n.º 2
0
        protected async Task CommandAsync(CancellationToken cancellationToken)
        {
            using (ServiceProvider provider = new ServiceCollection().AddTwitchServices(cancellationToken).BuildServiceProvider(new ServiceProviderOptions {
                ValidateScopes = true, ValidateOnBuild = true
            }))
            {
                using (IServiceScope scope = provider.CreateScope())
                {
                    using (var waiter = new ManualResetEventSlim())
                    {
                        // Initialize data
                        var gameData = scope.ServiceProvider.GetRequiredService <IGameData>();
                        await gameData.LoadDataAsync();

                        ITwitchBot twitchBot = scope.ServiceProvider.GetRequiredService <ITwitchBot>();
                        await twitchBot.InitializeAsync();

                        waiter.Wait(cancellationToken);
                    }
                }
            }
        }