Exemple #1
0
        private bool BuildBatch(int id)
        {
            using (RDATContext context = new RDATContext())
            {
                List <TempTestingLog> _logs = context.TempTestingLogs.ToList();

                foreach (TempTestingLog log in _logs)
                {
                    TestingLog _testingLog = new TestingLog();
                    _testingLog.Test_Type            = log.Test_Type;
                    _testingLog.Driver_Id            = log.Driver_Id;
                    _testingLog.Driver_Name          = log.Driver_Name;
                    _testingLog.Created              = log.CreatedDate;
                    _testingLog.Selectiondatealcohol = log.CreatedDate;
                    _testingLog.Selectiondatedrug    = log.CreatedDate;
                    _testingLog.Modified             = log.ModifiedDate;
                    _testingLog.TestDate             = log.CreatedDate;
                    _testingLog.Batch_Id             = id;
                    _testingLog.Company_Id           = log.Company_Id;
                    _testingLog.Reported_Results     = "0";

                    context.TestingLogs.Add(_testingLog);
                }

                context.SaveChanges();
                return(true);
            }

            return(false);
        }
        public IActionResult PostTestingLog(TestingLog testingLog)
        {
            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.PostTestingLog(testingLog);
                    return(StatusCode(201));
                }

                return(StatusCode(403, "This is an invalid access token."));
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message, e);
                return(StatusCode(500, e.Message));
            }
        }
Exemple #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Batch_Id,Selectiondatedrug,Selectiondatealcohol,Reported_Results,ResultsDate,SSN,Specimen_Id,ClosedDate,Test_Process_Id,Driver_Id,Test_Type,Drug_Percentage,Alcohol_Percentage,Created,Modified,Status,isDelete")] TestingLog testingLog)
        {
            if (id != testingLog.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(testingLog);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TestingLogExists(testingLog.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(testingLog));
        }
        public void PostTestingLog(TestingLog testingLog)
        {
            DbContextOptionsBuilder <KnightsArcadeContext> bootUp = new DbContextOptionsBuilder <KnightsArcadeContext>();

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

            knightsContext.TestingLog.Add(testingLog);
            knightsContext.SaveChanges();
        }
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (EtalonLog != null ? EtalonLog.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (TestingLog != null ? TestingLog.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ NewEtalon.GetHashCode();
         return(hashCode);
     }
 }
Exemple #6
0
        public async Task <IActionResult> Create([Bind("Id,Batch_Id,Selectiondatedrug,Selectiondatealcohol,Reported_Results,ResultsDate,SSN,Specimen_Id,ClosedDate,Test_Process_Id,Driver_Id,Test_Type,Drug_Percentage,Alcohol_Percentage,Created,Modified,Status,isDelete")] TestingLog testingLog)
        {
            if (ModelState.IsValid)
            {
                _context.Add(testingLog);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(testingLog));
        }
Exemple #7
0
        public bool PostTestingLog(TestingLog testLog, HttpClient client)
        {
            try
            {
                string json        = JsonConvert.SerializeObject(testLog);
                var    buffer      = System.Text.Encoding.UTF8.GetBytes(json);
                var    byteContent = new ByteArrayContent(buffer);
                byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                HttpResponseMessage response = client.PostAsync("http://" + _host + "/api/v1/Restricted/rds/testinglog/testinglog", byteContent).Result;

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

                return(false);
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message, e);
                return(false);
            }
        }
Exemple #8
0
 public void PostTestingLog(TestingLog testingLog)
 {
     _rdsData.PostTestingLog(testingLog);
     return;
 }
        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);
            }
        }