/// <summary>
        /// Set the message handler to be called when events are published to this topic.
        /// </summary>
        /// <param name="callback">Method to call when publish events are received for this topic.</param>
        public void OnMessage(OnMesageHandler callback)
        {
            // OK to hook callback before we are connected (in fact, recommended)
            _callback = callback;
            _mqtt.AddSubscriptionClient(this);

            if (_mqtt.IsConnected(_clientUid))
            {
                SubscribeToTopic();
            }
        }
Example #2
0
        /// <summary>
        /// Set the message handler to be called when events are published to this topic.
        /// </summary>
        /// <param name="callback">Method to call when publish events are received for this topic.</param>
        public void OnMessage(OnMesageHandler callback)
        {
            // OK to hook callback before we are connected (in fact, recommended)
            _callback = callback;
            _mqtt.AddSubscriptionClient(this);

            if (_mqtt.IsConnected(_clientUid))
            {
                SubscribeToTopic();
            }
        }
Example #3
0
        /// <summary>
        /// Closes this SubscriptionClient and stops receiving events.
        /// </summary>
        public async void Close()
        {
            if (_disposed)
            {
                return;
            }

            _disposed   = true;
            _subscribed = false;
            _callback   = null;
            _mqtt.RemoveSubscriptionClient(this);

            if (_mqtt.IsConnected(_clientUid))
            {
                try
                {
                    await UnsubscribeAsync(new[] { _subscription.TopicName }, 1);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(string.Format("SubscriptionClient({0}) failed to unsubscribe from topic. {1}", TopicName, ex.Message));
                }
            }
        }
        /// <summary>
        /// Closes this SubscriptionClient and stops receiving events.
        /// </summary>
        public async void Close()
        {
            if (_disposed)
            {
                return;
            }

            _disposed = true;
            _subscribed = false;
            _callback = null;
            _mqtt.RemoveSubscriptionClient(this);

            if (_mqtt.IsConnected(_clientUid))
            {
                try
                {
                    await UnsubscribeAsync(new[] { _subscription.TopicName }, 1);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(string.Format("SubscriptionClient({0}) failed to unsubscribe from topic. {1}", TopicName, ex.Message));
                }
            }
        }