public async Task<ActionResult> Index(string deviceId) { DeviceModel device = await _deviceLogic.GetDeviceAsync(deviceId); if (device.DeviceProperties == null) { throw new DeviceRequiredPropertyNotFoundException("'DeviceProperties' property is missing"); } IList<SelectListItem> commandListItems = CommandListItems(device); bool deviceIsEnabled = device.DeviceProperties.GetHubEnabledState(); DeviceCommandModel deviceCommandsModel = new DeviceCommandModel { CommandHistory = device.CommandHistory, CommandsJson = JsonConvert.SerializeObject(device.Commands), SendCommandModel = new SendCommandModel { DeviceId = device.DeviceProperties.DeviceID, CommandSelectList = commandListItems, CanSendDeviceCommands = deviceIsEnabled && PermsChecker.HasPermission(Permission.SendCommandToDevices) }, DeviceId = device.DeviceProperties.DeviceID }; return View(deviceCommandsModel); }
/// <summary> /// Returns a set of the names of a the Commands a Device supports. /// </summary> /// <param name="model"> /// A DeviceCommandModel, representing the Device for which a set of /// supported Command names should be returned. /// </param> /// <returns> /// A set of <paramref name="model" />'s supported Command names. /// </returns> public static HashSet<string> BuildAvailableCommandNameSet(DeviceCommandModel model) { if (model == null) { throw new ArgumentNullException("model"); } IEnumerable<string> commandNames = new string[0]; if ((model.SendCommandModel != null) && (model.SendCommandModel.CommandSelectList != null)) { commandNames = commandNames.Concat( model.SendCommandModel.CommandSelectList.Where( t => (t != null) && !string.IsNullOrWhiteSpace(t.Value)).Select(u => u.Value)); } return new HashSet<string>(commandNames); }
public async Task<ActionResult> Index(string deviceId) { dynamic device = await _deviceLogic.GetDeviceAsync(deviceId); List<SelectListItem> commandListItems = CommandListItems(device); var deviceCommandsModel = new DeviceCommandModel { CommandHistory = new List<dynamic>(CommandHistorySchemaHelper.GetCommandHistory(device)), CommandsJson = JsonConvert.SerializeObject(device.Commands), SendCommandModel = new SendCommandModel { DeviceId = DeviceSchemaHelper.GetDeviceID(device), CommandSelectList = commandListItems, CanSendDeviceCommands = DeviceSchemaHelper.GetHubEnabledState(device) == true && PermsChecker.HasPermission(Permission.SendCommandToDevices) }, DeviceId = DeviceSchemaHelper.GetDeviceID(device) }; return View(deviceCommandsModel); }