Ejemplo n.º 1
0
        public void AddNewGameData(GameData gameData)
        {
            if (null == gameData)
            {
                Trace.WriteLine(string.Format(
                                    "Invalid Game Data in Database.AddNewGameData!\n GameData is null."));

                return;
            }

            var winnerUser = GetUserFromEmailAddress(gameData.Winner);

            if (null == winnerUser)
            {
                Trace.WriteLine(string.Format(
                                    "Invalid Game Data in Database.AddNewGameData!\n Winner {0} not recognized.",
                                    gameData.Winner));

                return;
            }

            foreach (var kvp in gameData.PlayerDictionary)
            {
                var player = GetUserFromEmailAddress(kvp.Key);

                if (null == player)
                {
                    Trace.WriteLine(string.Format(
                                        "Invalid Game Data in Database.AddNewGameData!\n Player {0} not recognized.",
                                        kvp.Key));

                    return;
                }
            }

            if (gameData.GameDuration < 0)
            {
                Trace.WriteLine(string.Format(
                                    "Invalid Game Data in Database.AddNewGameData!\n GameDuration of value {0} is invalid.",
                                    gameData.GameDuration));

                return;
            }


            using (var connection = new SqlConnection(ConnectionString))
            {
                using (var db = new OzwegoDataClassesDataContext(connection))
                {
                    var newData = new game
                    {
                        winner        = winnerUser.ID,
                        gameStartTime = gameData.GameStartTime,
                        gameDuration  = gameData.GameDuration
                    };

                    // ToDo: newData.gameDataFile = ??


                    db.games.InsertOnSubmit(newData);

                    try
                    {
                        db.SubmitChanges();
                    }
                    catch (Exception e)
                    {
                        Trace.WriteLine(string.Format(
                                            "Exception in Database.AddNewGameData!\n Exception: {0} \n Callstack: {1}",
                                            e.Message,
                                            e.StackTrace));
                    }

                    var gameInstance = GetGameID(GetUserFromEmailAddress(gameData.Winner).ID, gameData.GameStartTime);

                    if (gameInstance == null)
                    {
                        return;
                    }

                    foreach (var kvp in gameData.PlayerDictionary)
                    {
                        var userGame = new user_game();
                        userGame.avgTimeBetweenDumps = kvp.Value.AvgTimeBetweenDumps;
                        userGame.avgTimeBetweenPeels = kvp.Value.AvgTimeBetweenPeels;
                        userGame.isWinner            = kvp.Value.IsWinner;
                        userGame.numberOfDumps       = kvp.Value.NumberOfDumps;
                        userGame.numberOfPeels       = kvp.Value.NumberOfPeels;
                        userGame.performedFirstPeel  = kvp.Value.PerformedFirstPeel;
                        userGame.userID = GetUserFromEmailAddress(kvp.Key).ID;
                        userGame.gameID = gameInstance.gameID;

                        db.user_games.InsertOnSubmit(userGame);
                    }

                    try
                    {
                        db.SubmitChanges();
                    }
                    catch (Exception e)
                    {
                        Trace.WriteLine(string.Format(
                                            "Exception in Database.AddNewGameData!\n Exception: {0} \n Callstack: {1}",
                                            e.Message,
                                            e.StackTrace));
                    }
                }
            }
        }
Ejemplo n.º 2
0
 partial void Deletegame(game instance);
Ejemplo n.º 3
0
        public void AddNewGameData(GameData gameData)
        {
            if (null == gameData)
            {
                Trace.WriteLine(string.Format(
                    "Invalid Game Data in Database.AddNewGameData!\n GameData is null."));

                return;
            }

            var winnerUser = GetUserFromEmailAddress(gameData.Winner);

            if (null == winnerUser)
            {
                Trace.WriteLine(string.Format(
                    "Invalid Game Data in Database.AddNewGameData!\n Winner {0} not recognized.",
                    gameData.Winner));

                return;
            }

            foreach (var kvp in gameData.PlayerDictionary)
            {
                var player = GetUserFromEmailAddress(kvp.Key);

                if (null == player)
                {
                    Trace.WriteLine(string.Format(
                        "Invalid Game Data in Database.AddNewGameData!\n Player {0} not recognized.",
                        kvp.Key));

                    return;
                }
            }

            if (gameData.GameDuration < 0)
            {
                Trace.WriteLine(string.Format(
                    "Invalid Game Data in Database.AddNewGameData!\n GameDuration of value {0} is invalid.",
                    gameData.GameDuration));

                return;
            }

            using (var connection = new SqlConnection(ConnectionString))
            {
                using (var db = new OzwegoDataClassesDataContext(connection))
                {

                    var newData = new game
                        {
                            winner = winnerUser.ID,
                            gameStartTime = gameData.GameStartTime,
                            gameDuration = gameData.GameDuration
                        };

                    // ToDo: newData.gameDataFile = ??

                    db.games.InsertOnSubmit(newData);

                    try
                    {
                        db.SubmitChanges();
                    }
                    catch (Exception e)
                    {
                        Trace.WriteLine(string.Format(
                                "Exception in Database.AddNewGameData!\n Exception: {0} \n Callstack: {1}",
                                e.Message,
                                e.StackTrace));
                    }

                    var gameInstance = GetGameID(GetUserFromEmailAddress(gameData.Winner).ID, gameData.GameStartTime);

                    if (gameInstance == null)
                    {
                        return;
                    }

                    foreach (var kvp in gameData.PlayerDictionary)
                    {
                        var userGame = new user_game();
                        userGame.avgTimeBetweenDumps = kvp.Value.AvgTimeBetweenDumps;
                        userGame.avgTimeBetweenPeels = kvp.Value.AvgTimeBetweenPeels;
                        userGame.isWinner = kvp.Value.IsWinner;
                        userGame.numberOfDumps = kvp.Value.NumberOfDumps;
                        userGame.numberOfPeels = kvp.Value.NumberOfPeels;
                        userGame.performedFirstPeel = kvp.Value.PerformedFirstPeel;
                        userGame.userID = GetUserFromEmailAddress(kvp.Key).ID;
                        userGame.gameID = gameInstance.gameID;

                        db.user_games.InsertOnSubmit(userGame);
                    }

                    try
                    {
                        db.SubmitChanges();
                    }
                    catch (Exception e)
                    {
                        Trace.WriteLine(string.Format(
                                "Exception in Database.AddNewGameData!\n Exception: {0} \n Callstack: {1}",
                                e.Message,
                                e.StackTrace));
                    }
                }
            }
        }
Ejemplo n.º 4
0
 partial void Updategame(game instance);
Ejemplo n.º 5
0
 partial void Insertgame(game instance);
 partial void Deletegame(game instance);
 partial void Updategame(game instance);
 partial void Insertgame(game instance);