Beispiel #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            var Form2 = new Form2();

            if (!CheckTradfriAddress(textBox3.Text))
            {
                MessageBox.Show("Could not find Tradfri gateway. Check address/DNS name.");
                return;
            }
            Form2.textBox1.Text = textBox1.Text;
            if (Form2.ShowDialog().Equals(DialogResult.OK))
            {
                try
                {
                    if (gatewayConnection == null)
                    {
                        gatewayConnection = new TradFriCoapConnector(textBox1.Text, textBox3.Text, textBox2.Text);
                    }

                    TradFriAuth ConnectionSecret = gatewayConnection.GeneratePSK(Form2.textBox2.Text, Form2.textBox1.Text);

                    // Write the connection settings back to the respective text boxes.
                    textBox1.Text     = Form2.textBox1.Text;
                    textBox2.Text     = ConnectionSecret.PSK;
                    gatewayConnection = null;
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Couldn't connect to TradFri gateway with provided settings: {ex.Message}");
                    gatewayConnection = null;
                }
            }
        }
Beispiel #2
0
 private void InitializePsk()
 {
     try
     {
         if (string.IsNullOrEmpty(Properties.Settings.Default.PSK))
         {
             TradFriAuth appSecret = _gatewayConnection.GeneratePSK(Properties.Settings.Default.GatewaySecret, Properties.Settings.Default.AppName);
             Properties.Settings.Default.PSK = appSecret.PSK;
             Properties.Settings.Default.Save();
         }
     }
     catch (Exception exception)
     {
         Console.WriteLine("Unable to create PSK Key: " + exception);
     }
 }