示例#1
0
        protected virtual void AttachVerifyCodeControl(IVerifyCodeControl control)
        {
            if (_verifyCodeBox != null)
            {
                throw new InvalidOperationException();
            }

            _verifyCodeBox = control;
            _verifyCodeBox.EnableAutoVc = VerifyCodeRecognizeServiceLoader.VerifyCodeRecognizeEngine != null && ProgramConfiguration.Instance.AutoSubmitOrderVcCode && Query.EnableAutoVC;

            _verifyCodeBox.AutoVcFailed += async(o, args) =>
            {
                await OnAutoVcFailed(_verifyCodeBox.AutoVcCount).ConfigureAwait(true);
            };
            _verifyCodeBox.AutoVcGiveUp += async(o, args) =>
            {
                await OnAutoVcGiveUp().ConfigureAwait(true);
            };
            _verifyCodeBox.BeginAutoVc += async(o, args) =>
            {
                await OnAutoVcBegin(_verifyCodeBox.AutoVcCount).ConfigureAwait(true);
            };
            _verifyCodeBox.EndAutoVc += async(o, args) =>
            {
                await OnAutoVcSuccess(_verifyCodeBox.AutoVcCount, _verifyCodeBox.AutoVcCode).ConfigureAwait(true);
            };
            _verifyCodeBox.VerifyCodeOnLoad += async(o, args) => await OnVcLoad().ConfigureAwait(true);

            _verifyCodeBox.VerifyCodeLoadComplete += async(o, args) =>
            {
                await OnVcLoadComplete().ConfigureAwait(true);

                OnCaptchaLoaded(this);
            };
            _verifyCodeBox.VerifyCodeLoadFailed += async(o, args) =>
            {
                await OnVcLoadFailed().ConfigureAwait(true);

                //验证码加载失败,则检查一次登录状态
                if (await Session.CheckOnlineStatusIfNeed().ConfigureAwait(true) == false)
                {
                    await PrepareFailed("此次登录即便封印了洪荒之力也依然被踢了……赶紧重新登录...").ConfigureAwait(true);
                }
            };
            _verifyCodeBox.VerifyCodeEnterComplete += async(s, e) =>
            {
                await TryBeginSubmitOrderAsync().ConfigureAwait(true);
            };

            //默认禁用
            _verifyCodeBox.Enabled = false;
        }
        /// <summary>
        /// 路由另一个控件的事件
        /// </summary>
        protected virtual void DelegateVcEvents(IVerifyCodeControl control)
        {
            _control = control;

            control.CodeEnterChanged        += (s, e) => OnCodeEnterChanged();
            control.VerifyCodeEnterComplete += (s, e) => OnVerifyCodeEnterComplete();
            control.BeginAutoVc             += (s, e) => OnBeginAutoVc(this, EventArgs.Empty);
            control.AutoVcFailed            += (s, e) => OnAutoVcFailed();
            control.AutoVcGiveUp            += (s, e) => OnAutoVcGiveUp();
            control.VerifyCodeOnLoad        += (s, e) => OnVerifyCodeOnLoad();
            control.VerifyCodeLoadComplete  += (s, e) => OnVerifyCodeLoadComplete();
            control.VerifyCodeLoadFailed    += (s, e) => OnVerifyCodeLoadFailed();
        }