Esempio n. 1
0
        private async Task ReceiveDataFromAzure()
        {
#if IOTHUB
            while (_azureIoTHubClient != null)
            {
                var message = await _azureIoTHubClient.ReceiveAsync();

                if (message != null)
                {
                    try
                    {
                        var msg = new Models.ReceivedMessage(message.GetBytes());
                        msg.MessageId = message.MessageId;
                        msg.Topic     = message.To;
                        DispatcherServices.Invoke(() => ReceivedMessageList.Insert(0, msg));
                        // Received a new message, display it
                        // We received the message, indicate IoTHub we treated it
                        await _azureIoTHubClient.CompleteAsync(message);
                    }
                    catch
                    {
                        await _azureIoTHubClient.RejectAsync(message);
                    }
                }
            }
#else
            await Task.FromResult(default(object));
#endif
        }
Esempio n. 2
0
        private void _mqttClient_CommandReceived(object sender, MqttMsgPublishEventArgs e)
        {
            var msg = new Models.ReceivedMessage(e.Message);

            msg.Topic     = e.Topic;
            msg.MessageId = e.MessageId;
            DispatcherServices.Invoke(() => ReceivedMessageList.Insert(0, msg));
        }