2013-04-27 04:03:34 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NzbDrone.Api.Extensions;
|
2013-05-13 02:36:23 +02:00
|
|
|
|
using NzbDrone.Common.Composition;
|
2013-04-27 04:03:34 +02:00
|
|
|
|
using NzbDrone.Common.Messaging;
|
2013-05-20 01:17:32 +02:00
|
|
|
|
using NzbDrone.Core.Download;
|
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
2013-04-27 04:03:34 +02:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.Commands
|
|
|
|
|
{
|
|
|
|
|
public class CommandModule : NzbDroneRestModule<CommandResource>
|
|
|
|
|
{
|
|
|
|
|
private readonly IMessageAggregator _messageAggregator;
|
2013-05-13 02:36:23 +02:00
|
|
|
|
private readonly IContainer _container;
|
2013-04-27 04:03:34 +02:00
|
|
|
|
|
2013-05-13 02:36:23 +02:00
|
|
|
|
public CommandModule(IMessageAggregator messageAggregator, IContainer container)
|
2013-04-27 04:03:34 +02:00
|
|
|
|
{
|
|
|
|
|
_messageAggregator = messageAggregator;
|
2013-05-13 02:36:23 +02:00
|
|
|
|
_container = container;
|
2013-04-27 04:03:34 +02:00
|
|
|
|
|
|
|
|
|
CreateResource = RunCommand;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private CommandResource RunCommand(CommandResource resource)
|
|
|
|
|
{
|
2013-05-13 02:36:23 +02:00
|
|
|
|
var commandType =
|
|
|
|
|
_container.GetImplementations(typeof(ICommand))
|
|
|
|
|
.Single(c => c.Name.Replace("Command", "")
|
2013-05-13 04:52:55 +02:00
|
|
|
|
.Equals(resource.Command, StringComparison.InvariantCultureIgnoreCase));
|
2013-04-27 04:03:34 +02:00
|
|
|
|
|
|
|
|
|
|
2013-05-08 07:47:15 +02:00
|
|
|
|
var command = Request.Body.FromJson<ICommand>(commandType);
|
|
|
|
|
|
|
|
|
|
_messageAggregator.PublishCommand(command);
|
|
|
|
|
|
|
|
|
|
return resource;
|
2013-04-27 04:03:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|