Exemple #1
0
        private async void createButton_Click(object sender, EventArgs e)
        {
            try
            {
                Device 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);

                string deviceInfo = String.Format("ID={0}\nPrimaryKey={1}\nSecondaryKey={2}", device.Id, device.Authentication.SymmetricKey.PrimaryKey, device.Authentication.SymmetricKey.SecondaryKey);

                DeviceCreatedForm deviceCreated = new DeviceCreatedForm(device.Id, device.Authentication.SymmetricKey.PrimaryKey, device.Authentication.SymmetricKey.SecondaryKey);
                deviceCreated.ShowDialog();

                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private async void createButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (String.IsNullOrEmpty(deviceIDTextBox.Text))
                {
                    throw new ArgumentNullException("DeviceId cannot be empty!");
                }

                var device = new Device(deviceIDTextBox.Text);
                device.Authentication = new AuthenticationMechanism();

                if (keysRadioButton.Checked)
                {
                    device.Authentication.SymmetricKey.PrimaryKey   = primaryKeyTextBox.Text;
                    device.Authentication.SymmetricKey.SecondaryKey = secondaryKeyTextBox.Text;
                }
                else if (x509RadioButton.Checked)
                {
                    device.Authentication.SymmetricKey   = null;
                    device.Authentication.X509Thumbprint = new X509Thumbprint()
                    {
                        PrimaryThumbprint   = primaryKeyTextBox.Text,
                        SecondaryThumbprint = secondaryKeyTextBox.Text
                    };
                }

                await registryManager.AddDeviceAsync(device);

                var deviceCreated = new DeviceCreatedForm(device);
                deviceCreated.ShowDialog();

                this.Close();
            }
            catch (Exception ex)
            {
                using (new CenterDialog(this))
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private async void createButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (String.IsNullOrEmpty(deviceIDTextBox.Text))
                {
                    throw new ArgumentNullException("DeviceId cannot be empty!");
                }

                var device = new Device(deviceIDTextBox.Text);
                device.Authentication = new AuthenticationMechanism();

                if (keysRadioButton.Checked)
                {
                    device.Authentication.SymmetricKey.PrimaryKey = primaryKeyTextBox.Text;
                    device.Authentication.SymmetricKey.SecondaryKey = secondaryKeyTextBox.Text;
                }
                else if (x509RadioButton.Checked)
                {
                    device.Authentication.SymmetricKey = null;
                    device.Authentication.X509Thumbprint = new X509Thumbprint()
                    {
                        PrimaryThumbprint = primaryKeyTextBox.Text,
                        SecondaryThumbprint = secondaryKeyTextBox.Text
                    };
                }

                await registryManager.AddDeviceAsync(device);

                var deviceCreated = new DeviceCreatedForm(device);
                deviceCreated.ShowDialog();

                this.Close();
            }
            catch (Exception ex)
            {
                using (new CenterDialog(this))
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private async void createButton_Click(object sender, EventArgs e)
        {
            try
            {
                Device 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);

                string deviceInfo = String.Format("ID={0}\nPrimaryKey={1}\nSecondaryKey={2}", device.Id, device.Authentication.SymmetricKey.PrimaryKey, device.Authentication.SymmetricKey.SecondaryKey);

                DeviceCreatedForm deviceCreated = new DeviceCreatedForm(device.Id, device.Authentication.SymmetricKey.PrimaryKey, device.Authentication.SymmetricKey.SecondaryKey);
                deviceCreated.ShowDialog();

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