コード例 #1
0
        private IDisposable RegisterToEvent(object instance, EventInfo @event, IPublisherRegistrationInterceptor interceptor)
        {
            string topic = interceptor.GetTopicUri(@event);

            IWampTopicProxy topicProxy = mProxy.TopicContainer.GetTopicByUri(topic);

            PublishOptions options = interceptor.GetPublishOptions(@event);

            Delegate createdDelegate;

            Type eventHandlerType = @event.EventHandlerType;

            if (IsPositional(eventHandlerType))
            {
                createdDelegate =
                    mEventHandlerGenerator.CreatePositionalDelegate(eventHandlerType, topicProxy, options);
            }
            else
            {
                createdDelegate =
                    mEventHandlerGenerator.CreateKeywordsDelegate(eventHandlerType, topicProxy, options);
            }

            @event.AddEventHandler(instance, createdDelegate);

            PublisherDisposable disposable =
                new PublisherDisposable(instance,
                                        createdDelegate,
                                        @event,
                                        topic, mProxy.Monitor);

            return(disposable);
        }
コード例 #2
0
        public IDisposable RegisterPublisher(object instance, IPublisherRegistrationInterceptor interceptor)
        {
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            Type runtimeType = instance.GetType();

            IEnumerable <Type> typesToExplore = GetTypesToExplore(runtimeType);

            List <IDisposable> disposables = new List <IDisposable>();

            foreach (Type type in typesToExplore)
            {
                foreach (EventInfo @event in type.GetInstanceEvents())
                {
                    if (interceptor.IsPublisherTopic(@event))
                    {
                        IDisposable disposable =
                            RegisterToEvent(instance, @event, interceptor);

                        disposables.Add(disposable);
                    }
                }
            }

            IDisposable result =
                new CompositeDisposable(disposables);

            return(result);
        }
コード例 #3
0
 public IDisposable RegisterPublisher(object instance, IPublisherRegistrationInterceptor interceptor)
 {
     return(mPublisherRegistrar.RegisterPublisher(instance, interceptor));
 }