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)); }
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(); //MDS bae 2017.0615 var appSettingsReader = new AppSettingsReader(); var connectionString = "----"; CloudStorageAccount storageaccount = CloudStorageAccount.Parse(connectionString); blobClient = storageaccount.CreateCloudBlobClient(); blobContainer = blobClient.GetContainerReference(blobContainerName); await blobContainer.CreateIfNotExistsAsync(); await blobContainer.SetPermissionsAsync(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }); CloudBlobDirectory blobDirectory = blobContainer.GetDirectoryReference(deviceId); foreach (IListBlobItem blob in blobDirectory.ListBlobs()) { if (blob.GetType() == typeof(CloudBlockBlob)) { //string blobfilename = blob.Uri.Segments.Last(); //blobfilename = blobfilename.Remove(blobfilename.Length - 4); //if (blobfilename == device.CommandHistory[device.CommandHistory.Count - 1].MessageId) flirimageurl = blob.Uri.ToString(); } } DeviceCommandModel deviceCommandsModel = new DeviceCommandModel { CommandHistory = device.CommandHistory.Where(c => c.DeliveryType == DeliveryType.Message).ToList(), CommandsJson = JsonConvert.SerializeObject(device.Commands.Where(c => c.DeliveryType == DeliveryType.Message)), SendCommandModel = new SendCommandModel { DeviceId = device.DeviceProperties.DeviceID, CommandSelectList = commandListItems, CanSendDeviceCommands = deviceIsEnabled && PermsChecker.HasPermission(Permission.SendCommandToDevices) }, ImageUrl = flirimageurl, //MDS bae 2017.0615 DeviceId = device.DeviceProperties.DeviceID, }; return(View(deviceCommandsModel)); }
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)); }
/// <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 <IActionResult> ExecuteCommand([FromQuery] string user_id, [FromQuery] string serial_number, [FromBody] DeviceCommandModel model) { var response = await GetResultAsync( action : async() => await this._deviceService.ExecuteActionAsync(user_id, serial_number, model.action_name, model.type, model.parameters), modelState : ModelState ); return(Result(response)); }