Exemple #1
0
        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);
        }
Exemple #2
0
        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");
            }
        }
Exemple #3
0
        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");
            }
        }