Esempio n. 1
0
            /// <summary>
            ///     Calls back on the provided callback when someone has published the requested service.
            ///     If the service was already available, this method invokes the callback immediately.
            ///     A generic version of this method is provided for convience, and calls the non-generic
            ///     method with appropriate casts.
            /// </summary>
            /// <param name="serviceType"></param>
            /// <param name="callback"></param>
            public override void Subscribe(Type serviceType, SubscribeServiceCallback callback)
            {
                if (serviceType == null)
                {
                    throw new ArgumentNullException("serviceType");
                }
                if (callback == null)
                {
                    throw new ArgumentNullException("callback");
                }

                var service = GetService(serviceType);

                if (service != null)
                {
                    // If the service is already available, callback immediately
                    callback(serviceType, service);
                }
                else
                {
                    // Otherwise, store this for later
                    if (_subscriptions == null)
                    {
                        _subscriptions = new Dictionary <Type, SubscribeServiceCallback>();
                    }
                    SubscribeServiceCallback existing = null;
                    _subscriptions.TryGetValue(serviceType, out existing);
                    existing = (SubscribeServiceCallback)Delegate.Combine(existing, callback);
                    _subscriptions[serviceType] = existing;
                }
            }
Esempio n. 2
0
            /// <summary>
            ///     Removes a subscription.
            /// </summary>
            public override void Unsubscribe(Type serviceType, SubscribeServiceCallback callback)
            {
                if (serviceType == null)
                {
                    throw new ArgumentNullException("serviceType");
                }
                if (callback == null)
                {
                    throw new ArgumentNullException("callback");
                }

                if (_subscriptions != null)
                {
                    SubscribeServiceCallback existing;
                    if (_subscriptions.TryGetValue(serviceType, out existing))
                    {
                        existing = (SubscribeServiceCallback)RemoveCallback(existing, callback);
                        if (existing == null)
                        {
                            _subscriptions.Remove(serviceType);
                        }
                        else
                        {
                            _subscriptions[serviceType] = existing;
                        }
                    }
                }
            }
Esempio n. 3
0
            public override void Subscribe(Type serviceType, SubscribeServiceCallback callback)
            {
                if (serviceType == null)
                {
                    throw new ArgumentNullException("serviceType");
                }
                if (callback == null)
                {
                    throw new ArgumentNullException("callback");
                }
                object service = this.GetService(serviceType);

                if (service != null)
                {
                    callback(serviceType, service);
                }
                else
                {
                    if (this._subscriptions == null)
                    {
                        this._subscriptions = new Dictionary <Type, SubscribeServiceCallback>();
                    }
                    SubscribeServiceCallback subscribeServiceCallback1 = (SubscribeServiceCallback)null;
                    this._subscriptions.TryGetValue(serviceType, out subscribeServiceCallback1);
                    SubscribeServiceCallback subscribeServiceCallback2 = subscribeServiceCallback1 + callback;
                    this._subscriptions[serviceType] = subscribeServiceCallback2;
                }
            }
Esempio n. 4
0
            public override void Unsubscribe(Type serviceType, SubscribeServiceCallback callback)
            {
                if (serviceType == null)
                {
                    throw new ArgumentNullException("serviceType");
                }
                if (callback == null)
                {
                    throw new ArgumentNullException("callback");
                }
                SubscribeServiceCallback subscribeServiceCallback1;

                if (this._subscriptions == null || !this._subscriptions.TryGetValue(serviceType, out subscribeServiceCallback1))
                {
                    return;
                }
                SubscribeServiceCallback subscribeServiceCallback2 = (SubscribeServiceCallback)ServiceManager.RemoveCallback((Delegate)subscribeServiceCallback1, (Delegate)callback);

                if (subscribeServiceCallback2 == null)
                {
                    this._subscriptions.Remove(serviceType);
                }
                else
                {
                    this._subscriptions[serviceType] = subscribeServiceCallback2;
                }
            }
Esempio n. 5
0
 public void Unsubscribe <TServiceType>(SubscribeServiceCallback <TServiceType> callback)
 {
     if (callback == null)
     {
         throw new ArgumentNullException("callback");
     }
     this.Unsubscribe(typeof(TServiceType), new ServiceManager.SubscribeProxy <TServiceType>(callback).Callback);
 }
        public void Unsubscribe <TServiceType>(SubscribeServiceCallback <TServiceType> callback)
        {
            if (callback == null)
            {
                throw FxTrace.Exception.ArgumentNull("callback");
            }
            SubscribeProxy <TServiceType> proxy = new SubscribeProxy <TServiceType>(callback);

            Unsubscribe(typeof(TServiceType), proxy.Callback);
        }
        public void Subscribe <TServiceType>(SubscribeServiceCallback <TServiceType> callback)
        {
            if (callback == null)
            {
                throw FxTrace.Exception.ArgumentNull("callback");
            }

            // Call the standard Subscribe method and use a generic proxy
            SubscribeProxy <TServiceType> proxy = new SubscribeProxy <TServiceType>(callback);

            Subscribe(typeof(TServiceType), proxy.Callback);
        }
            // <summary>
            //     Removes a subscription.
            // </summary>
            public override void Unsubscribe(Type serviceType, SubscribeServiceCallback callback) 
            {

                if (serviceType == null) 
                {
                    throw FxTrace.Exception.ArgumentNull("serviceType");
                }
                if (callback == null) 
                {
                    throw FxTrace.Exception.ArgumentNull("callback");
                }

                if (_subscriptions != null) 
                {
                    SubscribeServiceCallback existing;
                    if (_subscriptions.TryGetValue(serviceType, out existing)) 
                    {
                        existing = (SubscribeServiceCallback)RemoveCallback(existing, callback);
                        if (existing == null) 
                        {
                            _subscriptions.Remove(serviceType);
                        }
                        else 
                        {
                            _subscriptions[serviceType] = existing;
                        }
                    }
                }
            }
            // <summary>
            // Calls back on the provided callback when someone has published the requested service.
            // If the service was already available, this method invokes the callback immediately.
            //
            // A generic version of this method is provided for convience, and calls the non-generic
            // method with appropriate casts.
            // </summary>
            // <param name="serviceType"></param>
            // <param name="callback"></param>
            public override void Subscribe(Type serviceType, SubscribeServiceCallback callback) 
            {
                if (serviceType == null) 
                {
                    throw FxTrace.Exception.ArgumentNull("serviceType");
                }
                if (callback == null) 
                {
                    throw FxTrace.Exception.ArgumentNull("callback");
                }

                object service = GetService(serviceType);
                if (service != null) 
                {

                    // If the service is already available, callback immediately
                    callback(serviceType, service);
                }
                else 
                {

                    // Otherwise, store this for later
                    if (_subscriptions == null) 
                    {
                        _subscriptions = new Dictionary<Type, SubscribeServiceCallback>();
                    }
                    SubscribeServiceCallback existing = null;
                    _subscriptions.TryGetValue(serviceType, out existing);
                    existing = (SubscribeServiceCallback)Delegate.Combine(existing, callback);
                    _subscriptions[serviceType] = existing;
                }
            }
 internal SubscribeProxy(SubscribeServiceCallback <TServiceType> callback)
 {
     _genericCallback = callback;
 }
 /// <summary>
 /// Removes a subscription for the serviceType.
 /// </summary>
 /// <param name="serviceType">The type of service to remove the subscription from.</param>
 /// <param name="callback">The callback object to remove from the subscription.</param>
 /// <exception cref="ArgumentNullException">If serviceType or callback is null.</exception>
 public abstract void Unsubscribe(Type serviceType, SubscribeServiceCallback callback);