Exemplo n.º 1
0
        private void PreGenerateReport(IReadOnlyCollection <ScenarioCampaignFailure> data, Run run, Scenario scenario)
        {
            _auditEventRepository.Insert(AuditEventFactory.CreateAuditEventForInformationMessage(0,
                                                                                                 0, $"Start scenario campaign failures report generation. ScenarioId: {scenario.Id} Count: {data.Count}"));
            try
            {
                var reportService = new ScenarioCampaignFailuresReportCreator();
                var reportData    = new ScenarioCampaignFailuresDataSnapshot();
                var fileName      = ScenarioCampaignFailuresReportCreator.GetFilePath(scenario.Name, run.ExecuteStartedDateTime.Value, scenario.Id);

                var failureTypes = data.Select(c => c.FailureType)
                                   .Distinct()
                                   .ToList();

                DayOfWeek tenantStartDayOfWeek;
                using (var internalScope = _repositoryFactory.BeginRepositoryScope())
                {
                    reportData.Campaigns  = internalScope.CreateRepository <ICampaignRepository>().GetAllFlat();
                    reportData.FaultTypes = internalScope.CreateRepository <IFunctionalAreaRepository>().FindFaultTypes(failureTypes);
                    tenantStartDayOfWeek  = internalScope.CreateRepository <ITenantSettingsRepository>().GetStartDayOfWeek();
                }

                using (var reportStream = reportService.GenerateReport(data, reportData, tenantStartDayOfWeek))
                {
                    _ = _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 failures. ScenarioId: {scenario.Id}", e
                        )
                    );
                throw;
            }
            _auditEventRepository.Insert(AuditEventFactory.CreateAuditEventForInformationMessage(0,
                                                                                                 0, $"End scenario campaign failures report generation. ScenarioId: {scenario.Id}"));
        }
Exemplo n.º 2
0
        public IHttpActionResult GetExportScenarioCampaignFailuresLink([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 = ScenarioCampaignFailuresReportCreator.GetFilePath(scenario.Name, run.ExecuteStartedDateTime.Value, scenario.Id);

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

            if (!engine.FileExists(descriptor))
            {
                var reportService        = new ScenarioCampaignFailuresReportCreator();
                var reportData           = GenerateScenarioCampaignFailuresDataShapshot(scenarioId);
                var tenantStartDayOfWeek = _tenantSettingsRepository.GetStartDayOfWeek();

                var excelFile = reportService.GenerateReport(reportData.data, reportData.snapshot, tenantStartDayOfWeek);

                engine.Upload(new S3UploadComment()
                {
                    BucketName          = descriptor.BucketName,
                    DestinationFilePath = descriptor.FileNameWithPath,
                    FileStream          = excelFile
                });
            }

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