Ejemplo n.º 1
0
        public MainPage()
        {
            this.InitializeComponent();


            InitGPIO();

            var sender = new object();
            var e      = new RoutedEventArgs();

            GetDevicesButton_Click(sender, e);
            ListenForMessages();


            MyAzureClass myAzureClass = new MyAzureClass();

            // MainDevice = myAzureClass.AddDeviceToCloud(MainDevice.DeviceId, MainDevice.Status).Result;
            // Task.Run(async () => { MainDevice = await myAzureClass.AddDeviceToCloud(MainDevice.DeviceId, MainDevice.Status); }).GetAwaiter().GetResult();
            //AsyncContext.Run(() => );
            //while (MainDevice.PartitionKey == null) { }
            MainDevice.AssignRowKey();
            MainDevice.AssignPartitionKey();

            DeviceStatusButton.IsEnabled = true;
        }
Ejemplo n.º 2
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);
        }