示例#1
0
        public override void Connect()
        {
            //Creating propValues for connection
            IPortableDeviceValues clientValues = (IPortableDeviceValues) new PortableDeviceTypesLib.PortableDeviceValuesClass();

            //Set the application name
            _tagpropertykey prop = PortableDevicePKeys.WPD_CLIENT_NAME;

            clientValues.SetStringValue(ref prop, "iTunes Agent");
            //Set the App version
            prop = PortableDevicePKeys.WPD_CLIENT_MAJOR_VERSION;
            clientValues.SetFloatValue(ref prop, 2f);
            //Set the app minor version
            prop = PortableDevicePKeys.WPD_CLIENT_MINOR_VERSION;
            clientValues.SetFloatValue(ref prop, 0f);

            //Open connection
            this.portableDevice.Open(this.deviceId, clientValues);

            SetValues();

            RefreshContents();

            this.isConnected = true;
        }
        /// <summary>
        /// Connect to the portable device
        /// </summary>
        /// <param name="appName"></param>
        /// <param name="majorVersionNumber"></param>
        /// <param name="minorVersionNumber"></param>
        public void ConnectToDevice(string appName, float majorVersionNumber, float minorVersionNumber)
        {
            if (string.IsNullOrEmpty(appName))
            {
                throw new ArgumentNullException("appName");
            }

            if (IsConnected)
            {
                return;
            }
            //Creating propValues for connection
            IPortableDeviceValues clientValues = (IPortableDeviceValues) new PortableDeviceTypesLib.PortableDeviceValuesClass();

            //Set the application name
            _tagpropertykey prop = PortableDevicePKeys.WPD_CLIENT_NAME;

            clientValues.SetStringValue(ref prop, appName);
            //Set the App version
            prop = PortableDevicePKeys.WPD_CLIENT_MAJOR_VERSION;
            clientValues.SetFloatValue(ref prop, majorVersionNumber);
            //Set the app minor version
            prop = PortableDevicePKeys.WPD_CLIENT_MINOR_VERSION;
            clientValues.SetFloatValue(ref prop, minorVersionNumber);

            //Open connection
            this.portableDeviceClass.Open(this.DeviceId, clientValues);

            //Extract device capabilities
            //this.ExtractDeviceCapabilities();

            this.eventCallback = new PortableDeviceEventCallback(this);
            // According to documentation pParameters should be null (see http://msdn.microsoft.com/en-us/library/dd375684%28v=VS.85%29.aspx )
            this.portableDeviceClass.Advise(0, this.eventCallback, null, out this.adviseCookie);

            IsConnected = true;
        }