Better notification messages

pull/4/head
Mark McDowall 12 years ago
parent 125deb3931
commit eaa7b39025

@ -102,6 +102,13 @@ namespace NzbDrone.Core.Test.NotificationTests
.With(p => p.EpisodeNumbers = new int[] {1}) .With(p => p.EpisodeNumbers = new int[] {1})
.Build(); .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>() Mocker.GetMock<INotificationRepository>()
.Setup(s => s.All()) .Setup(s => s.All())
.Returns(notifications); .Returns(notifications);
@ -111,7 +118,7 @@ namespace NzbDrone.Core.Test.NotificationTests
.Setup(s => s.OnDownload(It.IsAny<string>(), series)) .Setup(s => s.OnDownload(It.IsAny<string>(), series))
.Throws(new SocketException()); .Throws(new SocketException());
Subject.Handle(new EpisodeDownloadedEvent(parsedEpisodeInfo, series)); Subject.Handle(new EpisodeDownloadedEvent(localEpisode));
Mocker.GetMock<Notifications.Xbmc.Xbmc>() Mocker.GetMock<Notifications.Xbmc.Xbmc>()
.Verify(v => v.OnDownload(It.IsAny<string>(), series), Times.Once()); .Verify(v => v.OnDownload(It.IsAny<string>(), series), Times.Once());

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

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

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

Loading…
Cancel
Save