static void Main(string[] args)
        {
            while (true)
            {
                // init sensors
                TemperatureSensorInterface temperatureSensor = new VirtualTemperatureSensor();
                // TODO add more sensors

                //TODO s2 reads from list
                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost:8080/cars/AB123CD");
                httpWebRequest.ContentType = "text/json";
                httpWebRequest.Method      = "POST";

                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    streamWriter.Write(temperatureSensor.toJson());
                }

                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

                Console.Out.WriteLine(httpResponse.StatusCode);

                System.Threading.Thread.Sleep(1000);
            }
        }
Exemplo n.º 2
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);
            }
        }