static void Main(string[] args) { int pullmanNumber = 6; int count = 0; var redis = new RedisClient("127.0.0.1"); Pullman p1 = new Pullman("CA128TD", 70); Pullman p2 = new Pullman("DB94111", 40); Pullman p3 = new Pullman("AA17424", 50); Pullman p4 = new Pullman("EE119CA", 70); Pullman p5 = new Pullman("PI11063", 70); Pullman p6 = new Pullman("PD54715", 30); while (true) { Thread.Sleep(3000); p1.Update(); p2.Update(); p3.Update(); p4.Update(); p5.Update(); p6.Update(); // sendToApi(JsonCreator(p1)); // sendToApi(JsonCreator(p2)); // sendToApi(JsonCreator(p3)); // sendToApi(JsonCreator(p4)); // sendToApi(JsonCreator(p5)); // sendToApi(JsonCreator(p6)); redis.LPush("sensors_data", JsonCreator(p1)); redis.LPush("sensors_data", JsonCreator(p2)); redis.LPush("sensors_data", JsonCreator(p3)); redis.LPush("sensors_data", JsonCreator(p4)); redis.LPush("sensors_data", JsonCreator(p5)); redis.LPush("sensors_data", JsonCreator(p6)); if (ping()) { if (count > 0) { for (int i = 0; i < count * pullmanNumber; i++) { sendToApi(redis.BLPop(30, "sensors_data")); } } for (int i = 0; i < pullmanNumber; i++) { sendToApi(redis.BLPop(30, "sensors_data")); } count = 0; } else { count++; } } }
static string JsonCreator(Pullman p) { string json = JsonConvert.SerializeObject(p, Formatting.Indented); return(json); }