private BusEventSubscriptionToken AddSubscriptionInternal <TBusEvent>(Action <TBusEvent> deliveryAction, Func <TBusEvent, bool> eventFilter, bool strongReference, IBusEventProxy proxy) where TBusEvent : class, IBusEvent { if (deliveryAction == null) { throw new ArgumentNullException("deliveryAction"); } if (eventFilter == null) { throw new ArgumentNullException("eventFilter"); } if (proxy == null) { throw new ArgumentNullException("proxy"); } lock (m_subscriptionsPadlock) { List <SubscriptionItem> currentSubscriptions; if (!m_subscriptions.TryGetValue(typeof(TBusEvent), out currentSubscriptions)) { currentSubscriptions = new List <SubscriptionItem>(); m_subscriptions[typeof(TBusEvent)] = currentSubscriptions; } var subscriptionToken = new BusEventSubscriptionToken(this, typeof(TBusEvent)); IBusEventSubscription subscription; if (strongReference) { subscription = new StrongBusEventSubscription <TBusEvent>(subscriptionToken, deliveryAction, eventFilter); } else { subscription = new WeakBusEventSubscription <TBusEvent>(subscriptionToken, deliveryAction, eventFilter); } currentSubscriptions.Add(new SubscriptionItem(proxy, subscription)); return(subscriptionToken); } }
/// <summary> /// Subscribe to a bus event type with the given destination and delivery action. /// Bus events will be delivered via the specified proxy. /// /// All bus events of this type will be delivered. /// </summary> /// <typeparam name="TBusEvent">Type of bus event</typeparam> /// <param name="deliveryAction">Action to invoke when bus event is delivered</param> /// <param name="useStrongReferences">Use strong references to destination and deliveryAction </param> /// <param name="proxy">Proxy to use when delivering the bus events</param> /// <returns>BusEventSubscriptionToken used to unsubscribing</returns> public BusEventSubscriptionToken Subscribe <TBusEvent>(Action <TBusEvent> deliveryAction, bool useStrongReferences, IBusEventProxy proxy) where TBusEvent : class, IBusEvent { return(AddSubscriptionInternal <TBusEvent>(deliveryAction, (m) => true, useStrongReferences, proxy)); }
/// <summary> /// Subscribe to a bus event type with the given destination and delivery action with the given filter. /// Bus events will be delivered via the specified proxy. /// All references are held with WeakReferences /// /// Only bus events that "pass" the filter will be delivered. /// </summary> /// <typeparam name="TBusEvent">Type of bus event</typeparam> /// <param name="deliveryAction">Action to invoke when bus event is delivered</param> /// <param name="useStrongReferences">Use strong references to destination and deliveryAction </param> /// <param name="proxy">Proxy to use when delivering the bus events</param> /// <returns>BusEventSubscriptionToken used to unsubscribing</returns> public BusEventSubscriptionToken Subscribe <TBusEvent>(Action <TBusEvent> deliveryAction, Func <TBusEvent, bool> eventFilter, bool useStrongReferences, IBusEventProxy proxy) where TBusEvent : class, IBusEvent { return(AddSubscriptionInternal <TBusEvent>(deliveryAction, eventFilter, useStrongReferences, proxy)); }
public SubscriptionItem(IBusEventProxy proxy, IBusEventSubscription subscription) { Proxy = proxy; Subscription = subscription; }