Add download links

This commit is contained in:
2016-05-06 11:19:01 -04:00
parent 972bb04291
commit f4ebeefad1
12 changed files with 109 additions and 29 deletions
+4
View File
@@ -50,6 +50,10 @@
<HintPath>..\packages\fasterflect.2.1.3\lib\net40\Fasterflect.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MlkPwgen, Version=0.2.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MlkPwgen.0.2.0.0\lib\net45\MlkPwgen.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.2.3\lib\net45\NLog.dll</HintPath>
<Private>True</Private>
+7
View File
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using LeafWeb.Core.Entities;
using MlkPwgen;
namespace LeafWeb.Core.DAL
{
@@ -50,6 +51,11 @@ namespace LeafWeb.Core.DAL
return _db.LeafInputs.FirstOrDefault(li => li.Id == id);
}
public LeafInput GetLeafInput(string uniqueToken)
{
return _db.LeafInputs.FirstOrDefault(li => li.UniqueToken == uniqueToken);
}
public IQueryable<LeafInput> GetLeafInputs(params LeafInputStatusType[] statuses)
{
return
@@ -61,6 +67,7 @@ namespace LeafWeb.Core.DAL
public void AddLeafInput(LeafInput leafInput)
{
leafInput.Added = DateTime.Now;
leafInput.UniqueToken = PasswordGenerator.Generate(12);
_db.LeafInputs.Add(leafInput);
SetLeafInputStatusNoUpdate(leafInput, LeafInputStatusType.Pending);
_db.SaveChanges();
+5
View File
@@ -70,5 +70,10 @@ namespace LeafWeb.Core.Entities
return compressedFileStream.ToArray();
}
}
public int GetOutputFileSizeSum()
{
return OutputFiles.Sum(o => o.Contents.Length);
}
}
}
+1
View File
@@ -4,6 +4,7 @@
<package id="CsvHelper" version="2.13.2.0" targetFramework="net45" />
<package id="EntityFramework" version="6.1.3" targetFramework="net45" />
<package id="fasterflect" version="2.1.3" targetFramework="net45" />
<package id="MlkPwgen" version="0.2.0.0" targetFramework="net45" />
<package id="NLog" version="4.2.3" targetFramework="net45" />
<package id="SSH.NET" version="2013.4.7" targetFramework="net45" />
</packages>
+5 -2
View File
@@ -94,10 +94,13 @@ namespace LeafWeb.Web.Controllers
private Bitmap CombineBitmaps(IList<Bitmap> bitmaps, int columnCount = 2)
{
if (!bitmaps.Any())
return null;
// bitmaps assumed to have same dimensions, use the first one to define that
var cellWidth = bitmaps[0].Width;
var cellHeight = bitmaps[0].Height;
var width = cellWidth * 2;
var height = cellHeight * bitmaps.Count / 2;
var width = cellWidth * columnCount;
var height = cellHeight * bitmaps.Count / columnCount;
var combinedBitmap = new Bitmap(width, height);
using (var g = Graphics.FromImage(combinedBitmap))
+1
View File
@@ -100,6 +100,7 @@ namespace LeafWeb.Web.Controllers
return View("Index", viewModel);
}
// Callback from Piscal
public void NotifyComplete()
{
HangfireStartup.TriggerPiscalProcessQueue();
+5 -2
View File
@@ -19,9 +19,12 @@ namespace LeafWeb.Web.Controllers
}
[ActionLog]
public FileContentResult DownloadResults(int id)
public ActionResult Download(string token)
{
var leafInput = DataService.GetLeafInput(id);
var leafInput = DataService.GetLeafInput(token);
if (leafInput == null)
return View("DownloadNotFound");
var zip = leafInput.GetOutputFileZip();
+22
View File
@@ -0,0 +1,22 @@
using System.Configuration;
using LeafWeb.Core.Entities;
namespace LeafWeb.Web.Services
{
public class DownloadUrlService
{
private readonly string _downloadUrl;
public DownloadUrlService()
{
_downloadUrl =
ConfigurationManager.AppSettings["LeafWebUrl"]
+ ConfigurationManager.AppSettings["ResultsDownloadPath"];
}
public string GetDownloadUrl(LeafInput leafInput)
{
return string.Format(_downloadUrl, leafInput.UniqueToken);
}
}
}
+28 -7
View File
@@ -17,6 +17,9 @@ namespace LeafWeb.Web.Services
private readonly string _emailFromAddress;
private const string EmailSuccessSubject = "LeafWeb Results";
private const string EmailErrorSubject = "LeafWeb processing error";
/// <summary>
/// Comma separated values
/// </summary>
@@ -26,10 +29,14 @@ namespace LeafWeb.Web.Services
private readonly DataService _dataService;
private readonly DownloadUrlService _downloadUrlService;
public EmailNotificationService(DataService dataService)
{
_dataService = dataService;
_downloadUrlService = new DownloadUrlService();
_smtpClient = new SmtpClient(
ConfigurationManager.AppSettings["SmtpHost"],
Convert.ToInt32(ConfigurationManager.AppSettings["SmtpPort"]));
@@ -66,19 +73,32 @@ namespace LeafWeb.Web.Services
private void SendLeafWebSuccess(LeafInput leafInput)
{
var fileStreams =
(from outputFile in
leafInput.OutputFiles
select Tuple.Create(outputFile, new MemoryStream(outputFile.Contents))).ToList();
var body = $"Your leaf analysis job, {leafInput.Identifier}, has completed. ";
body += FormatWarningMessage(leafInput);
if (true)
{
var downloadUrl = _downloadUrlService.GetDownloadUrl(leafInput);
body +=
"Download results with the following link:"
+ Environment.NewLine + Environment.NewLine
+ downloadUrl;
var message = new MailMessage(_emailFromAddress, leafInput.Email, EmailSuccessSubject, body);
SendMessage(message);
}
else
{
body += "Please see the attached results.";
var message = new MailMessage(_emailFromAddress, leafInput.Email, "LeafWeb results", body);
var message = new MailMessage(_emailFromAddress, leafInput.Email, EmailSuccessSubject, body);
var fileStreams =
(from outputFile in
leafInput.OutputFiles
select Tuple.Create(outputFile, new MemoryStream(outputFile.Contents))).ToList();
try
{
foreach (var fileStream in fileStreams)
@@ -98,6 +118,7 @@ namespace LeafWeb.Web.Services
}
}
}
}
private void SendLeafWebError(LeafInput leafInput, string errorMessage)
{
@@ -109,7 +130,7 @@ namespace LeafWeb.Web.Services
body += FormatWarningMessage(leafInput);
var message = new MailMessage(_emailFromAddress, leafInput.Email, "LeafWeb processing error", body);
var message = new MailMessage(_emailFromAddress, leafInput.Email, EmailErrorSubject, body);
SendMessage(message);
}
+10
View File
@@ -0,0 +1,10 @@
@{
ViewBag.Title = "Not Found";
}
<h1>
@ViewBag.Title
</h1>
<p>The given download link was not found. Please contact administrator, referencing the following url:</p>
<code>@Html.Raw(Request.Url)</code>
+1
View File
@@ -32,6 +32,7 @@
<add key="SmtpPassword" value="" />
<add key="LeafWebUrl" value="http://192.168.1.133:1640/" />
<add key="PiscalNotifyCompleteUrlPath" value="LeafInput/NotifyComplete" />
<add key="ResultsDownloadPath" value="Results/Download?token={0}" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
+2
View File
@@ -960,6 +960,7 @@
<Compile Include="Backload\Controller\BackloadController.obsolete.cs" />
<Compile Include="Backload\Helper\ResultCreator.Classic.cs" />
<Compile Include="Backload\Helper\ResultCreator.cs" />
<Compile Include="Services\DownloadUrlService.cs" />
<Compile Include="Services\LeafGasCharter.cs" />
<Compile Include="Controllers\ControllerBase.cs" />
<Compile Include="Controllers\FluxnetSiteController.cs" />
@@ -1020,6 +1021,7 @@
<Content Include="Views\Shared\EditorTemplates\SelectListViewModel.cshtml" />
<Content Include="Views\Results\Index.cshtml" />
<Content Include="Views\Pages\Information.cshtml" />
<Content Include="Views\Results\DownloadNotFound.cshtml" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>