示例#1
0
 /// <summary>
 ///     Creates a new instance of a SubscriptionsManager that uses the specified connection to manage subscriptions.
 /// </summary>
 /// <param name="connectionHandler">The connection handler that will be used to subscribe to topics.</param>
 /// <param name="publishingManager">The punlishing manager that handles the receipt of messages from the broker.</param>
 public SubscriptionsManager(IMqttConnectionHandler connectionHandler,
                             IPublishingManager publishingManager)
 {
     this.connectionHandler = connectionHandler;
     this.publishingManager = publishingManager;
     this.connectionHandler.RegisterForMessage(MqttMessageType.SubscribeAck, ConfirmSubscription);
     this.connectionHandler.RegisterForMessage(MqttMessageType.UnsubscribeAck, ConfirmUnsubscribe);
 }
示例#2
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="PublishingManager" /> class.
 /// </summary>
 /// <param name="connectionHandler">The connection handler.</param>
 public PublishingManager(IMqttConnectionHandler         connectionHandler) {
     this.connectionHandler = connectionHandler;
     connectionHandler.RegisterForMessage(MqttMessageType.PublishAck, HandlePublishAcknowledgement);
     connectionHandler.RegisterForMessage(MqttMessageType.Publish, HandlePublish);
     connectionHandler.RegisterForMessage(MqttMessageType.PublishComplete, HandlePublishComplete);
     connectionHandler.RegisterForMessage(MqttMessageType.PublishRelease, HandlePublishRelease);
     connectionHandler.RegisterForMessage(MqttMessageType.PublishReceived, HandlePublishReceived);
 }
示例#3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PublishingManager"/> class.
 /// </summary>
 /// <param name="connectionHandler">The connection handler.</param>
 /// <param name="publishMessageCallback">The function that should be called when a publish message is received.</param>
 public PublishingManager(IMqttConnectionHandler connectionHandler, Func <MqttPublishMessage, bool> publishMessageCallback)
 {
     this.connectionHandler      = connectionHandler;
     this.publishMessageCallback = publishMessageCallback;
     connectionHandler.RegisterForMessage(MqttMessageType.PublishAck, HandlePublishAcknowledgement);
     connectionHandler.RegisterForMessage(MqttMessageType.Publish, HandlePublish);
     connectionHandler.RegisterForMessage(MqttMessageType.PublishComplete, HandlePublishComplete);
     connectionHandler.RegisterForMessage(MqttMessageType.PublishRelease, HandlePublishRelease);
     connectionHandler.RegisterForMessage(MqttMessageType.PublishReceived, HandlePublishReceived);
 }
示例#4
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="MqttConnectionKeepAlive" /> class.
        /// </summary>
        /// <param name="connectionHandler">The connection to keep alive.</param>
        /// <param name="keepAliveSeconds">The keep alive duration in seconds.</param>
        public MqttConnectionKeepAlive(IMqttConnectionHandler connectionHandler, int keepAliveSeconds) {
            this.connectionHandler = connectionHandler;
            this.keepAlivePeriod = keepAliveSeconds*1000;

            // register for message handling of ping request and response messages.
            connectionHandler.RegisterForMessage(MqttMessageType.PingRequest, PingRequestReceived);
            connectionHandler.RegisterForMessage(MqttMessageType.PingResponse, PingResponseReceived);
            connectionHandler.RegisterForAllSentMessages(MessageSent);

            // Start the timer so we do a ping whenever required.
            pingTimer = new Timer(PingRequired, null, keepAlivePeriod, keepAlivePeriod);
        }
示例#5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MqttConnectionKeepAlive"/> class.
        /// </summary>
        /// <param name="connection">The connection to keep alive.</param>
        /// <param name="keepAliveSeconds">The keep alive duration in seconds.</param>
        public MqttConnectionKeepAlive(IMqttConnectionHandler connectionHandler, int keepAliveSeconds)
        {
            this.connectionHandler = connectionHandler;
            this.keepAlivePeriod   = keepAliveSeconds * 1000;

            // register for message handling of ping request and response messages.
            connectionHandler.RegisterForMessage(MqttMessageType.PingRequest, PingRequestReceived);
            connectionHandler.RegisterForMessage(MqttMessageType.PingResponse, PingResponseReceived);
            connectionHandler.RegisterForAllSentMessages(MessageSent);

            // Start the timer so we do a ping whenever required.
            pingTimer = new Timer(PingRequired, null, keepAlivePeriod, keepAlivePeriod);
        }
示例#6
0
 public SubscriptionsManager(IMqttConnectionHandler connectionHandler)
 {
     this.connectionHandler = connectionHandler;
     this.connectionHandler.RegisterForMessage(MqttMessageType.SubscribeAck, ConfirmSubscription);
 }