Ejemplo n.º 1
0
        private static void processCommand(C2DCommand c2dCommand)
        {
            switch (c2dCommand.command)
            {
            case C2DCommand.COMMAND_TEMPERATURE_ALERT:
                displayReceivedCommand(c2dCommand, ConsoleColor.Yellow);
                break;

            case C2DCommand.COMMAND_TURN_ONOFF:
                displayReceivedCommand(c2dCommand, ConsoleColor.Green);
                _isStopped = c2dCommand.value.Equals("0");     // 0 means turn the machine off, otherwise is turning on.
                break;

            default:
                Console.WriteLine("IT IS NOT A SUPPORTED COMMAND!");
                break;
            }
        }
Ejemplo n.º 2
0
        private static async void receiveCloudToDeviceMessageAsync()
        {
            Console.WriteLine("\nReceiving cloud to device messages from service");
            while (true)
            {
                // <Receive Async Here>


                string msg = Encoding.ASCII.GetString(receivedMessage.GetBytes());

                try
                {
                    C2DCommand c2dCommand = JsonConvert.DeserializeObject <C2DCommand>(msg);
                    processCommand(c2dCommand);
                }
                catch (Exception e)
                {
                    Console.WriteLine("CANNOT PROCESS THIS COMMAND! {0}", e.ToString());
                }

                // <C2D Complete Async Here>
                await _deviceClient.CompleteAsync(xxxx);
            }
        }
Ejemplo n.º 3
0
 private static void displayReceivedCommand(C2DCommand c2dCommand, ConsoleColor color)
 {
     Console.ForegroundColor = color;
     Console.WriteLine("Received message: {0}, {1}, {2}\n", c2dCommand.command, c2dCommand.value, c2dCommand.time);
     Console.ResetColor();
 }