Add Zip download link
This commit is contained in:
@@ -61,6 +61,7 @@
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
|
||||
namespace LeafWeb.Core.Entities
|
||||
@@ -41,5 +43,24 @@ namespace LeafWeb.Core.Entities
|
||||
{
|
||||
return $"{Id}_{Identifier}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains all output files in a zip
|
||||
/// </summary>
|
||||
public byte[] GetOutputFileZip()
|
||||
{
|
||||
using (var compressedFileStream = new MemoryStream())
|
||||
using (var archive = new ZipArchive(compressedFileStream, ZipArchiveMode.Create, true))
|
||||
{
|
||||
foreach (var outputFile in OutputFiles)
|
||||
{
|
||||
var entry = archive.CreateEntry(outputFile.Filename);
|
||||
using (var originalFileStream = new MemoryStream(outputFile.Contents))
|
||||
using (var entryStream = entry.Open())
|
||||
originalFileStream.CopyTo(entryStream);
|
||||
}
|
||||
return compressedFileStream.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using LeafWeb.Core.Entities;
|
||||
@@ -100,6 +104,15 @@ namespace LeafWeb.Web.Controllers
|
||||
return View("Index", viewModel);
|
||||
}
|
||||
|
||||
public FileContentResult DownloadResults(int d)
|
||||
{
|
||||
var leafInput = DataService.GetLeafInput(d);
|
||||
|
||||
var zip = leafInput.GetOutputFileZip();
|
||||
|
||||
return new FileContentResult(zip, "application/zip") {FileDownloadName = leafInput.Identifier + ".zip"};
|
||||
}
|
||||
|
||||
private FileInfo[] GetBackloadDirectoryFiles(string directoryName)
|
||||
{
|
||||
var path = Path.Combine(Server.MapPath("~/Files/"), directoryName + "\\");
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
<package id="NLog.Config" version="4.2.3" targetFramework="net45" />
|
||||
<package id="NLog.Schema" version="4.0.0" targetFramework="net45" />
|
||||
<package id="Owin" version="1.0" targetFramework="net45" />
|
||||
<package id="Polly" version="4.2.0" targetFramework="net45" />
|
||||
<package id="Twitter.Bootstrap.Less" version="3.3.6" targetFramework="net45" />
|
||||
<package id="WebGrease" version="1.6.0" targetFramework="net45" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user