private bool InitDevices()
        {
            if (devices != null)
            {
                return(true);
            }

            try
            {
                if (conf == null)
                {
                    conf = PushBulletAPI.GetSharedConfiguration("pushbullet");
                }
                var data = PushBulletAPI.GetResponseSection(this.conf);
                if (data == null)
                {
                    throw new Exception("Empty ResponseSection");
                }
                this.devices = data;
                // avoid NPEs
                //if (this.devices.Devices.Count == null) this.devices.devices = new PushBulletAPI.DevicesResponse.Device[] { };
                //if (this.devices.shared_devices == null) this.devices.shared_devices = new PushBulletAPI.DevicesResponse.SharedDevice[] { };
                if (devices.SharedDevices.Count == 0)
                {
                    MessageBox.Show("Kaboom");
                }
                return(true);
            }
            catch (Exception e)
            {
                err("Got an Exception while retrieving the devices: " + e.ToString());
                return(false);
            }
        }
示例#2
0
 private void UpdateUIElements(object sender, RunWorkerCompletedEventArgs e)
 {
     if (e.Result is PushBulletAPI.DevicesResponse)
     {
         var res = e.Result as PushBulletAPI.DevicesResponse;
         PushBulletAPI.SetConfigurationOption(PushBullet.conf, "apikey", apikeyInput.Text, false);
         if (doneWindowChkBox.IsChecked.HasValue)
         {
             PushBulletAPI.SetConfigurationOption(PushBullet.conf, "showDoneWindow", (bool)doneWindowChkBox.IsChecked, false);
         }
         var section = PushBulletAPI.GetResponseSection(PushBullet.conf);
         section.Devices.Clear();
         section.SharedDevices.Clear();
         foreach (PushBulletAPI.DevicesResponse.Device device in res.devices)
         {
             section.Devices.Add(device.ToDeviceConfig());
         }
         foreach (PushBulletAPI.DevicesResponse.SharedDevice sDevice in res.shared_devices)
         {
             section.SharedDevices.Add(sDevice.ToDeviceConfig());
         }
         PushBullet.conf.Save(System.Configuration.ConfigurationSaveMode.Modified);
         MessageBox.Show(Properties.Strings.SetupComplete, @"\o/", MessageBoxButton.OK, MessageBoxImage.Information);
         this.Close();
         return;
     }
     this.IsEnabled       = true;
     Mouse.OverrideCursor = null;
     apikeyInput.Clear();
 }