예제 #1
0
        public IActionResult DownloadDiagnosisKeysFile(string packageName)
        {
            _logger.LogInformation("DownloadDiagnosisKeysFile endpoint called");
            try
            {
                ZipFileInfo packageInfo    = _zipFileInfoService.CreateZipFileInfoFromPackageName(packageName);
                string      zipFilesFolder = _configuration["ZipFilesFolder"];

                _logger.LogInformation("Package Date: " + packageInfo.PackageDate);
                _logger.LogInformation("Add days: " + DateTime.UtcNow.Date.AddDays(-14));
                _logger.LogInformation("Utc now:" + DateTime.UtcNow);

                if (!IsDateValid(packageInfo.PackageDate, packageName))
                {
                    return(BadRequest("Package Date is invalid"));
                }

                var packageExists = _zipFileInfoService.CheckIfPackageExists(packageInfo, zipFilesFolder);
                if (packageExists)
                {
                    var zipFileContent     = _zipFileInfoService.ReadPackage(packageInfo, zipFilesFolder);
                    var currentBatchNumber = packageInfo.BatchNumber;
                    packageInfo.BatchNumber++;
                    var nextPackageExists = _zipFileInfoService.CheckIfPackageExists(packageInfo, zipFilesFolder);

                    AddResponseHeader(nextPackageExists, currentBatchNumber);
                    _logger.LogInformation("Zip package fetched successfully");
                    return(File(zipFileContent, System.Net.Mime.MediaTypeNames.Application.Zip));
                }
                else
                {
                    _logger.LogInformation("Package does not exist");
                    return(NoContent());
                }
            }
            catch (FormatException e)
            {
                _logger.LogError("Error when parsing data: " + e);
                return(BadRequest(e.Message));
            }
            catch (Exception e)
            {
                _logger.LogError("Error when downloading package: " + e);
                return(StatusCode(500));
            }
        }
예제 #2
0
        public void ReadPackageTestShouldReadRightFile()
        {
            var         date        = DateTime.UtcNow;
            ZipFileInfo zipFileInfo = new ZipFileInfo()
            {
                BatchNumber = 2,
                Origin      = "dk",
                PackageDate = date
            };
            string zipFilesFolder = "ZipFilesFolder";

            byte[] expectedContent = new byte[] { 1, 2, 3, 4 };
            _fileSystem.Setup(x => x.ReadFile(Path.Join(zipFilesFolder, zipFileInfo.Origin.ToLower(), zipFileInfo.FileName))).Returns(expectedContent);
            var actualContent = _fileInfoService.ReadPackage(zipFileInfo, zipFilesFolder);

            Assert.AreEqual(expectedContent, actualContent);
        }