private async Task ParseCommand(string command) { if (command.ToLower().StartsWith("shake")) { var orderShake = command.Split(":"); double fingerTemp = double.Parse(orderShake[1]); simulator.thing.Shake(fingerTemp); Console.WriteLine("Shaking..."); } else if (command.ToLower().StartsWith("put")) { if (command.IndexOf(":") > 0) { var orderPut = command.Split(":"); var top = int.Parse(orderPut[1]); if (top < 1 || top > faceList.Length) { Console.WriteLine("PUT's arg should be 1-6"); } simulator.thing.Put(simulator.RoomTemperature, faceList[top - 1]); } else { simulator.thing.Put(simulator.RoomTemperature); } Console.WriteLine("Put on thing"); } else if (command.ToLower().StartsWith("upload")) { var orderUploadFile = command.Substring(command.IndexOf(":") + 1); var fi = new FileInfo(orderUploadFile); await simulator.UploadFile(fi.Name, fi.FullName); Console.WriteLine("Uploaded {0} as {1}", fi.FullName, fi.Name); } else if (command.ToLower().StartsWith("reported")) { var twinJson = command.Substring(command.IndexOf(":") + 1); await simulator.UpdateReportedProperties(twinJson); Console.WriteLine("Reported via Reported Properties - {0}", twinJson); } else if (command.ToLower().StartsWith("send")) { var msg = command.Substring(command.IndexOf(":") + 1); try { await simulator.SendEvent(msg); Console.WriteLine("Send done - '{0}'", msg); } catch (Exception ex) { Console.WriteLine("Error - {0}", ex.Message); } } else if (command.ToLower().StartsWith("room")) { var orderRoom = command.Split(":"); var newTemp = double.Parse(orderRoom[1]); simulator.Room(newTemp); Console.WriteLine("Room Temperature Updated by {0}", newTemp); } else if (command.ToLower().StartsWith("hum")) { var orderHum = command.Split(":"); var newHum = double.Parse(orderHum[1]); simulator.Humidity(newHum); Console.WriteLine("Humidity updated by {0}", newHum); } else if (command.ToLower().StartsWith("photo")) { var orderPhoto = command.Split(":"); var intervalPhoto = int.Parse(orderPhoto[1]); if (simulatorPhotoTakingTask != null) { if (intervalPhoto > 0) { simulator.ChangeTakingPhotoInterval(intervalPhoto * 1000); } else { simulator.EndTakePicture(simulatorPhotoTakingTask, photoCancellingTokenSource); simulatorPhotoTakingTask = null; } } else { photoCancellingTokenSource = new System.Threading.CancellationTokenSource(); simulatorPhotoTakingTask = simulator.StartTakePicture(intervalPhoto * 1000, photoCancellingTokenSource); } } }