Exemplo n.º 1
0
        static void SendMetric(CloudQueue queue, DeviceMetric metric)
        {
            var content = JsonConvert.SerializeObject(metric);
            CloudQueueMessage message = new CloudQueueMessage(content);

            queue.AddMessage(message);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var accountName = "iotlabdemo2016";
            var key         = "MDwybITcIvLo03K1+gyPsncBP9Vma9C9XmV43V8Noy7U748o+WNB56DRhYfxEmdZnVSsCSIpUZlAkm44YAFLrQ==";

            var queue = SetupQueue(accountName, key);

            for (int i = 0; i < 10; i++)
            {
                DeviceMetric dm = new DeviceMetric()
                {
                    CreateDt = DateTime.UtcNow,
                    Name     = "Temperature",
                    Value    = i.ToString()
                };
                Thread.Sleep(1000);
                SendMetric(queue, dm);
            }

            DeviceMetric metric = null;

            while ((metric = ReceiveMetric(queue)) != null)
            {
                Console.WriteLine("{2:dd.MM.yy hh:mm:ss}: Received metric {0} with value {1}", metric.Name, metric.Value, metric.CreateDt);
            }

            Console.ReadLine();
        }