Esempio n. 1
0
        public async Task InsertGameEvent(GameEvent gameEvent)
        {
            if (gameEvent == null)
            {
                throw new ArgumentNullException("gameEvent");
            }

            using (var transactionScope = _transactionScopeFactory.Create())
            {
                using (var connection = await _connectionFactory.CreateConnectionAsync())
                {
                    // Insert event.
                    const string insertGameEventSql = "INSERT INTO GameEvents(Id, GameId, UserId, Body, Version) " +
                                                      "VALUES(@Id, @GameId, @userId, @body, @Version);";

                    var wrapper = gameEventMapper.MapToGameEventWrapper(gameEvent);
                    await connection.ExecuteAsync(insertGameEventSql, new { wrapper.Id, wrapper.GameId, wrapper.UserId, body = wrapper.Body, wrapper.Version });

                    //// Update snapshot.                
                    //var game = await GetGameAsync(gameEvent.GameId);
                    //await connection.ExecuteAsync("dbo.InsertOrUpdateGameSnapshot", new
                    //{
                    //    gameId = game.Id,
                    //    numUsers = game.Users.Count,
                    //    size = game.Size,
                    //    currentUserId = game.CurrentUserId == Guid.Empty ? (Guid?) null : game.CurrentUserId,
                    //    status = game.Status,
                    //    version = game.Version
                    //}, commandType: CommandType.StoredProcedure);
                }

                transactionScope.Complete();
            }
        }
Esempio n. 2
0
 private void RaiseEvent(GameEvent @event)
 {
     Apply((dynamic) @event);
     _events.Enqueue(@event);
 }