public GameServer(IChessService chessService, IGameMiddleware gameMiddleware, IGameHelper gameHelper) { this.chessService = chessService; this.gameMiddleware = gameMiddleware; this.gameHelper = gameHelper; Thread thread = new Thread(StartServer); thread.Start(); }
public ChessBoardPresentationModel(ChessBoard chessboard, IChessService chessService) { this.chessService = chessService; this.chessService.MoveCompleted += this.ChessService_MoveCompleted; this.chessService.ResetCompleted += (sender, e) => { if (e.Error == null) { this.View.DrawBoard(e.Board); } }; this.View = chessboard; this.View.Model = this; this.Reset(); }
public async Task MainAsync() { var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json").Build(); _client = new DiscordSocketClient(); _commands = new CommandService(); _client.Log += Log; string token = config["token"]; int timeout = 30000; int.TryParse(config["confirmationsTimeout"], out timeout); _services = new ServiceCollection() .AddSingleton <IAssetService, AssetService>() .AddSingleton <IChessService, ChessService>(s => new ChessService(timeout, s.GetService <IAssetService>())) .AddSingleton <ChessGame, ChessGame>() .AddSingleton(_client) .AddSingleton(_commands) .BuildServiceProvider(); _chessService = _services.GetService <IChessService>(); await InstallCommandsAsync(); await _client.LoginAsync(TokenType.Bot, token); await _client.StartAsync(); // Block this task until the program is closed. await Task.Delay(-1); }
public ShutdownCommand(IAuthorizationService authorizationService, IChessService chessService) : base(authorizationService) { _authorizationService = authorizationService; _chessService = chessService; }
public ShowCommand(IChessService chessService) { _chessService = chessService; }
public ResignCommand(IChessService chessService) { _chessService = chessService; }
public ChessCommands(IChessService chessService, IServiceProvider services, Db db) { _services = services; _chessService = chessService; _db = db; }
public ChessController(IChessService service, IRepository <User> repository) { _chessService = service; _repository = repository; }
public async Task MainAsync() { var config = GetConfiguration(); _client = new DiscordSocketClient(); _commands = new CommandService(); _client.Log += Log; string token = config["token"]; var adminUsernamesCsv = config["admins"]; var adminUsernames = adminUsernamesCsv?.Split(',') ?? new string[] {}; int timeout; if (!int.TryParse(config["confirmationsTimeout"], out timeout)) { timeout = 30000; } var discordBotsApiKey = config["discordBotsApiKey"]; var discordBotsBotId = config["discordBotsBotId"]; _services = new ServiceCollection() .AddSingleton <IAssetService, AssetService>() .AddSingleton <IDiscordBotsService, DiscordBotsService>(s => new DiscordBotsService(discordBotsApiKey, discordBotsBotId)) .AddSingleton <IChessService, ChessService>(s => new ChessService(timeout, s.GetService <IAssetService>(), _services)) .AddSingleton <ChessGame, ChessGame>() .AddSingleton(_client) .AddSingleton(_commands) .AddEntityFrameworkNpgsql().AddDbContext <Db>(options => options.UseNpgsql(config["Db"]), ServiceLifetime.Transient) .BuildServiceProvider(); _chessService = _services.GetService <IChessService>(); await InstallCommandsAsync(); await _client.LoginAsync(TokenType.Bot, token); await _client.StartAsync(); if (!string.IsNullOrEmpty(discordBotsApiKey)) { var discordBotsService = _services.GetService <IDiscordBotsService>(); async Task postStats() { await discordBotsService.UpdateStats(_client.Guilds.Count); }; _client.Ready += postStats; _client.JoinedGuild += async(c) => { await postStats(); }; _client.LeftGuild += async(c) => { await postStats(); }; } _client.Ready += async() => { await Task.Run(async() => { using (var db = _services.GetService <Db>()) { var matches = new List <ChessMatch>(); foreach (var match in db.Matches) { matches.Add(JsonConvert.DeserializeObject <ChessMatch>(match.matchjson)); } await _chessService.LoadState(matches, _client); } }); }; //Just a convenient way to pre-load EF related dlls. #pragma warning disable 4014 Task.Run(() => { using (var db = _services.GetService <Db>()) db.Matches.Count(); }); #pragma warning restore 4014 ShutdownEvent.WaitOne(); await _chessService.SaveMatches(); await _client.SetGameAsync(null); await _client.StopAsync(); await _client.LogoutAsync(); }
public UndoCommand(IChessService chessService) { _chessService = chessService; }
public AcceptCommand(IChessService chessService) { _chessService = chessService; }
public MoveCommand(IChessService chessService) { _chessService = chessService; }
public ChallengeCommand(IChessService chessService) { _chessService = chessService; }
public GameHelper(IChessService chessService) { this.chessService = chessService; gameTasks = new List <GameTask>(); }
public ChessController(IChessService chessService, IPwdManService pwdManService) { ChessService = chessService; PwdManService = pwdManService; }
public async Task MainAsync() { var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json").Build(); _client = new DiscordSocketClient(); _commands = new CommandService(); _client.Log += Log; string token = config["token"]; var adminUsernamesCsv = config["admins"]; var adminUsernames = adminUsernamesCsv?.Split(',') ?? new string[] {}; int timeout; if (!int.TryParse(config["confirmationsTimeout"], out timeout)) { timeout = 30000; } _services = new ServiceCollection() .AddSingleton <IAssetService, AssetService>() .AddSingleton <IChessService, ChessService>(s => new ChessService(timeout, s.GetService <IAssetService>())) .AddSingleton <IAuthorizationService, AuthorizationService>(s => new AuthorizationService(adminUsernames)) .AddSingleton <ChessGame, ChessGame>() .AddSingleton(_client) .AddSingleton(_commands) .BuildServiceProvider(); _chessService = _services.GetService <IChessService>(); await InstallCommandsAsync(); await _client.LoginAsync(TokenType.Bot, token); await _client.StartAsync(); var stateFilePath = Path.Combine(Directory.GetCurrentDirectory(), "state.json"); _client.Ready += async() => { if (System.IO.File.Exists(stateFilePath)) { var deserializedMatches = JsonConvert.DeserializeObject <List <ChessMatch> >(System.IO.File.ReadAllText(stateFilePath)); await _chessService.LoadState(deserializedMatches, _client); } }; ShutdownEvent.WaitOne(); System.IO.File.WriteAllText(stateFilePath, JsonConvert.SerializeObject(_chessService.Matches)); await _client.SetGameAsync(null); await _client.StopAsync(); await _client.LogoutAsync(); }