Add download links
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user