Add download links
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -100,6 +100,7 @@ namespace LeafWeb.Web.Controllers
|
||||
return View("Index", viewModel);
|
||||
}
|
||||
|
||||
// Callback from Piscal
|
||||
public void NotifyComplete()
|
||||
{
|
||||
HangfireStartup.TriggerPiscalProcessQueue();
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,35 +73,49 @@ 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);
|
||||
|
||||
body += "Please see the attached results.";
|
||||
|
||||
var message = new MailMessage(_emailFromAddress, leafInput.Email, "LeafWeb results", body);
|
||||
|
||||
try
|
||||
if (true)
|
||||
{
|
||||
foreach (var fileStream in fileStreams)
|
||||
{
|
||||
var attachment = new Attachment(fileStream.Item2, fileStream.Item1.Filename);
|
||||
message.Attachments.Add(attachment);
|
||||
}
|
||||
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);
|
||||
}
|
||||
finally
|
||||
else
|
||||
{
|
||||
// can't dispose those memory streams until the message is sent
|
||||
foreach (var stream in fileStreams.Select(f => f.Item2))
|
||||
body += "Please see the attached results.";
|
||||
|
||||
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
|
||||
{
|
||||
stream.Dispose();
|
||||
foreach (var fileStream in fileStreams)
|
||||
{
|
||||
var attachment = new Attachment(fileStream.Item2, fileStream.Item1.Filename);
|
||||
message.Attachments.Add(attachment);
|
||||
}
|
||||
|
||||
SendMessage(message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// can't dispose those memory streams until the message is sent
|
||||
foreach (var stream in fileStreams.Select(f => f.Item2))
|
||||
{
|
||||
stream.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
+6
-5
@@ -25,13 +25,14 @@
|
||||
<add key="TimeZoneId" value="US Eastern Standard Time" />
|
||||
<add key="EmailFromAddress" value="LeafWeb <noreply@leafweb.org>" />
|
||||
<add key="AdminEmailAddresses" value="kolpacksoftware@gmail.com" />
|
||||
<add key="ProcessQueueInterval" value="*/1 * * * *"/>
|
||||
<add key="SmtpHost" value="localhost"/>
|
||||
<add key="SmtpPort" value="25"/>
|
||||
<add key="SmtpUserName" value=""/>
|
||||
<add key="SmtpPassword" value=""/>
|
||||
<add key="ProcessQueueInterval" value="*/1 * * * *" />
|
||||
<add key="SmtpHost" value="localhost" />
|
||||
<add key="SmtpPort" value="25" />
|
||||
<add key="SmtpUserName" value="" />
|
||||
<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" />
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user