Exemplo n.º 1
0
        public IActionResult Download(long id)
        {
            var filename = _fileEntryService.GetSingleNoTracking(x => x.Id == id, select: x => x.Name);
            var name     = Path.GetFileNameWithoutExtension(filename);

            var files = new List <FileInfo> {
                new FileInfo(Path.Combine(_fileSystemOptions.Value.Content, filename)),
                new FileInfo(Path.Combine(_fileSystemOptions.Value.Content, $"{ name }.shuffled.csv")),
                new FileInfo(Path.Combine(_fileSystemOptions.Value.Content, $"{ name }.training.csv")),
                new FileInfo(Path.Combine(_fileSystemOptions.Value.Content, $"{ name }.evaluate.csv")),
                new FileInfo(Path.Combine(_fileSystemOptions.Value.Content, $"{name}.normalized.training.csv")),
                new FileInfo(Path.Combine(_fileSystemOptions.Value.Content, $"{name}.normalized.evaluate.csv")),
                new FileInfo(Path.Combine(_fileSystemOptions.Value.Content, $"{name}.analyst.ega")),
                new FileInfo(Path.Combine(_fileSystemOptions.Value.Content, $"{name}.evaluate.out.csv")),
            };

            using (var memoryStream = new MemoryStream()) {
                using (var ziparchive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true)) {
                    foreach (var file in files)
                    {
                        if (file.Exists)
                        {
                            ziparchive.CreateEntryFromFile(file.FullName, file.Name);
                        }
                    }
                }

                return(File(memoryStream.ToArray(), "application/zip", $"{name}.zip"));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Download(long id)
        {
            var filename = _fileEntryService.GetSingleNoTracking(x => x.Id == id, select: x => x.Name);

            if (filename == null)
            {
                return(Content("filename not present"));
            }

            var path = Path.Combine(_fileSystemOptions.Value.Content, filename);

            var memory = new MemoryStream();

            using (var stream = new FileStream(path, FileMode.Open)) {
                await stream.CopyToAsync(memory);
            }
            memory.Position = 0;
            return(File(memory, GetContentType(path), Path.GetFileName(path)));
        }