private void PreGenerateReport(List <ScenarioCampaignLevelResultItem> data, Run run, Scenario scenario)
        {
            _auditEventRepository.Insert(AuditEventFactory.CreateAuditEventForInformationMessage(0,
                                                                                                 0, $"Start scenario campaign level results report generation. ScenarioId: {scenario.Id} Count: {data.Count}"));
            try
            {
                _campaignResultReportCreator.EnablePerformanceKPIColumns(_includeScenarioPerformanceMeasurementKpIs);
                _campaignResultReportCreator.EnableCampaignLevel(!_saveData);
                string fileName = ReportFileNameHelper.ScenarioCampaignResult(scenario, run.ExecuteStartedDateTime.Value);

                using (var reportStream = _campaignResultReportCreator.GenerateReport(() =>
                                                                                      ScenarioCampaignResultReportHelper.MapToExtendedResults(data, scenario.CampaignPassPriorities, _mapper)))
                {
                    _ = _cloudStorage.Upload(new S3UploadComment
                    {
                        BucketName          = _awsSettings.S3Bucket,
                        DestinationFilePath = fileName,
                        FileStream          = reportStream
                    });
                }
            }
            catch (Exception e)
            {
                _auditEventRepository.Insert(
                    AuditEventFactory.CreateAuditEventForException(
                        0,
                        0,
                        $"Error while generating report for scenario campaign level results. ScenarioId: {scenario.Id}", e
                        )
                    );
                throw;
            }
            _auditEventRepository.Insert(AuditEventFactory.CreateAuditEventForInformationMessage(0,
                                                                                                 0, $"End scenario campaign level results report generation. ScenarioId: {scenario.Id}"));
        }
Пример #2
0
        public IHttpActionResult GetExportScenarioCampaignResultsLink([FromUri] Guid scenarioId)
        {
            var engine = _storageClientFactory.GetEngine();

            var run = _runRepository.FindByScenarioId(scenarioId);

            if (run is null)
            {
                return(this.Error().ResourceNotFound(RunNotFoundMessage));
            }

            var scenario = _scenarioRepository.Get(scenarioId);
            var filePath = ReportFileNameHelper.ScenarioCampaignResult(scenario, run.ExecuteStartedDateTime.Value);

            var descriptor = new S3FileComment()
            {
                BucketName       = _awsSettings.S3Bucket,
                FileNameWithPath = filePath
            };

            if (!engine.FileExists(descriptor))
            {
                using (var excelFileStream =
                           _scenarioCampaignResultReportCreator.GenerateReport(
                               ScenarioCampaignResultReportHelper.MapToExtendedResults(
                                   _scenarioCampaignResultRepository.Get(scenarioId)?.Items, scenario.CampaignPassPriorities, _mapper)))
                {
                    engine.Upload(new S3UploadComment()
                    {
                        BucketName          = descriptor.BucketName,
                        DestinationFilePath = descriptor.FileNameWithPath,
                        FileStream          = excelFileStream
                    });
                }
            }

            return(Content(HttpStatusCode.OK, engine.GetPreSignedUrl(descriptor)));
        }