Пример #1
0
        private void SetDeviceList()
        {
            string active = String.Empty;

            if (deviceselector.Items.Count != 0)
            {
                active = ((DataModelDevicesItem)deviceselector.SelectedItem).Serial;
            }

            App.Current.Dispatcher.Invoke((Action) delegate
            {
                // Here we refresh our combobox
                deviceselector.Items.Clear();
            });

            // This will get the currently connected ADB devices
            IEnumerable <DataModelDevicesItem> adbDevices = ADB.Devices();

            // This will get the currently connected Fastboot devices
            IEnumerable <DataModelDevicesItem> fastbootDevices = Fastboot.Devices();

            foreach (DataModelDevicesItem device in adbDevices)
            {
                App.Current.Dispatcher.Invoke((Action) delegate
                {
                    // here goes the add command ;)
                    deviceselector.Items.Add(device);
                    ConsoleAppend(String.Format("Device connected: {0} ({1}), State: {2}.", device.Model, device.Serial.ToString(), device.State.ToString()));
                });
            }
            foreach (DataModelDevicesItem device in fastbootDevices)
            {
                App.Current.Dispatcher.Invoke((Action) delegate
                {
                    deviceselector.Items.Add(device);
                    ConsoleAppend(String.Format("Device connected: {0} ({1}), State: {2}.", device.Model, device.Serial.ToString(), device.State.ToString()));
                });
            }
            if (deviceselector.Items.Count != 0)
            {
                int  i     = 0;
                bool empty = true;
                foreach (DataModelDevicesItem device in deviceselector.Items)
                {
                    if (device.Serial == active)
                    {
                        empty = false;
                        deviceselector.SelectedIndex = i;
                        break;
                    }
                    i++;
                }
                if (empty)
                {
                    // This calls will select the BASE class if we have no connected devices
                    ADB.SelectDevice();
                    Fastboot.SelectDevice();

                    App.Current.Dispatcher.Invoke((Action) delegate
                    {
                        deviceselector.SelectedIndex = 0;
                    });
                }
            }
        }