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))
diff --git a/Web/Controllers/LeafInputController.cs b/Web/Controllers/LeafInputController.cs
index 5dd13da..c5655be 100644
--- a/Web/Controllers/LeafInputController.cs
+++ b/Web/Controllers/LeafInputController.cs
@@ -100,6 +100,7 @@ namespace LeafWeb.Web.Controllers
return View("Index", viewModel);
}
+ // Callback from Piscal
public void NotifyComplete()
{
HangfireStartup.TriggerPiscalProcessQueue();
diff --git a/Web/Controllers/ResultsController.cs b/Web/Controllers/ResultsController.cs
index 1e05f77..8119282 100644
--- a/Web/Controllers/ResultsController.cs
+++ b/Web/Controllers/ResultsController.cs
@@ -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();
diff --git a/Web/Services/DownloadUrlService.cs b/Web/Services/DownloadUrlService.cs
new file mode 100644
index 0000000..c936501
--- /dev/null
+++ b/Web/Services/DownloadUrlService.cs
@@ -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);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Web/Services/EmailNotificationService.cs b/Web/Services/EmailNotificationService.cs
index 67fde4f..3b0cf20 100644
--- a/Web/Services/EmailNotificationService.cs
+++ b/Web/Services/EmailNotificationService.cs
@@ -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";
+
///
/// Comma separated values
///
@@ -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);
}
diff --git a/Web/Views/Results/DownloadNotFound.cshtml b/Web/Views/Results/DownloadNotFound.cshtml
new file mode 100644
index 0000000..031fe62
--- /dev/null
+++ b/Web/Views/Results/DownloadNotFound.cshtml
@@ -0,0 +1,10 @@
+@{
+ ViewBag.Title = "Not Found";
+}
+
+
+ @ViewBag.Title
+
+
+The given download link was not found. Please contact administrator, referencing the following url:
+@Html.Raw(Request.Url)
\ No newline at end of file
diff --git a/Web/Web.config b/Web/Web.config
index f5ce4a6..6ba5e22 100644
--- a/Web/Web.config
+++ b/Web/Web.config
@@ -25,13 +25,14 @@
-
-
-
-
-
+
+
+
+
+
+
diff --git a/Web/Web.csproj b/Web/Web.csproj
index cdc793b..d309321 100644
--- a/Web/Web.csproj
+++ b/Web/Web.csproj
@@ -960,6 +960,7 @@
+
@@ -1020,6 +1021,7 @@
+
Web.config