/// <summary> /// Sends a command to the provided device and updates the command history of the device /// </summary> /// <param name="device">Device to send the command to</param> /// <param name="commandName">Name of the command to send</param> /// <param name="parameters">Parameters to send with the command</param> /// <returns></returns> private async Task <dynamic> SendCommandAsyncWithDevice(dynamic device, string commandName, dynamic parameters) { string deviceId; if (device == null) { throw new ArgumentNullException("device"); } bool canDevicePerformCommand = CommandSchemaHelper.CanDevicePerformCommand(device, commandName); deviceId = DeviceSchemaHelper.GetDeviceID(device); if (!canDevicePerformCommand) { throw new UnsupportedCommandException(deviceId, commandName); } dynamic command = CommandHistorySchemaHelper.BuildNewCommandHistoryItem(commandName); CommandHistorySchemaHelper.AddParameterCollectionToCommandHistoryItem(command, parameters); CommandHistorySchemaHelper.AddCommandToHistory(device, command); //await _iotHubRepository.SendCommand(deviceId, command); bool isSimulated = DeviceSchemaHelper.IsDeviceSimuated(device); await this._iotHubRepository.SendCommand(deviceId, isSimulated, command); await this._deviceRegistryCrudRepository.UpdateDeviceAsync(device); return(command); }