Esempio n. 1
0
        public PlayLoad DecryptAzureIoTCommand(AzureIoTCommand azureIoTCommand)
        {
            switch (azureIoTCommand.PlayLoad.Command)
            {
            case IoTCommandTypeEnum.ShowName:

                lstCommands.Items.Add(azureIoTCommand.PlayLoad.Name);
                azureIoTCommand.PlayLoad.Status  = "OK";
                azureIoTCommand.PlayLoad.Command = IoTCommandTypeEnum.ShowName;
                return(azureIoTCommand.PlayLoad);

            case IoTCommandTypeEnum.ChangeColor:

                Random randomizer = new Random();
                int    r = randomizer.Next(0, 255), g = randomizer.Next(0, 255), b = randomizer.Next(0, 255);
                button1.BackColor = Color.FromArgb(r, g, b);

                azureIoTCommand.PlayLoad.Status  = "OK";
                azureIoTCommand.PlayLoad.Command = IoTCommandTypeEnum.ChangeColor;
                return(azureIoTCommand.PlayLoad);

            default:

                azureIoTCommand.PlayLoad.Status = "NOT FOUND";
                return(azureIoTCommand.PlayLoad);
            }
        }
Esempio n. 2
0
        private Task <MethodResponse> GetCommandFromCloud(MethodRequest methodRequest, object userContext)
        {
            try
            {
                if (!string.IsNullOrEmpty(methodRequest.DataAsJson))
                {
                    AzureIoTCommand azureIoTCommand = JsonConvert.DeserializeObject <AzureIoTCommand>(methodRequest.DataAsJson);
                    var             returnPlayLoad  = azureIoTCommand.PlayLoad;
                    returnPlayLoad = DecryptAzureIoTCommand(azureIoTCommand);
                    return(Task.FromResult(new MethodResponse(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(returnPlayLoad)), 200)));
                }

                return(Task.FromResult(new MethodResponse(Encoding.UTF8.GetBytes("ERROR"), 200)));
            }
            catch (Exception exception)
            {
                return(null);
            }
        }