コード例 #1
0
        /// <summary>
        /// 开启Session。Session需要在调用服务前先行打开,然后完成服务操作后自行关闭(函数会自动关闭),否则可能会遇到无法打开服务的错误
        /// </summary>
        /// <returns></returns>
        public kAMDError StartSession(bool isRretry = false)
        {
            var kAMDSuccess = kAMDError.kAMDSuccess;

            try
            {
                if (!this.isSessionOpen)
                {
                    kAMDSuccess = (kAMDError)MobileDevice.AMDeviceStartSession(this.DevicePtr);
                    if (kAMDSuccess != kAMDError.kAMDInvalidHostIDError)
                    {
                        if (kAMDSuccess != (int)kAMDError.kAMDSuccess)
                        {
                            //修复:Session关闭后一段时间无法再次打开的问题
                            if (!isRretry)
                            {
                                this.Disconnect();
                                this.Connect();
                                return(StartSession(true));
                            }
                            return(kAMDSuccess);
                        }
                        this.isSessionOpen = true;
                        return(kAMDSuccess);
                    }
                    if ((MobileDevice.AMDeviceUnpair(this.DevicePtr) == (int)kAMDError.kAMDSuccess) &&
                        (MobileDevice.AMDevicePair(this.DevicePtr) == (int)kAMDError.kAMDSuccess))
                    {
                        kAMDSuccess = (kAMDError)MobileDevice.AMDeviceStartSession(this.DevicePtr);
                        if (kAMDSuccess != kAMDError.kAMDSuccess)
                        {
                            return(kAMDSuccess);
                        }
                        this.isSessionOpen = true;
                        return(kAMDSuccess);
                    }
                }
                return(kAMDSuccess);
            }
            catch
            {
                kAMDSuccess = kAMDError.kAMDUndefinedError;
            }
            return(kAMDSuccess);
        }