private async void CheckDeviceConnection(object state)
        {
            Console.WriteLine("START getting attached devices");

            Devices = ProcessUtils.GetAttachedDevices();

            Console.WriteLine($"START getting attached devices SUCCESSFULLY, count={Devices?.Length}");

            _newDevices.Clear();

            foreach (var device in Devices)
            {
                if (!_oldDevices.Contains(device))
                {
                    _newDevices.Add(device);
                    _oldDevices.Add(device);
                }
            }

            if (VmManager.Instance.GetRunningCount() != Devices.Length)
            {
                _connectionFailedTimes++;

                if (VmManager.Instance.RunningGroupIndex != -1)
                {
                    if (_connectionFailedTimes > 30)
                    {
                        //ReconnectDevices();
                    }
                    else
                    {
                        //lock (TimerSyncObj)
                        //{
                        _checkCountTimer.Change(5000, Timeout.Infinite);
                        //}
                    }
                }
            }

            if (_newDevices.Count > 0)
            {
                // new device(s) attached

                EventAggregatorManager.Instance.EventAggregator.GetEvent <NewDeviceAttachedEvent>().Publish();

                List <Task> tasks = new List <Task>();

                foreach (var device in _newDevices)
                {
                    Console.WriteLine($"{device} ATTACHED");
                    tasks.Add(LaunchAndroidCommanderAsync(device));
                }

                await Task.WhenAll(tasks);
            }
        }
Beispiel #2
0
        private async void btnGetAttachedDevices_Click(object sender, RoutedEventArgs e)
        {
            string output = string.Empty;

            await Task.Run(() =>
            {
                string[] devices = ProcessUtils.GetAttachedDevices();

                for (int i = 0; i < devices.Length; i++)
                {
                    output += (devices[i] + "\r\n");
                }
            });

            MessageDialogManager.ShowDialogAsync($"连接设备列表:\r\n{output}");
        }
Beispiel #3
0
        private async void btnLaunchAndroidCommander_Click(object sender, RoutedEventArgs e)
        {
            if (VmManager.Instance.RunningGroupIndex == -1)
            {
                MessageDialogManager.ShowDialogAsync(SystemLanguageManager.Instance.ResourceManager.GetString("Error_Please_Launch_A_Vm", SystemLanguageManager.Instance.CultureInfo));
                return;
            }

            List <Task> tasks = new List <Task>();

            string[] devices = ProcessUtils.GetAttachedDevices();

            foreach (var device in devices)
            {
                tasks.Add(LaunchAndroidCommanderAsync(device));
            }

            await Task.WhenAll(tasks);
        }
        //private void CheckBlock2(object state)
        //{
        //    if (_killServerResult == null)
        //    {
        //        Console.WriteLine("_killServerResult is null");
        //        _checkBlockTimer2.Change(4000, Timeout.Infinite);
        //        Task.Run(() =>
        //        {
        //            _killServerResult = ProcessUtils.KillAdbServer();
        //        });
        //    }
        //    else
        //    {
        //        if (_startServerResult == null)
        //        {
        //            Console.WriteLine("_startServerResult is null");
        //            _checkBlockTimer2.Change(4000, Timeout.Infinite);
        //            Task.Run(() =>
        //            {
        //                _startServerResult = ProcessUtils.StartAdbServer();
        //            });
        //        }
        //        else
        //        {
        //            LaunchAndroidTestOnTheBackground(1000);
        //        }
        //    }
        //}

        //public void ReconnectDevices()
        //{
        //    Devices = new string[0];

        //    if (VmManager.Instance.RunningGroupIndex == -1)
        //    {
        //        MessageDialogManager.ShowDialogAsync(SystemLanguageManager.Instance.ResourceManager.GetString("Error_Please_Launch_A_Vm", SystemLanguageManager.Instance.CultureInfo));

        //        return;
        //    }

        //    lock (TimerSyncObj)
        //    {
        //        _checkCountTimer.Change(Timeout.Infinite, Timeout.Infinite);
        //    }

        //    EventAggregatorManager.Instance.EventAggregator.GetEvent<VmClosedEvent>().Publish();

        //    _checkBlockTimer2.Change(1000, Timeout.Infinite);
        //}

        private void CheckBlock(object state)
        {
            if (_rawDevices == null)
            {
                Console.WriteLine("TRY getting attached devices");
                _checkBlockTimer.Change(6000, Timeout.Infinite);
                Task.Run(() =>
                {
                    _rawDevices = ProcessUtils.GetAttachedDevices();
                });
            }
            else
            {
                Console.WriteLine($"TRY getting attached devices SUCCESSFULLY, count={_rawDevices?.Length}");
                //lock (TimerSyncObj)
                //{
                _checkCountTimer.Change(1000, Timeout.Infinite);
                //}
            }
        }