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")); }
public void Test(List <TestObject> inputData, bool includeHeaders, char separator, string expectedResult) { Stream serializedStream = CsvSerialiser.Serialise(inputData, includeHeaders, separator); string result = StreamToStrings(serializedStream); Assert.AreEqual(expectedResult, result); }
public async Task TestAsync(List <TestObject> inputData, bool includeHeaders, char separator, string expectedResult) { Stream serializedStream = await CsvSerialiser.SerialiseAsync(inputData, includeHeaders, separator); string result = await StreamToStringsAsync(serializedStream); Assert.AreEqual(expectedResult, result); }
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")); }