public IActionResult PutTestsQueue([FromBody] TestsQueue testsQueue)
        {
            try
            {
                StringValues accessToken = new StringValues();
                Request.Headers.TryGetValue("Authorization", out accessToken);

                if (accessToken.Count() == 0)
                {
                    return(StatusCode(401, "Empty or no authorization header."));
                }

                if (accessToken.FirstOrDefault().ToString() == null || accessToken.FirstOrDefault().ToString() == "")
                {
                    return(StatusCode(401, "Empty or no authorization header."));
                }

                if (_validation.CheckValidation(accessToken.ToString()))
                {
                    _rdsLogic.PutTestsQueue(testsQueue);
                    return(Ok());
                }

                return(StatusCode(403, "This is an invalid access token."));
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message, e);
                return(StatusCode(500, e.Message));
            }
        }
        public void RunAllEntryTests()
        {
            try
            {
                TestsQueue testsQueue = _webData.GetFirstTestQueue(_client);

                while (testsQueue != null)
                {
                    lock (_sync)
                    {
                        Tests testProcess = new Tests();
                        testProcess.GameId = testsQueue.GameId;
                        RunSingleEntryTest(testsQueue, testProcess);
                    }

                    DeleteFolder();

                    testsQueue = _webData.GetFirstTestQueue(_client);
                }

                SendEmail();
                _webData.StopAutomatedTestingEC2(_client);
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message, e);
                SendEmail();
                DeleteFolder();
                _webData.StopAutomatedTestingEC2(_client);
            }
        }
Exemple #3
0
        public bool PutTestsQueue(TestsQueue myTest, HttpClient client)
        {
            try
            {
                myTest.RetryCount++;
                string json = JsonConvert.SerializeObject(myTest);

                var buffer      = System.Text.Encoding.UTF8.GetBytes(json);
                var byteContent = new ByteArrayContent(buffer);
                byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                HttpResponseMessage response = client.PutAsync(new Uri("http://" + _host + "/api/v1/Restricted/rds/testsqueue/testqueue"), byteContent).Result;


                if (response.StatusCode.ToString() == "OK")
                {
                    return(true);
                }

                return(false);
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message, e);
                return(false);
            }
        }
        public void PutTestsQueue(TestsQueue testsQueue)
        {
            DbContextOptionsBuilder <KnightsArcadeContext> bootUp = new DbContextOptionsBuilder <KnightsArcadeContext>();

            bootUp.UseMySql(_configuration.GetConnectionString("KnightsArcadeDb"));
            KnightsArcadeContext knightsContext = new KnightsArcadeContext(bootUp.Options);

            knightsContext.Entry <TestsQueue>(testsQueue).State = EntityState.Modified;
            knightsContext.SaveChanges();
        }
        public void PostTestsQueue(TestsQueue testsQueue)
        {
            DbContextOptionsBuilder <KnightsArcadeContext> bootUp = new DbContextOptionsBuilder <KnightsArcadeContext>();

            bootUp.UseMySql(_configuration.GetConnectionString("KnightsArcadeDb"));
            KnightsArcadeContext knightsContext = new KnightsArcadeContext(bootUp.Options);

            knightsContext.Testsqueue.Add(testsQueue);
            knightsContext.SaveChanges();
        }
Exemple #6
0
        public void PutTestsQueue(TestsQueue testsQueue)
        {
            _rdsData.PutTestsQueue(testsQueue);

            Tests test = _rdsData.GetTests((int)testsQueue.GameId);

            test.TestAttempts = testsQueue.RetryCount;

            _rdsData.PutTests(test);
            return;
        }
        public TestsQueue GetTestsQueue()
        {
            DbContextOptionsBuilder <KnightsArcadeContext> bootUp = new DbContextOptionsBuilder <KnightsArcadeContext>();

            bootUp.UseMySql(_configuration.GetConnectionString("KnightsArcadeDb"));
            KnightsArcadeContext knightsContext = new KnightsArcadeContext(bootUp.Options);

            TestsQueue testsQueue = knightsContext.Testsqueue.FirstOrDefault();

            return(testsQueue);
        }
        public void DeleteTestsQueue(int gameId)
        {
            DbContextOptionsBuilder <KnightsArcadeContext> bootUp = new DbContextOptionsBuilder <KnightsArcadeContext>();

            bootUp.UseMySql(_configuration.GetConnectionString("KnightsArcadeDb"));
            KnightsArcadeContext knightsContext = new KnightsArcadeContext(bootUp.Options);

            TestsQueue testsQueue = knightsContext.Testsqueue.Find(gameId);

            knightsContext.Testsqueue.Remove(testsQueue);
            knightsContext.SaveChanges();
        }
        public void RunAllEntryTests()
        {
            TestsQueue testsQueue  = _webData.GetFirstTestQueue(_client);
            Tests      testProcess = new Tests()
            {
                GameId = testsQueue.GameId
            };

            try
            {
                while (testsQueue != null)
                {
                    lock (_sync)
                    {
                        testProcess.GameId = testsQueue.GameId;
                        RunSingleEntryTest(testsQueue, testProcess);
                    }

                    DeleteFolder();

                    testsQueue = _webData.GetFirstTestQueue(_client);
                }

                SendEmail();
                _webData.StopAutomatedTestingEC2(_client);
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message, e);
                _webData.DeleteTestQueue((int)testsQueue.GameId, _client);
                _webData.PutGames(new GamesEntry()
                {
                    GameId     = testsQueue.GameId,
                    GameStatus = "p"
                }, _client);
                _webData.PutTests(testProcess, _client);
                _webData.PostTestingLog(new TestingLog()
                {
                    GameId             = testsQueue.GameId,
                    TestlogAttempt     = -1,
                    TestlogDatetimeUtc = DateTime.Now,
                    TestlogLog         = "There was an error with the tests and the program has crashed due to: " + e.Message + " It will attempt to shutdown."
                }, _client);
                SendEmail();
                DeleteFolder();
                _webData.StopAutomatedTestingEC2(_client);
            }
        }
Exemple #10
0
        public TestsQueue GetFirstTestQueue(HttpClient client)
        {
            try
            {
                HttpResponseMessage response = client.GetAsync("http://" + _host + "/api/v1/Public/rds/testsqueue/firsttestsqueue").Result;
                string     json = response.Content.ReadAsStringAsync().Result;
                TestsQueue test = JsonConvert.DeserializeObject <TestsQueue>(json);

                return(test);
            }

            catch (Exception e)
            {
                _logger.LogError(e.Message, e);
                return(null);
            }
        }
Exemple #11
0
        public void PutNewEntry(GamesEntry updateEntry)
        {
            Games postedGame = _rdsData.GetGames((int)updateEntry.GameId);

            GamesEntry oldEntry = GamesToGamesEntry(postedGame);
            GamesEntry newEntry = UpdateEntry(oldEntry, updateEntry);

            Games newGamesUpdate = GamesEntryToGames(newEntry);

            _rdsData.PutGames(newGamesUpdate);

            try
            {
                TestsQueue newTestQueue = new TestsQueue()
                {
                    GameId     = newGamesUpdate.GameId,
                    RetryCount = 0
                };

                try
                {
                    _rdsData.DeleteTestsQueue((int)newGamesUpdate.GameId);
                }
                catch (Exception e)
                {
                    _logger.LogCritical(e.Message, e);
                }
                _rdsData.PostTestsQueue(newTestQueue);

                Tests newTest = new Tests()
                {
                    GameId              = newGamesUpdate.GameId,
                    Test10min           = false,
                    TestCloses          = false,
                    TestOpens           = false,
                    TestAttempts        = 0,
                    TestAverageRam      = null,
                    TestCloseOn3        = null,
                    TestCloseOnEscape   = null,
                    TestFolderFileNames = null,
                    TestNumExeFiles     = null,
                    TestPeakRam         = null
                };

                try
                {
                    _rdsData.DeleteTests((int)newGamesUpdate.GameId);
                }
                catch (Exception e)
                {
                    _logger.LogCritical(e.Message, e);
                }

                _rdsData.PostTests(newTest);

                return;
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message, e);
                throw new Exception(e.Message);
            }
        }
Exemple #12
0
        public Tuple <Games, int> PostNewEntry(GamesEntry newEntry)
        {
            Games newGame = new Games()
            {
                GameControls            = newEntry.GameControls,
                GameCreatorName         = newEntry.GameCreatorName,
                GameCreatorEmail        = newEntry.GameCreatorEmail,
                GameDescription         = newEntry.GameDescription,
                GameGenreAction         = newEntry.GameGenreAction,
                GameGenreAdventure      = newEntry.GameGenreAdventure,
                GameGenreFighting       = newEntry.GameGenreFighting,
                GameGenrePuzzle         = newEntry.GameGenrePuzzle,
                GameGenreRacing         = newEntry.GameGenreRacing,
                GameGenreRhythm         = newEntry.GameGenreRhythm,
                GameGenreRpg            = newEntry.GameGenreRpg,
                GameGenreShooter        = newEntry.GameGenreShooter,
                GameGenreSports         = newEntry.GameGenreSports,
                GameGenreStrategy       = newEntry.GameGenreStrategy,
                GameGenreSurvival       = newEntry.GameGenreSurvival,
                GameGenrePlatformer     = newEntry.GameGenrePlatformer,
                GameName                = newEntry.GameName,
                GamePath                = newEntry.GamePath,
                GameVideoLink           = newEntry.GameVideoLink,
                GameOnArcade            = false,
                GameStatus              = "t",
                GameSubmissionDateUtc   = DateTime.UtcNow,
                GameAvailableToDownload = newEntry.GameAvailableToDownload,
            };

            char[] s = new char[5];

            newGame = InsertArrayToColumn(newGame, newEntry);
            if (_rdsData.GetGames(newGame.GameName) != null)
            {
                return(Tuple.Create <Games, int>(null, 1));
            }

            try
            {
                _rdsData.PostGames(newGame);
                Games postedGame = _rdsData.GetGames(newGame.GameName);

                TestsQueue newTestQueue = new TestsQueue()
                {
                    GameId     = postedGame.GameId,
                    RetryCount = 0
                };

                _rdsData.PostTestsQueue(newTestQueue);

                Tests newTest = new Tests()
                {
                    GameId              = postedGame.GameId,
                    Test10min           = false,
                    TestCloses          = false,
                    TestOpens           = false,
                    TestAttempts        = 0,
                    TestAverageRam      = null,
                    TestCloseOn3        = null,
                    TestCloseOnEscape   = null,
                    TestFolderFileNames = null,
                    TestNumExeFiles     = null,
                    TestPeakRam         = null
                };

                _rdsData.PostTests(newTest);

                return(Tuple.Create(newGame, 0));
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message, e);
                CleanUpOnCrash((int)newGame.GameId);
                throw new Exception(e.Message);
            }
        }
Exemple #13
0
        public void PutSubmissions(Submissions submission)
        {
            if (submission.SubmissionStatus == "d")
            {
                submission.SubmissionImage0 = "DEFAULT_PLACEHOLDER/default.png";
            }
            _rdsData.PutSubmissions(submission);

            try
            {
                Games game = new Games();
                game.GameId = submission.GameId;
                if (submission.SubmissionImage0 != null)
                {
                    game.GameImage0 = submission.SubmissionImage0;
                }
                if (submission.SubmissionReviewDateUtc != null)
                {
                    game.GameReviewDateUtc = submission.SubmissionReviewDateUtc;
                }
                if (submission.SubmissionStatus != null)
                {
                    game.GameStatus = submission.SubmissionStatus;
                }

                if (submission.SubmissionStatus == "d")
                {
                    _rdsData.DeleteGames((int)game.GameId);
                }
                else
                {
                    _rdsData.PutGames(game);
                }

                try
                {
                    _rdsData.DeleteTestsQueue((int)submission.GameId);
                }
                catch (Exception e)
                {
                    _logger.LogWarning(e.Message, e);
                }

                if (submission.SubmissionStatus == "t")
                {
                    TestsQueue testsQueue = new TestsQueue()
                    {
                        GameId     = submission.GameId,
                        RetryCount = 0
                    };
                    _rdsData.PostTestsQueue(testsQueue);
                }

                if (submission.CreatorEmail != null)
                {
                    List <Users> users = _rdsData.GetAllUsers().Where(x => x.Username == submission.CreatorName).ToList();
                    users.Where(x => x.UserEmail != submission.CreatorEmail).ToList().ForEach(x =>
                    {
                        x.UserEmail = submission.CreatorEmail;
                        _rdsData.PutUser(x);
                    });
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message, e);
            }

            return;
        }
Exemple #14
0
        public void PutNewEntry(NewEntry updateEntry)
        {
            Games updateGame = new Games()
            {
                GameId                  = updateEntry.GameId,
                GameControls            = updateEntry.GameControls,
                GameCreatorName         = updateEntry.GameCreatorName,
                GameDescription         = updateEntry.GameDescription,
                GameGenreAction         = updateEntry.GameGenreAction,
                GameGenreAdventure      = updateEntry.GameGenreAdventure,
                GameGenreFighting       = updateEntry.GameGenreFighting,
                GameGenrePuzzle         = updateEntry.GameGenrePuzzle,
                GameGenreRacing         = updateEntry.GameGenreRacing,
                GameGenreRhythm         = updateEntry.GameGenreRhythm,
                GameGenreRpg            = updateEntry.GameGenreRpg,
                GameGenreShooter        = updateEntry.GameGenreShooter,
                GameGenreSports         = updateEntry.GameGenreSports,
                GameGenreStrategy       = updateEntry.GameGenreStrategy,
                GameGenreSurvival       = updateEntry.GameGenreSurvival,
                GameGenrePlatformer     = updateEntry.GameGenrePlatformer,
                GameName                = updateEntry.GameName,
                GamePath                = updateEntry.GamePath,
                GameVideolink           = updateEntry.GameVideoLink,
                GameOnArcade            = false,
                GameStatus              = "t",
                GameSubmissionDateUtc   = DateTime.UtcNow,
                GameAvailableToDownload = updateEntry.GameAvailableToDownload
            };

            char[] s = new char[5];
            updateGame = InsertArrayToColumn(updateGame, updateEntry);

            try
            {
                _rdsData.PutGames(updateGame);
                Games postedGame = _rdsData.GetGames(updateGame.GameName);

                Submissions updateSubmission = new Submissions()
                {
                    GameId            = postedGame.GameId,
                    SubmissionDateUtc = postedGame.GameSubmissionDateUtc,
                    SubmissionImage0  = postedGame.GameImage0,
                    SubmissionName    = postedGame.GameName,
                    SubmissionStatus  = postedGame.GameStatus,
                    CreatorName       = postedGame.GameCreatorName,
                    CreatorEmail      = updateEntry.GameCreatorEmail
                };

                _rdsData.PutSubmissions(updateSubmission);

                TestsQueue newTestQueue = new TestsQueue()
                {
                    GameId     = updateEntry.GameId,
                    RetryCount = 0
                };

                try
                {
                    _rdsData.DeleteTestsQueue((int)updateEntry.GameId);
                }
                catch (Exception e)
                {
                    _logger.LogCritical(e.Message, e);
                }
                _rdsData.PostTestsQueue(newTestQueue);

                Tests newTest = new Tests()
                {
                    GameId              = postedGame.GameId,
                    Test5min            = false,
                    TestCloses          = false,
                    TestOpens           = false,
                    TestAttempts        = 0,
                    TestAverageRam      = null,
                    TestCloseOn3        = null,
                    TestCloseOnEscape   = null,
                    TestFolderFileNames = null,
                    TestNumExeFiles     = null,
                    TestPeakRam         = null
                };

                try
                {
                    _rdsData.DeleteTests((int)postedGame.GameId);
                }
                catch (Exception e)
                {
                    _logger.LogCritical(e.Message, e);
                }

                _rdsData.PostTests(newTest);

                return;
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message, e);
                CleanUpOnCrash((int)updateEntry.GameId);
                throw new Exception(e.Message);
            }
        }
        public void RunSingleEntryTest(TestsQueue testsQueue, Tests testProcess)
        {
            try
            {
                while (testsQueue.RetryCount < 3)
                {
                    testProcess.Test10min           = false;
                    testProcess.TestAttempts        = testsQueue.RetryCount;
                    testProcess.TestCloseOn3        = false;
                    testProcess.TestCloseOnEscape   = false;
                    testProcess.TestCloses          = false;
                    testProcess.TestOpens           = false;
                    testProcess.TestNumExeFiles     = 0;
                    testProcess.TestAverageRam      = null;
                    testProcess.TestFolderFileNames = null;
                    testProcess.TestPeakRam         = null;

                    TestingLog testLog = new TestingLog();

                    _webData.PutTestsQueue(testsQueue, _client);

                    testLog.TestlogAttempt = (int)testsQueue.RetryCount;
                    testLog.GameId         = (int)testsQueue.GameId;

                    GamesEntry myGame = _webData.GetGamesByID(testsQueue.GameId, _client);

                    //Retry to pull game if it failed the first time
                    if (myGame == null)
                    {
                        testLog.TestlogLog         = "No valid game found with this ID.";
                        testLog.TestlogDatetimeUtc = DateTime.UtcNow;
                        _webData.PostTestingLog(testLog, _client);
                        continue;
                    }

                    string debugKey = "public/" + myGame.GamePath;
                    fileLocation = _s3Data.ReadObjectDataAsync(debugKey).Result;

                    //Point variable to folder which contains .exe file
                    string subFileLocation = FindSubDir(fileLocation);

                    //Store list of names of files within game folder
                    testProcess.TestFolderFileNames = FolderFileNames(subFileLocation);

                    //Find .exe file path
                    string[] exeFiles = FindExe(subFileLocation);

                    //Store number of exe files within game folder
                    testProcess.TestNumExeFiles = exeFiles.Length;

                    gameProcess = new Process();

                    //start .exe, check to see if it started
                    testProcess.TestOpens = StartFile(exeFiles[0]);

                    //Retry tests if process does not start
                    if (!(bool)testProcess.TestOpens)
                    {
                        testLog.TestlogLog         = "Game Failed Start Test";
                        testLog.TestlogDatetimeUtc = DateTime.UtcNow;

                        _webData.PostTestingLog(testLog, _client);
                        continue;
                    }

                    //Check to see if game still running after 5 min
                    testProcess.Test10min = SleepFile(exeFiles[0]);

                    //Retry tests if process does not stay open for 5 min
                    if ((bool)!testProcess.Test10min)
                    {
                        testLog.TestlogLog         = "Game Failed Sleep Test";
                        testLog.TestlogDatetimeUtc = DateTime.UtcNow;

                        _webData.PostTestingLog(testLog, _client);
                        continue;
                    }

                    //Store memory usage by game process
                    testProcess.TestAverageRam = RamFile();

                    //Retry tests if the program is unable to record the game's RAM usage
                    if (testProcess.TestAverageRam == null)
                    {
                        testLog.TestlogLog         = "Game Average RAM Test Failed";
                        testLog.TestlogDatetimeUtc = DateTime.UtcNow;

                        _webData.PostTestingLog(testLog, _client);
                        continue;
                    }

                    //Store memory usage by game process
                    testProcess.TestPeakRam = RamFile();

                    //Retry tests if the program is unable to record the game's RAM usage
                    if (testProcess.TestPeakRam == null)
                    {
                        testLog.TestlogLog         = "Game Peak RAM Test Failed";
                        testLog.TestlogDatetimeUtc = DateTime.UtcNow;

                        _webData.PostTestingLog(testLog, _client);
                        continue;
                    }

                    //Test whether game will close on "3" key press
                    int i = CloseOn3(exeFiles[0]);

                    if (i == 0)
                    {
                        testProcess.TestCloseOn3   = true;
                        testLog.TestlogLog         = "Game shut down on 3 press.";
                        testLog.TestlogDatetimeUtc = DateTime.UtcNow;

                        _webData.PostTestingLog(testLog, _client);
                    }
                    else if (i == 1)
                    {
                        testLog.TestlogLog         = "Game did not shut down on 3 press.";
                        testLog.TestlogDatetimeUtc = DateTime.UtcNow;

                        _webData.PostTestingLog(testLog, _client);
                    }
                    //Retry tests if the program is unable to restart after passing "3" test
                    else if (i == 2)
                    {
                        testLog.TestlogLog         = "Game passed 'close on 3' test but failed to restart";
                        testLog.TestlogDatetimeUtc = DateTime.UtcNow;

                        _webData.PostTestingLog(testLog, _client);
                        continue;
                    }

                    //Test whether game will close on "Escape" key press
                    i = EscapeFile(exeFiles[0]);

                    //Log if game did not shut down after "Escape" press
                    if (i == 0)
                    {
                        testProcess.TestCloseOnEscape = true;

                        testLog.TestlogLog         = "Game shut down after Escape press";
                        testLog.TestlogDatetimeUtc = DateTime.UtcNow;

                        _webData.PostTestingLog(testLog, _client);
                    }
                    else if (i == 1)
                    {
                        testProcess.TestCloseOnEscape = false;

                        testLog.TestlogLog         = "Game did not down after Escape press";
                        testLog.TestlogDatetimeUtc = DateTime.UtcNow;

                        _webData.PostTestingLog(testLog, _client);
                    }

                    //Retry tests if the program is unable to restart after passing "3" test
                    else if (i == 2)
                    {
                        testLog.TestlogLog         = "Game passed 'close on Escape' test but failed to restart";
                        testLog.TestlogDatetimeUtc = DateTime.UtcNow;

                        _webData.PostTestingLog(testLog, _client);
                        continue;
                    }

                    //Log if game did not shut down after "3" press
                    if ((bool)!testProcess.TestCloseOnEscape)
                    {
                        testLog.TestlogLog         = "Game failed 'close on Escape' test";
                        testLog.TestlogDatetimeUtc = DateTime.UtcNow;

                        _webData.PostTestingLog(testLog, _client);
                    }

                    //stop .exe, check to see if it stopped
                    testProcess.TestCloses = StopFile(exeFiles[0]);

                    if ((bool)!testProcess.TestCloses)
                    {
                        testLog.TestlogLog         = "Game Failed Stop Test";
                        testLog.TestlogDatetimeUtc = DateTime.UtcNow;

                        _webData.PostTestingLog(testLog, _client);
                        continue;
                    }


                    //If all tests passed, update game object and stop rechecking
                    if ((bool)testProcess.TestOpens && (bool)testProcess.Test10min && (bool)testProcess.TestCloses)
                    {
                        myGame.GameReviewDateUtc = DateTime.UtcNow;
                        myGame.GameStatus        = "p";

                        if ((testsQueue.RetryCount - 1) == 0)
                        {
                            testLog.TestlogLog = "Game Passed all essential tests on first try";
                        }
                        else if ((testsQueue.RetryCount - 1) == 1)
                        {
                            testLog.TestlogLog = "Game Passed all essential tests after 1 retry";
                        }
                        else if ((testsQueue.RetryCount - 1) == 2)
                        {
                            testLog.TestlogLog = "Game Passed all essential tests after 2 retries";
                        }

                        _webData.PostTestingLog(testLog, _client);
                        _webData.PutGames(myGame, _client);

                        break;
                    }
                }

                //Delete game from test queue and push the test results to database
                _webData.DeleteTestQueue(testsQueue.GameId, _client);
                _webData.PutTests(testProcess, _client);
            }

            catch (Exception e)
            {
                _webData.PostTestingLog(new TestingLog()
                {
                    GameId             = testsQueue.GameId,
                    TestlogAttempt     = (int)testsQueue.RetryCount,
                    TestlogDatetimeUtc = DateTime.UtcNow,
                    TestlogLog         = "There was an error with the testing process, and it has crashed during this test. The error: " + e.Message
                }, _client);
                _webData.PutGames(new GamesEntry()
                {
                    GameId     = testsQueue.GameId,
                    GameStatus = "p"
                }, _client);
                _webData.DeleteTestQueue(testsQueue.GameId, _client);
                _webData.PutTests(testProcess, _client);
                _logger.LogError(e.Message, e);
            }
        }