private static void processLinuxCommand(C2DCommandLinux c2dCommand) { switch (c2dCommand.Name) { case C2DCommandLinux.COMMAND_CUTOUT_SPEED_WARNING: displayReceivedLinuxCommand(c2dCommand.Name, null, ConsoleColor.Yellow); break; case C2DCommandLinux.COMMAND_REPAIR_WARNING: displayReceivedLinuxCommand(c2dCommand.Name, null, ConsoleColor.Red); break; case C2DCommandLinux.COMMAND_TURN_ONOFF: string on = (string)c2dCommand.Parameters["On"]; displayReceivedLinuxCommand(c2dCommand.Name, on, ConsoleColor.Green); _isStopped = on.Equals("0"); // 0 means turn the machine off, otherwise is turning on. break; case C2DCommandLinux.COMMAND_RESET_DEPRECIATION: string depreciation = (string)c2dCommand.Parameters["Depreciation"]; displayReceivedLinuxCommand(c2dCommand.Name, depreciation, ConsoleColor.Cyan); _currentDepreciation = Convert.ToDouble(depreciation); break; default: Console.WriteLine("IT IS NOT A SUPPORTED COMMAND!"); break; } }
private static async void receiveCloudToDeviceMessageAsync() { Console.WriteLine("\nReceiving cloud to device messages from service"); while (true) { Message receivedMessage = await _deviceClient.ReceiveAsync(); if (receivedMessage == null) { continue; // It returns null after a specifiable timeout period (in this case, the default of one minute is used) } string msg = Encoding.ASCII.GetString(receivedMessage.GetBytes()); try { C2DCommandLinux c2dCommand = JsonConvert.DeserializeObject <C2DCommandLinux>(msg); processLinuxCommand(c2dCommand); } catch (Exception e) { Console.WriteLine("CANNOT PROCESS THIS COMMAND!"); } await _deviceClient.CompleteAsync(receivedMessage); } }