Пример #1
0
        public async Task <ActionResult> GetAsync(Guid id)
        {
            var model = await _rulesService
                        .GetAsync(id);

            if (model != null)
            {
                return(Ok(model));
            }

            return(NotFound());
        }
Пример #2
0
        public async Task <IActionResult> GetRulesAsync()
        {
            var result = await service.GetAsync();

            return(new OkObjectResult(result));
        }
Пример #3
0
        public async Task <RuleTestResult> ExecuteRuleByEnvironmentIdAsync(Guid ruleId, DatabaseEnvironmentBO databaseEnvironment)
        {
            int?ruleDetailsDestinationId = null;
            var rule = await _ruleService.GetAsync(ruleId);

            var executionLogs = await _ruleExecutionLogQueries.GetByRuleIdAsync(ruleId);

            var connectionString = databaseEnvironment.GetConnectionString();

            var stopWatch = System.Diagnostics.Stopwatch.StartNew();

            RuleTestResult testResult = await ExecuteRuleAsync(rule, connectionString, databaseEnvironment.UserParams, databaseEnvironment.TimeoutInMinutes);

            var containerParent = await _collectionQueries.GetAsync(rule.ContainerId);

            if (containerParent.ParentContainerId != null)
            {
                var collectionParent = await _collectionQueries.GetAsync(containerParent.ParentContainerId.Value);

                ruleDetailsDestinationId = collectionParent.RuleDetailsDestinationId;
            }

            RuleExecutionLog ruleExecutionLog = new RuleExecutionLog()
            {
                Id                       = 0,
                Evaluation               = testResult.Evaluation,
                RuleId                   = ruleId,
                StatusId                 = (int)testResult.Status,
                Result                   = testResult.Result,
                Response                 = testResult.Evaluation ? "Ok" : testResult.ErrorMessage,
                DatabaseEnvironmentId    = databaseEnvironment.Id,
                ExecutedSql              = testResult.ExecutedSql,
                DiagnosticSql            = rule.DiagnosticSql,
                RuleDetailsDestinationId = ruleDetailsDestinationId
            };

            if (ruleExecutionLog.RuleDetailsDestinationId == null || ruleExecutionLog.RuleDetailsDestinationId.Value == 0)
            {
                ruleExecutionLog.RuleDetailsDestinationId = null;
            }

            testResult.LastExecuted          = executionLogs.Any() ? executionLogs.FirstOrDefault().ExecutionDate : (DateTime?)null;
            ruleExecutionLog.ExecutionTimeMs = stopWatch.ElapsedMilliseconds;
            ruleExecutionLog.Result          = testResult.Result;

            var newRuleExecutionLog = await _ruleExecutionLogCommands.AddAsync(ruleExecutionLog);

            testResult.TestResults = await _ruleService.GetTopResults(ruleId, databaseEnvironment.Id);

            if (!testResult.Evaluation)
            {
                testResult.DiagnosticSql = rule.DiagnosticSql;
            }

            try
            {
                //Validate if the rule is going to any queue table
                if (ruleDetailsDestinationId != null && ruleDetailsDestinationId.Value > 0)
                {
                    var existCatalog = await _catalogQueries.GetAsync(ruleDetailsDestinationId.Value);

                    if (existCatalog != null)
                    {
                        int maxNumberResults = databaseEnvironment.MaxNumberResults.Value;
                        if (rule.MaxNumberResults != null)
                        {
                            maxNumberResults = rule.MaxNumberResults.Value;
                        }

                        await InsertDiagnosticSqlIntoDetails(rule, newRuleExecutionLog, connectionString, databaseEnvironment.UserParams, existCatalog.Name, maxNumberResults);
                    }
                }
            }
            catch (Exception ex)
            {
                newRuleExecutionLog.Result   = -1;
                newRuleExecutionLog.Response = ex.Message;
                await _ruleExecutionLogCommands.UpdateAsync(newRuleExecutionLog);
            }

            return(testResult);
        }