private async Task ProcessHubCommand(Type messageType, IHubCommand hubCommand) { var handlerType = _commandHandlers[messageType]; var handler = _handlerActivator.GetInstance(handlerType); var handleMethodInfo = handlerType.GetMethod("HandleAsync"); if (handleMethodInfo == null) { return; } await((Task)handleMethodInfo?.Invoke(handler, new[] { hubCommand })).ConfigureAwait(false); }
private async Task HandleEvent(BrokeredMessage eventToHandle) { try { var eventType = Type.GetType(eventToHandle.ContentType); _logger.Debug(LoggerContext, "Handling event {0}", eventType.Name); object message; if (_useJsonSerialization) { message = JsonConvert.DeserializeObject(eventToHandle.GetBody <string>(), eventType); } else { message = eventToHandle.GetType() .GetMethod("GetBody", new Type[] { }) .MakeGenericMethod(eventType) .Invoke(eventToHandle, new object[] { }); } var handlerTypes = _eventHandlers[eventType]; foreach (var handlerType in handlerTypes) { var handler = _handlerActivator.GetInstance(handlerType); var handleMethodInfo = handlerType.GetMethod("HandleAsync", new[] { eventType }); await(Task) handleMethodInfo.Invoke(handler, new[] { message }); } eventToHandle.Complete(); } catch (Exception ex) { Console.WriteLine(" Abandoning {0}: {1}", eventToHandle.MessageId, ex.Message); await Task.Delay(100); eventToHandle.Abandon(); } }