diff --git a/src/NzbDrone.Core.Test/MediaCoverTests/MediaCoverServiceFixture.cs b/src/NzbDrone.Core.Test/MediaCoverTests/MediaCoverServiceFixture.cs index 602c5448f..d8cca98fe 100644 --- a/src/NzbDrone.Core.Test/MediaCoverTests/MediaCoverServiceFixture.cs +++ b/src/NzbDrone.Core.Test/MediaCoverTests/MediaCoverServiceFixture.cs @@ -8,7 +8,6 @@ using NzbDrone.Common.Disk; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Core.MediaCover; -using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Movies; using NzbDrone.Core.Movies.Events; using NzbDrone.Core.Test.Framework; @@ -33,16 +32,6 @@ public void Setup() Mocker.GetMock().Setup(m => m.GetMovie(It.Is(id => id == _movie.Id))).Returns(_movie); } - private void ExecuteAndVerifyCommand(Movie movie) - { - Subject.HandleAsync(new MovieUpdatedEvent(movie)); - - Mocker.GetMock() - .Verify(v => v.Push(It.Is(c => c.MovieId == movie.Id), It.IsAny(), It.IsAny()), Times.Once()); - - Subject.Execute(new EnsureMediaCoversCommand(movie.Id)); - } - [Test] public void should_convert_cover_urls_to_local() { @@ -86,7 +75,7 @@ public void should_resize_covers_if_main_downloaded() .Setup(v => v.FileExists(It.IsAny())) .Returns(true); - ExecuteAndVerifyCommand(_movie); + Subject.HandleAsync(new MovieUpdatedEvent(_movie)); Mocker.GetMock() .Verify(v => v.Resize(It.IsAny(), It.IsAny(), It.IsAny()), Times.Exactly(2)); @@ -103,7 +92,7 @@ public void should_resize_covers_if_missing() .Setup(v => v.FileExists(It.IsAny())) .Returns(false); - ExecuteAndVerifyCommand(_movie); + Subject.HandleAsync(new MovieUpdatedEvent(_movie)); Mocker.GetMock() .Verify(v => v.Resize(It.IsAny(), It.IsAny(), It.IsAny()), Times.Exactly(2)); @@ -124,7 +113,7 @@ public void should_not_resize_covers_if_exists() .Setup(v => v.GetFileSize(It.IsAny())) .Returns(1000); - ExecuteAndVerifyCommand(_movie); + Subject.HandleAsync(new MovieUpdatedEvent(_movie)); Mocker.GetMock() .Verify(v => v.Resize(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never()); @@ -145,7 +134,7 @@ public void should_resize_covers_if_existing_is_empty() .Setup(v => v.GetFileSize(It.IsAny())) .Returns(0); - ExecuteAndVerifyCommand(_movie); + Subject.HandleAsync(new MovieUpdatedEvent(_movie)); Mocker.GetMock() .Verify(v => v.Resize(It.IsAny(), It.IsAny(), It.IsAny()), Times.Exactly(2)); @@ -166,7 +155,7 @@ public void should_log_error_if_resize_failed() .Setup(v => v.Resize(It.IsAny(), It.IsAny(), It.IsAny())) .Throws(); - ExecuteAndVerifyCommand(_movie); + Subject.HandleAsync(new MovieUpdatedEvent(_movie)); Mocker.GetMock() .Verify(v => v.Resize(It.IsAny(), It.IsAny(), It.IsAny()), Times.Exactly(2)); diff --git a/src/NzbDrone.Core/MediaCover/EnsureMediaCoversCommand.cs b/src/NzbDrone.Core/MediaCover/EnsureMediaCoversCommand.cs deleted file mode 100644 index fa3d6cc8a..000000000 --- a/src/NzbDrone.Core/MediaCover/EnsureMediaCoversCommand.cs +++ /dev/null @@ -1,18 +0,0 @@ -using NzbDrone.Core.Messaging.Commands; - -namespace NzbDrone.Core.MediaCover -{ - public class EnsureMediaCoversCommand : Command - { - public int MovieId { get; set; } - - public EnsureMediaCoversCommand() - { - } - - public EnsureMediaCoversCommand(int movieId) - { - MovieId = movieId; - } - } -} diff --git a/src/NzbDrone.Core/MediaCover/MediaCoverService.cs b/src/NzbDrone.Core/MediaCover/MediaCoverService.cs index b3e215696..e49edb45f 100644 --- a/src/NzbDrone.Core/MediaCover/MediaCoverService.cs +++ b/src/NzbDrone.Core/MediaCover/MediaCoverService.cs @@ -9,7 +9,6 @@ using NzbDrone.Common.Extensions; using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; -using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Movies; using NzbDrone.Core.Movies.Events; @@ -24,10 +23,7 @@ public interface IMapCoversToLocal public class MediaCoverService : IHandleAsync, - - //IHandleAsync, IHandleAsync, - IExecute, IMapCoversToLocal { private readonly IImageResizer _resizer; @@ -36,8 +32,6 @@ public class MediaCoverService : private readonly ICoverExistsSpecification _coverExistsSpecification; private readonly IConfigFileProvider _configFileProvider; private readonly IEventAggregator _eventAggregator; - private readonly IManageCommandQueue _commandQueue; - private readonly IMovieService _movieService; private readonly Logger _logger; private readonly string _coverRootFolder; @@ -53,8 +47,6 @@ public MediaCoverService(IImageResizer resizer, ICoverExistsSpecification coverExistsSpecification, IConfigFileProvider configFileProvider, IEventAggregator eventAggregator, - IManageCommandQueue commandQueue, - IMovieService movieService, Logger logger) { _resizer = resizer; @@ -63,8 +55,6 @@ public MediaCoverService(IImageResizer resizer, _coverExistsSpecification = coverExistsSpecification; _configFileProvider = configFileProvider; _eventAggregator = eventAggregator; - _commandQueue = commandQueue; - _movieService = movieService; _logger = logger; _coverRootFolder = appFolderInfo.GetMediaCoverPath(); @@ -85,11 +75,11 @@ public void ConvertToLocalUrls(int movieId, IEnumerable covers) mediaCover.Url = _configFileProvider.UrlBase + @"/MediaCover/" + movieId + "/" + mediaCover.CoverType.ToString().ToLower() + ".jpg"; - /*if (_diskProvider.FileExists(filePath)) + if (_diskProvider.FileExists(filePath)) { var lastWrite = _diskProvider.FileGetLastWrite(filePath); mediaCover.Url += "?lastWrite=" + lastWrite.Ticks; - }*/ + } } } @@ -98,7 +88,7 @@ private string GetMovieCoverPath(int movieId) return Path.Combine(_coverRootFolder, movieId.ToString()); } - private void EnsureCovers(Movie movie, int retried = 0) + private void EnsureCovers(Movie movie) { var toResize = new List>(); @@ -116,25 +106,7 @@ private void EnsureCovers(Movie movie, int retried = 0) } catch (WebException e) { - if (e.Status == WebExceptionStatus.ProtocolError) - { - _logger.Warn(e, "Couldn't download media cover for {0}, likely the cover doesn't exist for this movie. {1}", movie, e.Message); - } - else - { - _logger.Warn(e, "Couldn't download media cover for {0}. {1}", movie, e.Message); - if (retried < 3) - { - retried += 1; - _logger.Warn("Retrying for the {0}. time in ten seconds.", retried); - System.Threading.Thread.Sleep(10 * 1000); - EnsureCovers(movie, retried); - } - else - { - _logger.Warn(e, "Couldn't download media cover even after retrying five times :(."); - } - } + _logger.Warn("Couldn't download media cover for {0}. {1}", movie, e.Message); } catch (Exception e) { @@ -212,27 +184,10 @@ private void EnsureResizedCovers(Movie movie, MediaCover cover, bool forceResize } } - public void Execute(EnsureMediaCoversCommand command) - { - var movie = _movieService.GetMovie(command.MovieId); - EnsureCovers(movie); - _eventAggregator.PublishEvent(new MediaCoversUpdatedEvent(movie)); - } - public void HandleAsync(MovieUpdatedEvent message) { - //EnsureCovers(message.Movie); - _logger.Info("Testing: {0}, {1}", _commandQueue, message.Movie.Id); - _commandQueue.Push(new EnsureMediaCoversCommand(message.Movie.Id)); - - //_eventAggregator.PublishEvent(new MediaCoversUpdatedEvent(message.Movie)); - } - - public void HandleAsync(MovieAddedEvent message) - { - //EnsureCovers(message.Movie); - //_commandQueue.Push(new EnsureMediaCoversCommand(message.Movie.Id)); - //_eventAggregator.PublishEvent(new MediaCoversUpdatedEvent(message.Movie)); + EnsureCovers(message.Movie); + _eventAggregator.PublishEvent(new MediaCoversUpdatedEvent(message.Movie)); } public void HandleAsync(MovieDeletedEvent message)