protected override void OnStart()
        {
            _gameDataRepository.Start();

            // Initialize data in a in memory repository
            using (var writeContext = _gameDataRepository.BeginWrite())
            {
                InitTeamAndPlayerData(writeContext);
                InitGameSchedule(writeContext);
            }

            // Load all games and start the clock
            var allGames = _gameDataRepository.GetAll <Game>();


            foreach (var game in allGames)
            {
                var activeGame = new GameMetadata(game);

                _games.Add(activeGame);
            }

            //
            _clock.AccelerationFactor = 2m;
            _clock.Start();

            //
            _startableThread.Start();
        }
Esempio n. 2
0
        public ICommandResponse Handle(ISecurityContext securityContext, AddPlayerCommand command)
        {
            // TODO: Should check ISecurityContext if the user is allowed to run the command

            var player = new Player
            {
                Id     = command.Id.GetValueOrDefault(),
                Name   = command.Name,
                TeamId = command.TeamId.GetValueOrDefault(),

                Created      = DateTime.UtcNow,
                LastModified = DateTime.UtcNow,
            };

            try
            {
                using (var writeContext = _gameDataRepository.BeginWrite())
                {
                    writeContext.Insert(player);
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex, ex.Message);

                // Command did not finish correctly...
                return(new CommandResponse
                {
                    ErrorCode = 123,
                    ErrorMessage = ex.Message
                });
            }

            return(new CommandResponse());
        }