private void UpdateDevice_Click(object sender, RoutedEventArgs e) { AzureDevices SelectedDevice = (AzureDevices)DeviceList.SelectedItems[0]; if (TrueRadio.IsChecked.Value) { SelectedDevice.Status = true; } else { SelectedDevice.Status = false; } var index = DeviceList.Items.IndexOf(DeviceList.SelectedItem); list.RemoveAt(index); list.Insert(index, SelectedDevice); /* DeviceList.ItemsSource = null; * DeviceList.ItemsSource = list;*/ MyAzureClass myAzureClass = new MyAzureClass(); myAzureClass.UpdateRecordInTable(SelectedDevice); AzureIoTHub.SendDeviceToCloudMessageAsync(); }
public async Task <AzureDevices> AddDeviceToCloud(string device, bool isChecked) { // Retrieve the storage account from the connection string. AzureDevices deviceStatus = new AzureDevices(); deviceStatus.DeviceId = device; deviceStatus.Status = isChecked; deviceStatus.AssignRowKey(); deviceStatus.AssignPartitionKey(); var table = GetCloudTable(); AzureDevices deviceRetrieve = await AzureDevices.RetrieveRecord(table, device); if (deviceRetrieve == null) { TableOperation tableOperation = TableOperation.Insert(deviceStatus); await table.ExecuteAsync(tableOperation); Debug.WriteLine("Record inserted"); } else { Debug.WriteLine("Record exists"); } return(deviceRetrieve); }
private void DeleteDeviceButton_Click(object sender, RoutedEventArgs e) { //int Index = DeviceList.SelectedIndex; AzureDevices SelectedDevice = (AzureDevices)DeviceList.SelectedItems[0]; MyAzureClass myAzureClass = new MyAzureClass(); myAzureClass.DeleteRecordinTable(SelectedDevice.DeviceId); var index = DeviceList.Items.IndexOf(DeviceList.SelectedItem); list.RemoveAt(index); DeviceList.ItemsSource = null; DeviceList.ItemsSource = list; }
public async void DeleteRecord(CloudTable table, string deviceid) { AzureDevices DeleteAzureDevice = await RetrieveRecord(table, deviceid); if (DeleteAzureDevice != null) { TableOperation tableOperation = TableOperation.Delete(DeleteAzureDevice); await table.ExecuteAsync(tableOperation); Debug.WriteLine("Record deleted"); } else { Debug.WriteLine("Record does not exists"); } }
public async void DeleteRecordinTable(string DeviceId) { var table = GetCloudTable(); AzureDevices device = await AzureDevices.RetrieveRecord(table, DeviceId); if (device != null) { TableOperation tableOperation = TableOperation.Delete(device); await table.ExecuteAsync(tableOperation); Debug.WriteLine("Record deleted"); } else { Debug.WriteLine("Record does not exists"); } }
public async void UpdateRecordInTable(AzureDevices device) { var table = GetCloudTable(); AzureDevices devices = await AzureDevices.RetrieveRecord(table, device.DeviceId); if (devices != null) { TableOperation tableOperation = TableOperation.InsertOrReplace(device); await table.ExecuteAsync(tableOperation); Console.WriteLine("Record updated"); } else { Console.WriteLine("Record does not exists"); } }