Esempio n. 1
0
 public RegisteredEventListener(Type eventType, MethodInfo method, EventListenerAttribute attribute, Type eventListenerType)
 {
     EventType          = eventType;
     _eventListenerType = eventListenerType;
     Priority           = attribute.Priority;
     IgnoreCancelled    = attribute.IgnoreCancelled;
     Method             = method.GetFriendlyName(showParameters: false);
     _invoker           = CreateInvoker(method, attribute.IgnoreCancelled);
 }
        /// <summary>
        ///     Build a EventListener class based on the attribute and the class type
        /// </summary>
        /// <param name="eventListenerAttribute"></param>
        /// <param name="classType"></param>
        private void BuildEventListener(EventListenerAttribute eventListenerAttribute, Type classType)
        {
            var queueExists = _eventListeners.FirstOrDefault(el =>
                                                             el.EventListenerAttribute.QueueName == eventListenerAttribute.QueueName);

            if (queueExists == null)
            {
                var eventListener = new EventListener
                {
                    EventListenerAttribute = eventListenerAttribute, Class = classType
                };
                BuildTopics(classType, eventListener);
                _eventListeners.Add(eventListener);
            }
            else
            {
                BuildTopics(classType, queueExists);
            }
        }
        /// <summary>
        /// Register possible event listeners
        /// </summary>
        protected virtual void RegisterListener(TypeInfo type)
        {
            Logger.LogTrace($"Retrieving relevant methods from type {type.Name}");

            foreach (MethodInfo methodInfo in GetRelevantMethods(type))
            {
                EventListenerAttribute eventQueueName = methodInfo.GetCustomAttribute <EventListenerAttribute>();
                string commandQueueName = methodInfo.GetCustomAttribute <CommandListenerAttribute>()?.QueueName;

                if (eventQueueName != null)
                {
                    RegisterEventListener(type, methodInfo);
                }
                else if (commandQueueName != null)
                {
                    RegisterCommandListener(type, methodInfo, commandQueueName);
                }
                else
                {
                    Logger.LogTrace($"Method {methodInfo.Name} does not contain listener attributes.");
                }
            }
        }
        public void Register(EventListenerAttribute attribute, MethodInfo method)
        {
            var listener = new SubscriberRegistration(attribute.Evaluate, method);

            _registrations.Add(listener);
        }
Esempio n. 5
0
 public EventData(Type[] types, IEventListener listener, MethodInfo methodInfo, EventListenerAttribute attribute)
 {
     Types           = types;
     Listener        = listener;
     MethodInfo      = methodInfo;
     Priority        = attribute.Priority;
     IgnoreCancelled = attribute.IgnoreCancelled;
     Method          = methodInfo.GetFriendlyName(showParameters: false);
     IsTask          = methodInfo.ReturnParameter.ParameterType.IsTask();
 }