1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-13 22:43:35 +01:00
Radarr/NzbDrone.Api/Commands/CommandModule.cs

40 lines
1.2 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Api.Extensions;
using NzbDrone.Common.Composition;
using NzbDrone.Common.Messaging;
2013-05-20 01:17:32 +02:00
using NzbDrone.Core.Download;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Api.Commands
{
public class CommandModule : NzbDroneRestModule<CommandResource>
{
private readonly IMessageAggregator _messageAggregator;
private readonly IContainer _container;
public CommandModule(IMessageAggregator messageAggregator, IContainer container)
{
_messageAggregator = messageAggregator;
_container = container;
CreateResource = RunCommand;
}
private CommandResource RunCommand(CommandResource resource)
{
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));
var command = Request.Body.FromJson<ICommand>(commandType);
_messageAggregator.PublishCommand(command);
return resource;
}
}
}