/// <summary> /// Calls the generic subscribe function of EasyNetQ using the details and type given. /// </summary> /// <param name="bus"> The easyNetQ bus</param> /// <param name="details"> The details of the subscriber function</param> /// <param name="typeDetails"> The type to register against the bus</param> /// <returns> THe modified EastNetQ Bus</returns> private static IBus RegisterAsyncAction(IBus bus, SubscriberDetails details, Type typeDetails) { if (!details.IsSubscriberAsyncDetails()) { throw new ArgumentException( "The details parameter must be of generic type SubscriberAsyncDetails", "details"); } var messageType = typeDetails.GetProperty("Type").GetValue(details, null) as Type; var messageAction = typeDetails.GetProperty("GetMessageHandler").GetValue(details, null); var method = typeof(NonGenericExtensions).GetMethod("Subscribe", new[] {typeof (IBus), typeof (Type), typeof (string), typeof (Action<object>)}); method.Invoke(null, new[] {bus, messageType, "test", messageAction}); return bus; }
/// <summary> /// Calls the EasyNetQ Respond function with the type details contained in the SubscriberDetails. /// </summary> /// <param name="bus"> The EasyNetQ bus</param> /// <param name="details"> The subscriber details</param> /// <param name="typeDetails"> The </param> /// <returns></returns> private static IBus RegisterSynchronousAction(IBus bus, SubscriberDetails details, Type typeDetails) { if (details.IsSubscriberAsyncDetails()) { throw new ArgumentException( "The details parameter must be of generic type SubscriberSyncronousDetails", "details"); } var requestType = typeDetails.GetProperty("GetRequestType").GetValue(details, null) as Type; var responseType = typeDetails.GetProperty("GetResponseType").GetValue(details, null) as Type; var messageAction = typeDetails.GetProperty("GetMessageHandler").GetValue(details, null); var method = new Func<Func<object, object>, IDisposable>(bus.Respond); var methodInfo = method.Method.GetGenericMethodDefinition().MakeGenericMethod(requestType, responseType); methodInfo.Invoke(bus, new[] {messageAction}); return bus; }