Example #1
0
        static void Main(string[] args)
        {
            //init sensors
            MessageQueuing queue          = new MessageQueuing();
            ThreadStart    threadDelegate = new ThreadStart(Send.sendData);

            Thread t = new Thread(threadDelegate);

            t.Start();
            RandomGenerator            random = new RandomGenerator();
            TemperatureSensorInterface temp   = new VirtualTemperatureSensor(random);
            SpeedSensorInterface       speed  = new VirtualSpeedSensor(random);
            GPSSensorInterface         gps    = new VirtualGPSSensor(random);
            DirectionSensorInterface   dir    = new VirtualDirectionSensor();

            while (true)
            {
                long   epoch = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
                var    Speed = speed.getSpeed();
                string s     = "temperatura:" + temp.getTemperature();
                var    x     = new
                {
                    fields = new[] {
                        new { fldName = "temperatura", value = temp.getTemperature() },
                        new { fldName = "velocità", value = speed.getSpeed() },
                        new { fldName = "lat", value = gps.getLat() },
                        new { fldName = "lon", value = gps.getLon() }
                    },
                    tags = new[] {
                        new { fldName = "temperatura", value = temp.getTemperature() },
                        new { fldName = "velocità", value = speed.getSpeed() },
                        new { fldName = "lat", value = gps.getLat() },
                        new { fldName = "lon", value = gps.getLon() }
                    },

                    direction = dir.getDirection(),
                    timestamp = epoch
                };

                queue.addMessage(JsonConvert.SerializeObject(x));

                Console.WriteLine("Added to queue : \n {0}", JsonConvert.SerializeObject(x));

                Thread.Sleep(1000);
            }
        }