Better notification messages

This commit is contained in:
Mark McDowall 2013-08-01 00:11:42 -07:00
parent 125deb3931
commit eaa7b39025
4 changed files with 35 additions and 19 deletions

View File

@ -102,6 +102,13 @@ namespace NzbDrone.Core.Test.NotificationTests
.With(p => p.EpisodeNumbers = new int[] {1})
.Build();
var localEpisode = Builder<LocalEpisode>.CreateNew()
.With(e => e.Series = series)
.With(e => e.ParsedEpisodeInfo = parsedEpisodeInfo)
.With(e => e.Episodes = Builder<Episode>.CreateListOfSize(1)
.Build().ToList())
.Build();
Mocker.GetMock<INotificationRepository>()
.Setup(s => s.All())
.Returns(notifications);
@ -111,7 +118,7 @@ namespace NzbDrone.Core.Test.NotificationTests
.Setup(s => s.OnDownload(It.IsAny<string>(), series))
.Throws(new SocketException());
Subject.Handle(new EpisodeDownloadedEvent(parsedEpisodeInfo, series));
Subject.Handle(new EpisodeDownloadedEvent(localEpisode));
Mocker.GetMock<Notifications.Xbmc.Xbmc>()
.Verify(v => v.OnDownload(It.IsAny<string>(), series), Times.Once());

View File

@ -77,7 +77,7 @@ namespace NzbDrone.Core.MediaFiles
var destinationFilename = _buildFileNames.BuildFilePath(localEpisode.Series, localEpisode.SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path));
episodeFile = MoveFile(episodeFile, destinationFilename);
_messageAggregator.PublishEvent(new EpisodeDownloadedEvent(localEpisode.ParsedEpisodeInfo, localEpisode.Series));
_messageAggregator.PublishEvent(new EpisodeDownloadedEvent(localEpisode));
return episodeFile;
}

View File

@ -6,13 +6,11 @@ namespace NzbDrone.Core.MediaFiles.Events
{
public class EpisodeDownloadedEvent : IEvent
{
public ParsedEpisodeInfo ParsedEpisodeInfo { get; private set; }
public Series Series { get; set; }
public LocalEpisode Episode { get; private set; }
public EpisodeDownloadedEvent(ParsedEpisodeInfo parsedEpisodeInfo, Series series)
public EpisodeDownloadedEvent(LocalEpisode episode)
{
ParsedEpisodeInfo = parsedEpisodeInfo;
Series = series;
Episode = episode;
}
}
}

View File

@ -135,24 +135,35 @@ namespace NzbDrone.Core.Notifications
return instance;
}
private string GetMessage(ParsedEpisodeInfo parsedEpisodeInfo, Series series)
private string GetMessage(Series series, List<Episode> episodes, QualityModel quality)
{
if (series.SeriesType == SeriesTypes.Daily)
{
return String.Format("{0} - {1}",
series.Title,
parsedEpisodeInfo.AirDate.Value.ToString(Episode.AIR_DATE_FORMAT));
var episode = episodes.First();
return String.Format("{0} - {1} - {2} [{3}]",
series.Title,
episode.AirDate,
episode.Title,
quality);
}
return String.Format("{0} - {1}{2}",
series.Title,
parsedEpisodeInfo.SeasonNumber,
String.Concat(parsedEpisodeInfo.EpisodeNumbers.Select(i => String.Format("x{0:00}", i))));
var episodeNumbers = String.Concat(episodes.Select(e => e.EpisodeNumber)
.Select(i => String.Format("x{0:00}", i)));
var episodeTitles = String.Join(" + ", episodes.Select(e => e.Title));
return String.Format("{0} - {1}{2} - {3} {4}",
series.Title,
episodes.First().SeasonNumber,
episodeNumbers,
episodeTitles,
quality);
}
public void Handle(EpisodeGrabbedEvent message)
{
var messageBody = GetMessage(message.Episode.ParsedEpisodeInfo, message.Episode.Series);
var messageBody = GetMessage(message.Episode.Series, message.Episode.Episodes, message.Episode.ParsedEpisodeInfo.Quality);
foreach (var notification in All().Where(n => n.OnGrab))
{
@ -170,13 +181,13 @@ namespace NzbDrone.Core.Notifications
public void Handle(EpisodeDownloadedEvent message)
{
var messageBody = GetMessage(message.ParsedEpisodeInfo, message.Series);
var messageBody = GetMessage(message.Episode.Series, message.Episode.Episodes, message.Episode.ParsedEpisodeInfo.Quality);
foreach (var notification in All().Where(n => n.OnDownload))
{
try
{
notification.Instance.OnDownload(messageBody, message.Series);
notification.Instance.OnDownload(messageBody, message.Episode.Series);
}
catch (Exception ex)