예제 #1
0
        private async Task ReceiveMessagesFromDeviceAsync(string partition)
        {
            var eventHubReceiver = eventHubClient.GetDefaultConsumerGroup().CreateReceiver(partition, DateTime.Now);

            while (true)
            {
                EventData eventData = await eventHubReceiver.ReceiveAsync();

                if (eventData == null)
                {
                    continue;
                }

                string data = Encoding.UTF8.GetString(eventData.GetBytes());
                Console.WriteLine(string.Format("Message received. Partition: {0} Data: '{1}'", partition, data));

                WeatherRecord record = JsonConvert.DeserializeObject <WeatherRecord>(data);

                try
                {
                    WriteToTable(record);
                }
                catch (Exception ex)
                {
                    ex = ex;
                }
            }
        }
예제 #2
0
        private void WriteToTable(WeatherRecord record)
        {
            // Create the TableOperation object that inserts the customer entity.
            TableOperation insertOperation = TableOperation.Insert(record);

            // Execute the insert operation.
            _weatherTable.Execute(insertOperation);
        }
예제 #3
0
        private void WriteToTable(WeatherRecord record)
        {
            // Create the TableOperation object that inserts the customer entity.
            TableOperation insertOperation = TableOperation.Insert(record);

            // Execute the insert operation.
            _weatherTable.Execute(insertOperation);
        }