Пример #1
0
        public Device(PortableDeviceManager devices, string id)
        {
            this.id = id;

            uint length = 0;

            devices.GetDeviceDescription(id, null, ref length);

            char[] bytes = new char[length];
            devices.GetDeviceDescription(id, bytes, ref length);
            description = new string(bytes, 0, (int)length - 1);

            foobalator.Log.WriteLine(string.Format("Discovered {0}", description));

            PortableDeviceValues values = new PortableDeviceValues();

            values.SetUnsignedIntegerValue(Constants.WPD_CLIENT_DESIRED_ACCESS, Constants.GENERIC_READ | Constants.GENERIC_WRITE);

            PortableDevice device = new PortableDevice();

            device.Open(id, values);
            device.Content(out content);
            content.Properties(out properties);

            DeviceObject root = new DeviceObject(this, "DEVICE");

            DeviceObject phoneFolder = root.GetChildByName("Phone");

            if (phoneFolder == null)
            {
                return;
            }

            musicFolder = phoneFolder.GetChildByName("Music");
            if (musicFolder == null)
            {
                return;
            }

            playlistFolder = musicFolder.GetChildByName("Playlist");
            if (playlistFolder == null)
            {
                return;
            }
        }
Пример #2
0
        /// <summary>
        /// 连接设备
        /// </summary>
        public bool Connect(string DeviceId)
        {
            bool bRet = true;

            try
            {
                IPortableDeviceValues clientInfo = (IPortableDeviceValues) new PortableDeviceTypesLib.PortableDeviceValues();
                portableDevice = new PortableDevice();
                portableDevice.Open(DeviceId, clientInfo);
                portableDevice.Content(out deviceContent);
                deviceContent.Properties(out deviceProperties);
                deviceProperties.GetValues("DEVICE", null, out deviceValues);

                AdviceEvent();
            }
            catch (Exception)
            {
                bRet = false;
            }

            return(bRet);
        }