2016-12-23 21:45:24 +00:00
|
|
|
|
using System.IO;
|
2014-07-23 23:43:54 +00:00
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Common.Disk;
|
2014-12-02 06:26:25 +00:00
|
|
|
|
using NzbDrone.Common.Extensions;
|
2014-07-23 23:43:54 +00:00
|
|
|
|
using NzbDrone.Common.Instrumentation.Extensions;
|
|
|
|
|
using NzbDrone.Core.Messaging.Commands;
|
|
|
|
|
using NzbDrone.Core.Messaging.Events;
|
|
|
|
|
using NzbDrone.Core.Organizer;
|
|
|
|
|
using NzbDrone.Core.Tv.Commands;
|
|
|
|
|
using NzbDrone.Core.Tv.Events;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Tv
|
|
|
|
|
{
|
|
|
|
|
public class MoveSeriesService : IExecute<MoveSeriesCommand>
|
|
|
|
|
{
|
|
|
|
|
private readonly ISeriesService _seriesService;
|
|
|
|
|
private readonly IBuildFileNames _filenameBuilder;
|
2014-11-15 00:42:22 +00:00
|
|
|
|
private readonly IDiskTransferService _diskTransferService;
|
2014-07-23 23:43:54 +00:00
|
|
|
|
private readonly IEventAggregator _eventAggregator;
|
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
|
|
public MoveSeriesService(ISeriesService seriesService,
|
|
|
|
|
IBuildFileNames filenameBuilder,
|
2014-11-15 00:42:22 +00:00
|
|
|
|
IDiskTransferService diskTransferService,
|
2014-07-23 23:43:54 +00:00
|
|
|
|
IEventAggregator eventAggregator,
|
|
|
|
|
Logger logger)
|
|
|
|
|
{
|
|
|
|
|
_seriesService = seriesService;
|
|
|
|
|
_filenameBuilder = filenameBuilder;
|
2014-11-15 00:42:22 +00:00
|
|
|
|
_diskTransferService = diskTransferService;
|
2014-07-23 23:43:54 +00:00
|
|
|
|
_eventAggregator = eventAggregator;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Execute(MoveSeriesCommand message)
|
|
|
|
|
{
|
|
|
|
|
var series = _seriesService.GetSeries(message.SeriesId);
|
|
|
|
|
var source = message.SourcePath;
|
|
|
|
|
var destination = message.DestinationPath;
|
|
|
|
|
|
|
|
|
|
if (!message.DestinationRootFolder.IsNullOrWhiteSpace())
|
|
|
|
|
{
|
|
|
|
|
_logger.Debug("Buiding destination path using root folder: {0} and the series title", message.DestinationRootFolder);
|
|
|
|
|
destination = Path.Combine(message.DestinationRootFolder, _filenameBuilder.GetSeriesFolder(series));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_logger.ProgressInfo("Moving {0} from '{1}' to '{2}'", series.Title, source, destination);
|
|
|
|
|
|
|
|
|
|
//TODO: Move to transactional disk operations
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-11-15 00:42:22 +00:00
|
|
|
|
_diskTransferService.TransferFolder(source, destination, TransferMode.Move);
|
2014-07-23 23:43:54 +00:00
|
|
|
|
}
|
|
|
|
|
catch (IOException ex)
|
|
|
|
|
{
|
2017-01-05 23:32:17 +00:00
|
|
|
|
_logger.Error(ex, "Unable to move series from '{0}' to '{1}'", source, destination);
|
2014-07-23 23:43:54 +00:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_logger.ProgressInfo("{0} moved successfully to {1}", series.Title, series.Path);
|
|
|
|
|
|
|
|
|
|
//Update the series path to the new path
|
|
|
|
|
series.Path = destination;
|
|
|
|
|
series = _seriesService.UpdateSeries(series);
|
|
|
|
|
|
|
|
|
|
_eventAggregator.PublishEvent(new SeriesMovedEvent(series, source, destination));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|