public async Task <IActionResult> DeleteOlderTestCasesHistoryAsync()
        {
            try
            {
                // Get all test cases history where are not updated in the last 30 days.
                var testCasesHistory = _meissaRepository.GetAllQuery <TestCaseHistory>();
                foreach (var currentTestCaseHistory in testCasesHistory)
                {
                    var allHistoryEntries = _meissaRepository.GetAllQuery <TestCaseHistoryEntry>();
                    if (allHistoryEntries.Count(x => x.TestCaseHistoryId.Equals(currentTestCaseHistory.TestCaseHistoryId)) > 3)
                    {
                        var filteredEntries = allHistoryEntries.Where(x => x.TestCaseHistoryId.Equals(currentTestCaseHistory.TestCaseHistoryId)).OrderByDescending(j => j.TestCaseHistoryEntryId).Skip(3).ToList();
                        _meissaRepository.DeleteRange(filteredEntries);
                    }
                }

                var outdatedTestCasesHistory = _meissaRepository.GetAllQuery <TestCaseHistory>().Where(x => x.LastUpdatedTime < DateTime.Now.AddDays(-30));
                _meissaRepository.DeleteRange(outdatedTestCasesHistory);
                await _meissaRepository.SaveAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                // Ignore.
            }

            return(NoContent());
        }
Exemple #2
0
        public async Task <IActionResult> DeleteOldTestRunDataByTestRunIdAsync([FromBody] Guid id)
        {
            try
            {
                var testRun = _meissaRepository.GetAllQuery <TestRun>().FirstOrDefault(r => r.TestRunId.Equals(id));
                if (testRun != null)
                {
                    var testRunOutputs = _meissaRepository.GetAllQuery <TestRunOutput>().Where(x => x.TestRunId.Equals(testRun.TestRunId));
                    _meissaRepository.DeleteRange(testRunOutputs);
                    var testRunCustomArguments = _meissaRepository.GetAllQuery <TestRunCustomArgument>().Where(x => x.TestRunId.Equals(testRun.TestRunId));
                    _meissaRepository.DeleteRange(testRunCustomArguments);
                    var testAgentRuns = _meissaRepository.GetAllQuery <TestAgentRun>().Where(x => x.TestRunId.Equals(testRun.TestRunId));
                    DeleteTestAgentRunAvailabilitiesForTestAgentRuns(testAgentRuns);
                    _meissaRepository.DeleteRange(testAgentRuns);
                    var testRunLogs = _meissaRepository.GetAllQuery <TestRunLog>().Where(x => x.TestRunId.Equals(testRun.TestRunId));
                    _meissaRepository.DeleteRange(testRunLogs);
                    var testRunAvailabilities = _meissaRepository.GetAllQuery <TestRunAvailability>().Where(x => x.TestRunId.Equals(testRun.TestRunId));
                    _meissaRepository.DeleteRange(testRunLogs);
                    await _meissaRepository.DeleteWithSaveAsync(testRun);

                    await _meissaRepository.SaveAsync();
                }
            }
            catch (DbUpdateConcurrencyException ex)
            {
                // Ignore.
            }

            return(NoContent());
        }