コード例 #1
0
ファイル: MessageLogger.cs プロジェクト: fm0597/nmqtt
 /// <summary>
 ///     Logs a message to the message log
 /// </summary>
 /// <param name="msg">The message to log.</param>
 /// <param name="inbound">Set to true if the message is inbound to the client.</param>
 private void LogMessage(MqttMessage msg, bool inbound) {
     if (!disposed) {
         Log.Info(m => m(String.Format("{0} {1} ]>----<[ {2} ]>----|", inbound ? "<<<<" : ">>>>",
                                       DateTime.Now, 
                                       msg.Header.MessageType)));
     }
 }
コード例 #2
0
ファイル: MQTTMessageTests.cs プロジェクト: lingxyd/Charlotte
        public void CanIndex()
        {
            dynamic msg = new MqttMessage();

            msg["anyvalue"] = "something";

            Assert.Equal("something", msg["anyvalue"]);
        }
コード例 #3
0
ファイル: MQTTMessageTests.cs プロジェクト: lingxyd/Charlotte
        public void CanAccessDirectly()
        {
            dynamic msg = new MqttMessage();

            msg.anyvalue = "something";

            Assert.Equal("something", msg.anyvalue);
        }
コード例 #4
0
ファイル: MQTTMessageTests.cs プロジェクト: lingxyd/Charlotte
        public void WillAcceptNonStrings()
        {
            dynamic msg = new MqttMessage();

            msg.anyvalue = 0;

            Assert.Equal("0", msg.anyvalue);
        }
コード例 #5
0
ファイル: MQTTMessageTests.cs プロジェクト: lingxyd/Charlotte
        public void InvalidNamesThrow()
        {
            dynamic msg = new MqttMessage();

            Assert.Throws<MissingMemberException>(() => { var test = msg.anyvalue; });
        }
コード例 #6
0
ファイル: MessageLogger.cs プロジェクト: fm0597/nmqtt
 /// <summary>
 ///     Logs details of received messages.
 /// </summary>
 /// <param name="msg">The message to log.</param>
 /// <returns>true, always.</returns>
 private bool MessageLoggerCallback(MqttMessage msg) {
     LogMessage(msg, true);
     return true;
 }
コード例 #7
0
ファイル: InMemoryStorage.cs プロジェクト: madrang/nmqtt
        //Dictionary<short, MqttMessage> messages = new Dictionary<short, MqttMessage>();

        #region IStorage Members

        public void StoreMessage(MqttMessage message)
        {
        }
コード例 #8
0
ファイル: MqttWinclient.cs プロジェクト: simonAndre/MQTT
        private void DisplayMessage(MqttMessage message)
        {
            string messageformat = string.Format("{0}\t{1}\t{2}\t{3}\r\n", message.Date, message.Topic, (int)message.QosLevel, message.GetStringMessage());

            fulltext = messageformat + (
                (fulltext != null && fulltext.Length > 10000) ?
                fulltext.Substring(0, 1000) : fulltext);
            this.textBox_messagereceived.Text = fulltext;
        }
コード例 #9
0
 public MqttUnsubAckHandler(MqttSession session, MqttMessage message)
     : base(session, message)
 {
 }
コード例 #10
0
 public MqttClientOptionsBuilder WithWillMessage(MqttMessage value)
 {
     _options.WillMessage = value;
     return(this);
 }
コード例 #11
0
        public static object ConvertPayloadToObject(this MqttMessage message)
        {
            var str = message.ConvertPayloadToString();

            return(JsonConvert.DeserializeObject(str));
        }
コード例 #12
0
ファイル: MqttClientSession.cs プロジェクト: newyty/SAEA
        private async Task RunInternalAsync(MqttConnectPacket connectPacket, IMqttChannelAdapter adapter)
        {
            if (connectPacket == null)
            {
                throw new ArgumentNullException(nameof(connectPacket));
            }
            if (adapter == null)
            {
                throw new ArgumentNullException(nameof(adapter));
            }

            try
            {
                if (_cancellationTokenSource != null)
                {
                    Stop(MqttClientDisconnectType.Clean, true);
                }

                adapter.ReadingPacketStarted   += OnAdapterReadingPacketStarted;
                adapter.ReadingPacketCompleted += OnAdapterReadingPacketCompleted;

                _cancellationTokenSource = new CancellationTokenSource();

                //workaround for https://github.com/dotnet/corefx/issues/24430
#pragma warning disable 4014
                _cleanupHandle = _cancellationTokenSource.Token.Register(async() =>
                {
                    await TryDisconnectAdapterAsync(adapter).ConfigureAwait(false);
                    TryDisposeAdapter(adapter);
                });
#pragma warning restore 4014
                //end workaround

                _wasCleanDisconnect = false;
                _willMessage        = connectPacket.WillMessage;

                _pendingPacketsQueue.Start(adapter, _cancellationTokenSource.Token);
                _keepAliveMonitor.Start(connectPacket.KeepAlivePeriod, _cancellationTokenSource.Token);

                _adapterEndpoint        = adapter.Endpoint;
                _adapterProtocolVersion = adapter.PacketSerializer.ProtocolVersion;

                while (!_cancellationTokenSource.IsCancellationRequested)
                {
                    var packet = await adapter.ReceivePacketAsync(_options.DefaultCommunicationTimeout, _cancellationTokenSource.Token).ConfigureAwait(false);

                    if (packet != null)
                    {
                        _keepAliveMonitor.PacketReceived(packet);
                        ProcessReceivedPacket(adapter, packet, _cancellationTokenSource.Token);
                    }
                }
            }
            catch (OperationCanceledException)
            {
            }
            catch (Exception exception)
            {
                if (exception is MqttCommunicationException)
                {
                    if (exception is MqttCommunicationClosedGracefullyException)
                    {
                        _logger.Verbose("Client '{0}': Connection closed gracefully.", ClientId);
                    }
                    else
                    {
                        _logger.Warning(exception, "Client '{0}': Communication exception while receiving client packets.", ClientId);
                    }
                }
                else
                {
                    _logger.Error(exception, "Client '{0}': Unhandled exception while receiving client packets.", ClientId);
                }

                Stop(MqttClientDisconnectType.NotClean, true);
            }
            finally
            {
                _adapterEndpoint        = null;
                _adapterProtocolVersion = null;

                // Uncomment as soon as the workaround above is no longer needed.
                //await TryDisconnectAdapterAsync(adapter).ConfigureAwait(false);
                //TryDisposeAdapter(adapter);

                _cleanupHandle?.Dispose();
                _cleanupHandle = null;

                _cancellationTokenSource?.Cancel(false);
                _cancellationTokenSource?.Dispose();
                _cancellationTokenSource = null;
            }
        }
コード例 #13
0
 public MqttManagedMessageBuilder WithApplicationMessage(MqttMessage applicationMessage)
 {
     _applicationMessage = applicationMessage;
     return(this);
 }
コード例 #14
0
 public MqttPubCompHandler(MqttSession session, MqttMessage message)
     : base(session, message)
 {
 }
コード例 #15
0
ファイル: MessageLogger.cs プロジェクト: nuxleus/nmqtt
 /// <summary>
 /// Logs a message to the message log
 /// </summary>
 /// <param name="msg"></param>
 public void LogMessage(MqttMessage msg, bool inbound)
 {
     if (!disposed)
     {
         if (logFileWriter != null)
         {
             logFileWriter.WriteLine(String.Format("{0} {1} ]>----<[ {2} ]>----|", inbound ? "<<<<" : ">>>>", DateTime.Now, msg.Header.MessageType));
             logFileWriter.WriteLine(msg.ToString());
             logFileWriter.Flush();
         }
     }
 }
コード例 #16
0
ファイル: InMemoryStorage.cs プロジェクト: nuxleus/nmqtt
 public void StoreMessage(MqttMessage message)
 {
 }
コード例 #17
0
ファイル: MessageLogger.cs プロジェクト: fm0597/nmqtt
 /// <summary>
 ///     Called whenever a message is sent from the client to the broker.
 /// </summary>
 /// <param name="msg">The message that was sent.</param>
 /// <returns>true; always.</returns>
 private bool MessageSentCallback(MqttMessage msg) {
     LogMessage(msg, false);
     return true;
 }
コード例 #18
0
ファイル: MqttWinclient.cs プロジェクト: simonAndre/MQTT
        private void sendCommandToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SendCommand scf = new SendCommand();
            if (scf.ShowDialog(this) == DialogResult.OK)
            {
                SanSensNetProtocol a = new SanSensNetProtocol();
                byte[] buff = a.Encode_SendCommand(scf.CommandId, scf.V1, scf.V2);
                string publishtopic = ConfigurationManager.AppSettings["publishCommands_topic"];
                Console.WriteLine("send commande");
                MqttMessage mess = new MqttMessage(publishtopic, buff, 1, false);
                mqtt.publish(mess);
            }


        }
コード例 #19
0
 public void OnMessageReceived(string senderClientId, MqttMessage applicationMessage)
 {
     ApplicationMessageReceived?.Invoke(this, new MqttMessageReceivedEventArgs(senderClientId, applicationMessage));
 }