Beispiel #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));
                    }
                }
            }
        }
Beispiel #2
0
 private void detach_user_games(user_game entity)
 {
     this.SendPropertyChanging();
     entity.game = null;
 }
Beispiel #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));
                    }
                }
            }
        }
Beispiel #4
0
 partial void Deleteuser_game(user_game instance);
Beispiel #5
0
 private void attach_user_games(user_game entity)
 {
     this.SendPropertyChanging();
     entity.game = this;
 }
Beispiel #6
0
 partial void Insertuser_game(user_game instance);
Beispiel #7
0
 partial void Updateuser_game(user_game instance);
		private void detach_user_games(user_game entity)
		{
			this.SendPropertyChanging();
			entity.game = null;
		}
		private void attach_user_games(user_game entity)
		{
			this.SendPropertyChanging();
			entity.game = this;
		}
 partial void Deleteuser_game(user_game instance);
 partial void Updateuser_game(user_game instance);
 partial void Insertuser_game(user_game instance);