Пример #1
0
        private void connectWithDevice(object state)
        {
            if (detected)
            {
                return;
            }

            detected = true;

            Console.WriteLine("Device detected");

            var devices = new PortableDeviceCollection();

            devices.Refresh();

            device = devices.First();
            device.Connect();

            Console.WriteLine("Connected to: " + device.FriendlyName);

            var root = device.GetContents();

            servicePlatformFolder = (PortableDeviceFolder)device.getServicePlatformFolder();

            if (servicePlatformFolder == null)
            {
                Console.WriteLine("Could not find ServicePlatform folder, have you installed ServicePlatform mobile app? Disconnecting...");
                device.Disconnect();
                return;
            }

            getServicesList(device, servicePlatformFolder);

            if (!servicesFileDetected)
            {
                Console.WriteLine("Could not detect services! Disconnecting...");
                device.Disconnect();
                return;
            }

            BeginInvoke(new MethodInvoker(delegate {
                Show();
                //MessageBox.Show("Connected to: " + device.FriendlyName);
            }));

            cleanup(device, servicePlatformFolder);

            //device.Disconnect();
        }