Beispiel #1
0
        /// <summary>
        /// Enqueue EventData for sending
        /// </summary>
        /// <param name="data">EventData to enqueue</param>
        private void Enqueue(EventData data)
        {
            // enqueue event data
            lock (this.queue)
            {
                this.queue.Enqueue(data);
            }

            this.queueEvent.Set();
        }
        internal override EventData PrepareEventData(IDictionary bag)
        {
            foreach (SensorType type in bag.Keys)
            {
                if (type == SensorType.Temperature)
                {
                    float temperature = (float)bag[type];

                    this.sensor.measurename = Enum.GetName(typeof(SensorType), SensorType.Temperature);
                    this.sensor.timecreated = DateTime.UtcNow.ToString("o");
                    this.sensor.unitofmeasure = "C";
                    this.sensor.value = temperature;

                    Debug.WriteLine("temp: " + temperature);
                }
                else if (type == SensorType.Humidity)
                {
                    // nothing
                }
                else if (type == SensorType.Accelerometer)
                {
                    // nothing
                }
            }

            EventData data = new EventData(Encoding.UTF8.GetBytes(this.sensor.ToJson()));

            return data;
        }
Beispiel #3
0
 /// <summary>
 /// Send data to the event hub
 /// </summary>
 /// <param name="data">EventData instance to send</param>
 public void Send(EventData data)
 {
     this.CreateSender();
     this.Sender.SendEventData(data);
 }