Esempio n. 1
0
 private Task <List <AggregateReportExportItem> > GetResults(List <AggregateReportExportItem> export = null) =>
 sut.AddReverseDnsInfoToExport(
     export ?? new List <AggregateReportExportItem>
 {
     new AggregateReportExportItem("", "192.168.1.1", "", 0, "", "", "", "", DateTime.Now)
 },
     DateTime.Now);
Esempio n. 2
0
        public async Task <IActionResult> GetAggregateReportExport(int id, DateTime date)
        {
            int?userId = User.GetId();

            if (!userId.HasValue)
            {
                _log.LogWarning("Forbid unknown user.");
                return(Forbid());
            }

            DomainPermissions domainPermissions = await _permissionDao.GetPermissions(userId.Value, id);

            if (!domainPermissions.DomainPermission)
            {
                _log.LogWarning($"Domain {id} not found for user {userId}.");
                return(NotFound(new ErrorResponse($"No domain found for ID {id}.")));
            }

            if (!domainPermissions.AggregatePermission)
            {
                _log.LogWarning($"Forbid user {userId}");
                return(Forbid());
            }

            List <AggregateReportExportItem> export = await _reverseDnsApi.AddReverseDnsInfoToExport(
                await _domainStatusDao.GetAggregateReportExport(id, date), date);

            Stream stream = await CsvSerialiser.SerialiseAsync(export);

            return(File(stream, "application/octet-stream", $"AggregateReportExport-{id}-{date:yyyy-MM-dd}.csv"));
        }
Esempio n. 3
0
        public async Task <IActionResult> GetAggregateReportExport(int id, DateTime startDate, DateTime endDate)
        {
            int?userId = User.GetId();

            if (!userId.HasValue)
            {
                _log.LogWarning("Forbid unknown user.");
                return(Forbid());
            }

            DomainPermissions domainPermissions = await _permissionDao.GetPermissions(userId.Value, id);

            if (!domainPermissions.DomainPermission)
            {
                _log.LogWarning($"Domain {id} not found for user {userId}.");
                return(NotFound(new ErrorResponse($"No domain found for ID {id}.")));
            }

            if (!domainPermissions.AggregatePermission)
            {
                _log.LogWarning($"Forbid user {userId}");
                return(Forbid());
            }

            Stopwatch stopwatch = Stopwatch.StartNew();

            List <AggregateReportExportItem> results =
                await _domainStatusDao.GetAggregateReportExport(id, startDate, endDate);

            _log.LogInformation($"Took {stopwatch.Elapsed.Seconds} seconds to get aggregate data for domain ID {id}.");

            stopwatch.Restart();

            List <AggregateReportExportItem> export = results
                                                      .GroupBy(_ => _.EffectiveDate)
                                                      .ToDictionary(_ => _.Key, _ => _.ToList())
                                                      .Select(_ => _reverseDnsApi.AddReverseDnsInfoToExport(_.Value, _.Key))
                                                      .Batch(10)
                                                      .Select(async _ => await Task.WhenAll(_))
                                                      .SelectMany(_ => _.Result.SelectMany(x => x))
                                                      .OrderByDescending(_ => _.EffectiveDate)
                                                      .ToList();

            _log.LogInformation($"Took {stopwatch.Elapsed.Seconds} seconds to get reverse dns data for domain ID {id}.");

            stopwatch.Stop();

            Stream stream = await CsvSerialiser.SerialiseAsync(export);

            return(File(stream,
                        "application/octet-stream",
                        $"AggregateReportExport_{id}_{startDate:yyyy-MM-dd}_{endDate:yyyy-MM-dd}.csv"));
        }