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)); }
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); }
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); }
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"); }
//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); } }
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); }
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); }
private void GuiThreadChanged(WpfGuiChangedMessage wpfGuiChangedMessage) { _guiThreadProvider = wpfGuiChangedMessage.NewGuiThreadProvider; Unsubscribe(_ticket); _ticket = Subscribe <WpfGuiChangedMessage>(GuiThreadChangedInvalid); }
///<summary> /// Initializes <see cref="EventAggregator"/> with provided <see cref="guiThreadProvider"/>. ///</summary> public EventAggregator(IGuiThreadProvider guiThreadProvider) { _guiThreadProvider = guiThreadProvider; _ticket = Subscribe <WpfGuiChangedMessage>(GuiThreadChanged); }
public void OnLoad() { _readyForResolvingTicket = _eventAggregator.Subscribe <NomadAllModulesLoadedMessage>(LocalResolutionMethod); }
public ProgressBarHelper(IEventAggregator eventAggregator) { _ticket = eventAggregator.Subscribe<ThreadedWorkerProgressMessage>(ProgressChanged, DeliveryMethod.GuiThread); }
public void OnLoad() { _readyForResolvingTicket = _eventAggregator.Subscribe<NomadAllModulesLoadedMessage>(LocalResolutionMethod); }
public void OnLoad() { // subscribing to the CounterMessage _subscriptionTicket = _eventAggregator.Subscribe <CounterMessageType>(CheckCounter); }
public void OnLoad() { // subscribing to the CounterMessage _subscriptionTicket = _eventAggregator.Subscribe<CounterMessageType>(CheckCounter); }