From 587eba63240c72f1e44a62fab3c72df28fe457d1 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Mon, 20 May 2013 19:49:08 -0700 Subject: [PATCH] less reflectionee Command publishing. --- NzbDrone.Common/Messaging/MessageAggregator.cs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/NzbDrone.Common/Messaging/MessageAggregator.cs b/NzbDrone.Common/Messaging/MessageAggregator.cs index 53965ffb5..825fe3b42 100644 --- a/NzbDrone.Common/Messaging/MessageAggregator.cs +++ b/NzbDrone.Common/Messaging/MessageAggregator.cs @@ -76,23 +76,18 @@ namespace NzbDrone.Common.Messaging _logger.Trace("Publishing {0}", command.GetType().Name); - var handler = _serviceFactory.Build(handlerContract); + var handler = (IExecute)_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 @@ namespace NzbDrone.Common.Messaging 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); } } }