Пример #1
0
        public void after_calling_unsubscribe_handler_is_not_called_when_event_is_published()
        {
            Action <MessageType> myAction = x => { Assert.Fail("Delegate was not removed"); };
            IEventAggregatorTicket <MessageType> ticket = _eventAggregator.Subscribe(myAction);

            ticket.Dispose();
            _eventAggregator.Publish(new MessageType(NameToSend));
        }
Пример #2
0
        public void OnLoad()
        {
            // subscribing to an event (Stop Publishing) in Nomad
            _stopPublishingSubscriptionTicket = _eventAggregator.Subscribe <StopPublishingMessageType>(StopPublishing);

            //subscribing to AllModulesLoaded event in Nomad
            _allModulesLoadedSubscriptionTicket = _eventAggregator.Subscribe <NomadAllModulesLoadedMessage>(TickerMethod);
        }
Пример #3
0
        public void OnLoad()
        {
            // subscribing to an event (Stop Publishing) in Nomad
            _stopPublishingSubscriptionTicket = _eventAggregator.Subscribe<StopPublishingMessageType>(StopPublishing);

            //subscribing to AllModulesLoaded event in Nomad
            _allModulesLoadedSubscriptionTicket = _eventAggregator.Subscribe<NomadAllModulesLoadedMessage>(TickerMethod);
        }
Пример #4
0
        public void after_unsubscribing_subscribing_again_results_in_working_event()
        {
            Action <MessageType> myAction = x => { Assert.Fail("Delegate was not removed"); };
            IEventAggregatorTicket <MessageType> ticket = _eventAggregator.Subscribe(myAction);

            ticket.Dispose();
            _eventAggregator.Subscribe <MessageType>(x => { });
            Assert.DoesNotThrow(() => _eventAggregator.Publish(new MessageType(NameToSend)),
                                "After subscribing and unsubscribing an event we can no longer use event of this type");
        }
Пример #5
0
        //TODO: Unsubsribing new lambda won't work!
        /// <summary>
        /// Unsubsribes specified action.
        /// Removes event from collection. Thread safe.
        /// <see cref="IEventAggregator.Unsubscribe{T}"/>
        /// </summary>
        /// <param name="ticket">ticket have to be <see cref="EventAggregatorTicket{T}"/></param>
        /// <exception cref="KeyNotFoundException">when unsubscribing from type which was no subsription ever</exception>
        /// <exception cref="MemberAccessException"></exception>
        private void Unsubscribe(IEventAggregatorTicket ticket)
        {
            Type type = ticket.ActionType;
            HashSet <IEventAggregatorTicket> tickets = null;

            lock (_subscriptions)
            {
                tickets = _subscriptions[type];
            }
            lock (tickets)
            {
                tickets.Remove(ticket);
            }
        }
Пример #6
0
        public void when_one_handler_unsubscribes_others_are_still_called()
        {
            var         sentPayload     = new MessageType(NameToSend);
            MessageType receivedPayload = null;

            _eventAggregator.Subscribe <MessageType>(payload => receivedPayload = payload);

            Action <MessageType> myAction = x => { };
            IEventAggregatorTicket <MessageType> ticket = _eventAggregator.Subscribe(myAction);

            ticket.Dispose();

            _eventAggregator.Publish(sentPayload);
            Assert.AreSame(sentPayload, receivedPayload);
        }
Пример #7
0
        public IEventAggregatorTicket <T> Subscribe <T>(Action <T> action, DeliveryMethod deliveryMethod) where T : class
        {
            // subscribe on local event
            IEventAggregatorTicket <T> ticket = _localEventAggregator.Subscribe(action, deliveryMethod);

            // update counter of subscrbers
            int    value;
            string key = typeof(T).AssemblyQualifiedName;

            if (TicketsCounter.TryGetValue(key, out value))
            {
                TicketsCounter[key] = value + 1;
            }
            else
            {
                TicketsCounter[key] = 1;
            }

            // remove from ticketCounter if ticket is disposed
            ticket.TicketDisposed += (sender, args) =>
            {
                int    v;
                string k = args.EventType.AssemblyQualifiedName;
                if (TicketsCounter.TryGetValue(k, out v))
                {
                    TicketsCounter[k] = v - 1;
                }
                else
                {
                    throw new InvalidOperationException("Removed the typed which was never added");
                }
            };

            // subscribe on remote or not by now);
            return(ticket);
        }
Пример #8
0
 private void GuiThreadChanged(WpfGuiChangedMessage wpfGuiChangedMessage)
 {
     _guiThreadProvider = wpfGuiChangedMessage.NewGuiThreadProvider;
     Unsubscribe(_ticket);
     _ticket = Subscribe <WpfGuiChangedMessage>(GuiThreadChangedInvalid);
 }
Пример #9
0
 ///<summary>
 /// Initializes <see cref="EventAggregator"/> with provided <see cref="guiThreadProvider"/>.
 ///</summary>
 public EventAggregator(IGuiThreadProvider guiThreadProvider)
 {
     _guiThreadProvider = guiThreadProvider;
     _ticket            = Subscribe <WpfGuiChangedMessage>(GuiThreadChanged);
 }
Пример #10
0
 public void OnLoad()
 {
     _readyForResolvingTicket =
         _eventAggregator.Subscribe <NomadAllModulesLoadedMessage>(LocalResolutionMethod);
 }
Пример #11
0
 public ProgressBarHelper(IEventAggregator eventAggregator)
 {
     _ticket = eventAggregator.Subscribe<ThreadedWorkerProgressMessage>(ProgressChanged, DeliveryMethod.GuiThread);
 }
Пример #12
0
 public void OnLoad()
 {
     _readyForResolvingTicket =
         _eventAggregator.Subscribe<NomadAllModulesLoadedMessage>(LocalResolutionMethod);
 }
Пример #13
0
 public void OnLoad()
 {
     // subscribing to the CounterMessage
     _subscriptionTicket = _eventAggregator.Subscribe <CounterMessageType>(CheckCounter);
 }
Пример #14
0
 public void OnLoad()
 {
     // subscribing to the CounterMessage
     _subscriptionTicket = _eventAggregator.Subscribe<CounterMessageType>(CheckCounter);
 }