1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 02:22:31 +01:00

less reflectionee Command publishing.

This commit is contained in:
kay.one 2013-05-20 19:49:08 -07:00
parent c122502634
commit 587eba6324

View File

@ -76,23 +76,18 @@ public void PublishCommand<TCommand>(TCommand command) where TCommand : class, I
_logger.Trace("Publishing {0}", command.GetType().Name);
var handler = _serviceFactory.Build(handlerContract);
var handler = (IExecute<TCommand>)_serviceFactory.Build(handlerContract);
_logger.Debug("{0} -> {1}", command.GetType().Name, handler.GetType().Name);
try
{
handlerContract.GetMethod("Execute").Invoke(handler, new object[] { command });
handler.Execute(command);
PublishEvent(new CommandCompletedEvent(command));
}
catch (TargetInvocationException e)
catch (Exception e)
{
PublishEvent(new CommandFailedEvent(command, e));
if (e.InnerException != null)
{
throw e.InnerException;
}
throw;
}
finally
@ -108,9 +103,8 @@ public void PublishCommand(string commandTypeName)
var commandType = _serviceFactory.GetImplementations(typeof(ICommand))
.Single(c => c.FullName.Equals(commandTypeName, StringComparison.InvariantCultureIgnoreCase));
//json.net is better at creating objects
var command = Json.Deserialize("{}", commandType);
PublishCommand((ICommand)command);
dynamic command = Json.Deserialize("{}", commandType);
PublishCommand(command);
}
}
}