Exemple #1
0
        public IEnumerable <ScenarioResult> CalculateBRSIndicatorsAfterRunCompleted(Run run)
        {
            if (run.Scenarios.Count > 1 && run.HasAllScenarioCompletedSuccessfully)
            {
                var infoLabel = $"(RunID={run.Id}, BRSConfigurationTemplateId={run.BRSConfigurationTemplateId})";

                RaiseInfo($"Starting calculation of BRS Indicator {infoLabel}. Scenarios info: {run.Scenarios.Select(x => new { ScenarioId = x.Id, x.Status }) }");
                var scenarioResults = CalculateBRSIndicators(run);
                RaiseInfo($"Scenario results after calculation {infoLabel}: {JsonConvert.SerializeObject(scenarioResults)}");
                _scenarioResultRepository.UpdateRange(scenarioResults);
                _scenarioResultRepository.SaveChanges();
                RaiseInfo($"Finished calculation of BRS Indicator {infoLabel}");

                return(scenarioResults);
            }

            return(null);
        }
        public IHttpActionResult PostCalculateAndSave(Guid runId, int?brsConfigurationTemplateId = null)
        {
            var run = _runRepository.Find(runId);

            if (run == null)
            {
                return(NotFound());
            }

            var scenarioResults = _brsManager.CalculateBRSIndicators(run, brsConfigurationTemplateId);

            _scenarioResultRepository.UpdateRange(scenarioResults);
            if (brsConfigurationTemplateId.HasValue)
            {
                run.BRSConfigurationTemplateId = brsConfigurationTemplateId.Value;
                _runRepository.Update(run);
            }
            _scenarioResultRepository.SaveChanges();

            return(Ok(_mapper.Map <List <BRSIndicatorValueForScenarioResultModel> >(scenarioResults)));
        }