Exemplo n.º 1
0
        private async void createButton_Click(object sender, EventArgs e)
        {
            if (comboBoxDevMDeviceType.Text == "" || comboBoxDevMStatus.Text == "")
            {
                MessageBox.Show("Both Device Type and Status are required !", "** Input Error **", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                var device = new Device(deviceIDTextBox.Text);
                await registryManager.AddDeviceAsync(device);

                device = await registryManager.GetDeviceAsync(device.Id);

                device.Authentication.SymmetricKey.PrimaryKey   = primaryKeyTextBox.Text;
                device.Authentication.SymmetricKey.SecondaryKey = secondaryKeyTextBox.Text;
                device = await registryManager.UpdateDeviceAsync(device);

                // IoT Hub Device
                var deviceCreated = new DeviceCreatedForm(device.Id, device.Authentication.SymmetricKey.PrimaryKey, device.Authentication.SymmetricKey.SecondaryKey);
                deviceCreated.ShowDialog();

                // RBFX Device Master
                var deviceEntity = new DeviceEntity();
                deviceEntity.Id = device.Id;
                deviceEntity.DevM_DeviceType          = comboBoxDevMDeviceType.Text;
                deviceEntity.DevM_Status              = comboBoxDevMStatus.Text;
                deviceEntity.DevM_ResourceGroupId     = textBoxDevMRescGrpId.Text;
                deviceEntity.DevM_Description         = textBoxDevMDesc.Text;
                deviceEntity.DevM_Registered_DateTime = DateTime.Now;
                var dmi = new DeviceMasterInfo(sqlConnectionString, deviceEntity);
                dmi.CreateDevice();

                // Create Storage Queue (Option)
                if (queueStorageConnString != string.Empty)
                {
                    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(queueStorageConnString);
                    CloudQueueClient    queueClient    = storageAccount.CreateCloudQueueClient();
                    CloudQueue          queue          = queueClient.GetQueueReference(device.Id);
                    // Create the queue if it doesn't already exist
                    queue.CreateIfNotExists();
                }

                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private async void createButton_Click(object sender, EventArgs e)
        {
            if (comboBoxDevMDeviceType.Text == "" || comboBoxDevMStatus.Text == "")
            {
                MessageBox.Show("Both Device Type and Status are required !", "** Input Error **", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                var device = new Device(deviceIDTextBox.Text);
                await registryManager.AddDeviceAsync(device);

                device = await registryManager.GetDeviceAsync(device.Id);

                device.Authentication.SymmetricKey.PrimaryKey   = primaryKeyTextBox.Text;
                device.Authentication.SymmetricKey.SecondaryKey = secondaryKeyTextBox.Text;
                device = await registryManager.UpdateDeviceAsync(device);

                // IoT Hub Device
                var deviceCreated = new DeviceCreatedForm(device.Id, device.Authentication.SymmetricKey.PrimaryKey, device.Authentication.SymmetricKey.SecondaryKey);
                deviceCreated.ShowDialog();

                // RBFX Device Master
                var deviceEntity = new DeviceEntity();
                deviceEntity.Id = device.Id;
                deviceEntity.DevM_DeviceType          = comboBoxDevMDeviceType.Text;
                deviceEntity.DevM_Status              = comboBoxDevMStatus.Text;
                deviceEntity.DevM_ResourceGroupId     = textBoxDevMRescGrpId.Text;
                deviceEntity.DevM_Description         = textBoxDevMDesc.Text;
                deviceEntity.DevM_Registered_DateTime = DateTime.Now;
                var dmi = new DeviceMasterInfo(sqlConnectionString, deviceEntity);
                dmi.CreateDevice();

                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }