mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 02:37:08 -07:00
added commands.
they can be triggered using the api api/command/
This commit is contained in:
parent
68ee71ea81
commit
182192e0ba
31 changed files with 265 additions and 74 deletions
35
NzbDrone.Api/Commands/CommandModule.cs
Normal file
35
NzbDrone.Api/Commands/CommandModule.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Api.Extensions;
|
||||
using NzbDrone.Common.Messaging;
|
||||
|
||||
namespace NzbDrone.Api.Commands
|
||||
{
|
||||
public class CommandModule : NzbDroneRestModule<CommandResource>
|
||||
{
|
||||
private readonly IMessageAggregator _messageAggregator;
|
||||
private readonly IEnumerable<ICommand> _commands;
|
||||
|
||||
public CommandModule(IMessageAggregator messageAggregator, IEnumerable<ICommand> commands)
|
||||
{
|
||||
_messageAggregator = messageAggregator;
|
||||
_commands = commands;
|
||||
|
||||
CreateResource = RunCommand;
|
||||
}
|
||||
|
||||
private CommandResource RunCommand(CommandResource resource)
|
||||
{
|
||||
var commandType = _commands.Single(c => c.GetType().Name.Replace("Command", "").Equals(resource.Command, StringComparison.InvariantCultureIgnoreCase))
|
||||
.GetType();
|
||||
var command = (object)Request.Body.FromJson<ICommand>(commandType);
|
||||
var method = typeof(IMessageAggregator).GetMethod("PublishCommand");
|
||||
var genericMethod = method.MakeGenericMethod(commandType);
|
||||
genericMethod.Invoke(_messageAggregator, new[] { command });
|
||||
|
||||
return resource;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue