public void CtorDataAvailableInProperty() { DataAvailableEventArgs e = new DataAvailableEventArgs(new Collection<byte>(new byte[] { 3, 2, 1 })); Assert.Equal<int>(3, e.MessageData.Count()); Assert.Equal<byte>(3, e.MessageData[0]); Assert.Equal<byte>(2, e.MessageData[1]); Assert.Equal<byte>(1, e.MessageData[2]); }
/// <summary> /// Handles the DataAvailable event of the connection control for handling non connection messages /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e"> /// The <see cref="Nmqtt.DataAvailableEventArgs" /> instance containing the event data. /// </param> protected void connection_MessageDataAvailable(object sender, DataAvailableEventArgs e) { try { // read the message, and if it's valid, signal to the keepalive so that we don't // spam ping requests at the broker. MqttMessage msg = MqttMessage.CreateFrom(e.MessageData); List <Func <MqttMessage, bool> > callbacks = messageProcessorRegistry[msg.Header.MessageType]; foreach (var callback in callbacks) { callback(msg); } } catch (InvalidMessageException) { // TODO: Figure out what to do if we receive a dud message during normal processing. } }
/// <summary> /// Handles the DataAvailable event of the connection control for handling non connection messages /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Nmqtt.DataAvailableEventArgs"/> instance containing the event data.</param> protected void connection_MessageDataAvailable(object sender, DataAvailableEventArgs e) { try { // read the message, and if it's valid, signal to the keepalive so that we don't // spam ping requests at the broker. MqttMessage msg = MqttMessage.CreateFrom(e.MessageData); List<Func<MqttMessage, bool>> callbacks = messageProcessorRegistry[msg.Header.MessageType]; foreach (Func<MqttMessage, bool> callback in callbacks) { callback(msg); } } catch (InvalidMessageException) { // TODO: Figure out what to do if we receive a dud message during normal processing. } }