1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-12 11:15:43 +02:00

added sample event for series added

This commit is contained in:
kay.one 2013-02-23 12:34:51 -08:00
parent 66972e5bc6
commit c35682376e
5 changed files with 31 additions and 18 deletions

View File

@ -10,20 +10,12 @@ namespace NzbDrone.Common.Test.EventingTests
[TestFixture]
public class ServiceNameFixture : TestBase
{
private EventAggregator _aggregator;
[SetUp]
public void Setup()
{
_aggregator = new EventAggregator(TestLogger, null);
}
[Test]
public void should_publish_event_to_handlers()
{
var intHandler = new Mock<IHandle<int>>();
_aggregator = new EventAggregator(TestLogger, new List<IHandle> { intHandler.Object });
_aggregator.Publish(12);
var aggregator = new EventAggregator(TestLogger, new List<IHandle> { intHandler.Object });
aggregator.Publish(12);
intHandler.Verify(c => c.Handle(12), Times.Once());
}
@ -31,23 +23,23 @@ public void should_publish_event_to_handlers()
[Test]
public void should_publish_to_more_than_one_handler()
{
var intHandler1 =new Mock<IHandle<int>>();
var intHandler1 = new Mock<IHandle<int>>();
var intHandler2 = new Mock<IHandle<int>>();
_aggregator = new EventAggregator(TestLogger, new List<IHandle> { intHandler1.Object, intHandler2.Object });
_aggregator.Publish(12);
var aggregator = new EventAggregator(TestLogger, new List<IHandle> { intHandler1.Object, intHandler2.Object });
aggregator.Publish(12);
intHandler1.Verify(c => c.Handle(12), Times.Once());
intHandler2.Verify(c => c.Handle(12), Times.Once());
}
[Test]
public void should_not_publish_to_incompatible_handlers()
{
var intHandler = new Mock<IHandle<int>>();
var stringHandler = new Mock<IHandle<string>>();
_aggregator = new EventAggregator(TestLogger, new List<IHandle> { intHandler.Object, stringHandler.Object });
var aggregator = new EventAggregator(TestLogger, new List<IHandle> { intHandler.Object, stringHandler.Object });
_aggregator.Publish(12);
aggregator.Publish(12);
intHandler.Verify(c => c.Handle(12), Times.Once());
stringHandler.Verify(c => c.Handle(It.IsAny<string>()), Times.Never());

View File

@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Common.EnsureThat;
namespace NzbDrone.Common.Eventing
{
@ -11,6 +12,7 @@ public class EventAggregator : IEventAggregator
public EventAggregator(Logger logger, IEnumerable<IHandle> handlers)
{
Ensure.That(() => handlers).HasItems();
_logger = logger;
_handlers = handlers;
}

View File

@ -306,6 +306,7 @@
<Compile Include="Model\LanguageType.cs" />
<Compile Include="Model\MisnamedEpisodeModel.cs" />
<Compile Include="Tv\EpisodeService.cs" />
<Compile Include="Tv\Events\SeriesAddedEvent.cs" />
<Compile Include="Tv\SeasonRepository.cs" />
<Compile Include="Tv\SeriesRepository.cs" />
<Compile Include="Tv\QualityModel.cs" />

View File

@ -0,0 +1,12 @@
namespace NzbDrone.Core.Tv.Events
{
public class SeriesAddedEvent
{
public Series Series { get; private set; }
public SeriesAddedEvent(Series series)
{
Series = series;
}
}
}

View File

@ -4,9 +4,11 @@
using System.Text.RegularExpressions;
using NLog;
using NzbDrone.Common.EnsureThat;
using NzbDrone.Common.Eventing;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Tv.Events;
namespace NzbDrone.Core.Tv
{
@ -26,6 +28,7 @@ public class SeriesService : ISeriesService
private readonly TvDbProvider _tvDbProvider;
private readonly MetadataProvider _metadataProvider;
private readonly TvRageMappingProvider _tvRageMappingProvider;
private readonly IEventAggregator _eventAggregator;
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
@ -33,7 +36,7 @@ public class SeriesService : ISeriesService
public SeriesService(ISeriesRepository seriesRepository, ConfigProvider configProviderProvider,
TvDbProvider tvDbProviderProvider, SceneMappingProvider sceneNameMappingProvider, MetadataProvider metadataProvider,
TvRageMappingProvider tvRageMappingProvider)
TvRageMappingProvider tvRageMappingProvider, IEventAggregator eventAggregator)
{
_seriesRepository = seriesRepository;
_configProvider = configProviderProvider;
@ -41,6 +44,7 @@ public SeriesService(ISeriesRepository seriesRepository, ConfigProvider configPr
_sceneNameMappingProvider = sceneNameMappingProvider;
_metadataProvider = metadataProvider;
_tvRageMappingProvider = tvRageMappingProvider;
_eventAggregator = eventAggregator;
}
@ -128,6 +132,8 @@ public void AddSeries(string title, string path, int tvDbSeriesId, int qualityPr
repoSeries.CustomStartDate = airedAfter;
_seriesRepository.Insert(repoSeries);
_eventAggregator.Publish(new SeriesAddedEvent(repoSeries));
}
@ -156,7 +162,7 @@ public void UpdateFromSeriesEditor(IList<Series> editedSeries)
/// </summary>
/// <param name = "rawTime">The TVDB AirsTime</param>
/// <returns>String that contains the AirTimes</returns>
private static readonly Regex timeRegex = new Regex(@"^(?<time>\d+:?\d*)\W*(?<meridiem>am|pm)?", RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static string CleanAirsTime(string rawTime)
{