Provider testing improvements

New: Test button for indexers in UI

Fixed: Testing download clients shows error messages in UI
Fixed: Testing notifications shows error messages in UI
This commit is contained in:
Mark McDowall
2014-07-04 01:09:48 -07:00
parent c5bd8b27fb
commit 7af782d353
70 changed files with 727 additions and 591 deletions
+18 -6
View File
@@ -1,15 +1,18 @@
using System;
using System.Collections.Generic;
using FluentValidation.Results;
using NzbDrone.Common;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Notifications.Email
{
public class Email : NotificationBase<EmailSettings>
{
private readonly IEmailService _smtpProvider;
private readonly IEmailService _emailService;
public Email(IEmailService smtpProvider)
public Email(IEmailService emailService)
{
_smtpProvider = smtpProvider;
_emailService = emailService;
}
public override string Link
@@ -20,9 +23,9 @@ namespace NzbDrone.Core.Notifications.Email
public override void OnGrab(string message)
{
const string subject = "NzbDrone [TV] - Grabbed";
var body = String.Format("{0} sent to SABnzbd queue.", message);
var body = String.Format("{0} sent to queue.", message);
_smtpProvider.SendEmail(Settings, subject, body);
_emailService.SendEmail(Settings, subject, body);
}
public override void OnDownload(DownloadMessage message)
@@ -30,11 +33,20 @@ namespace NzbDrone.Core.Notifications.Email
const string subject = "NzbDrone [TV] - Downloaded";
var body = String.Format("{0} Downloaded and sorted.", message.Message);
_smtpProvider.SendEmail(Settings, subject, body);
_emailService.SendEmail(Settings, subject, body);
}
public override void AfterRename(Series series)
{
}
public override ValidationResult Test()
{
var failures = new List<ValidationFailure>();
failures.AddIfNotNull(_emailService.Test(Settings));
return new ValidationResult(failures);
}
}
}
@@ -1,18 +1,18 @@
using System;
using System.Net;
using System.Net.Mail;
using FluentValidation.Results;
using NLog;
using NzbDrone.Core.Messaging.Commands;
using Omu.ValueInjecter;
namespace NzbDrone.Core.Notifications.Email
{
public interface IEmailService
{
void SendEmail(EmailSettings settings, string subject, string body, bool htmlBody = false);
ValidationFailure Test(EmailSettings settings);
}
public class EmailService : IEmailService, IExecute<TestEmailCommand>
public class EmailService : IEmailService
{
private readonly Logger _logger;
@@ -66,14 +66,21 @@ namespace NzbDrone.Core.Notifications.Email
}
}
public void Execute(TestEmailCommand message)
public ValidationFailure Test(EmailSettings settings)
{
var settings = new EmailSettings();
settings.InjectFrom(message);
const string body = "Success! You have properly configured your email notification settings";
SendEmail(settings, "NzbDrone - Test Notification", body);
try
{
SendEmail(settings, "NzbDrone - Test Notification", body);
}
catch (Exception ex)
{
_logger.ErrorException("Unable to send test email: " + ex.Message, ex);
return new ValidationFailure("Server", "Unable to send test email");
}
return null;
}
}
}
@@ -1,23 +0,0 @@
using NzbDrone.Core.Messaging.Commands;
namespace NzbDrone.Core.Notifications.Email
{
public class TestEmailCommand : Command
{
public override bool SendUpdatesToClient
{
get
{
return true;
}
}
public string Server { get; set; }
public int Port { get; set; }
public bool Ssl { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string From { get; set; }
public string To { get; set; }
}
}