コード例 #1
0
        /// <summary>
        /// 登录
        /// </summary>
        private void Login()
        {
            try
            {
                var loginUrl = LoginQR.GetLoginUrl();
                if (loginUrl == null)
                {
                    return;
                }

                if (loginUrl.Status != true)
                {
                    ExecuteBackSpace();
                    return;
                }

                if (loginUrl.Data == null || loginUrl.Data.Url == null)
                {
                    eventAggregator.GetEvent <MessageEvent>().Publish(DictionaryResource.GetString("GetLoginUrlFailed"));
                    return;
                }

                PropertyChangeAsync(new Action(() => { LoginQRCode = LoginQR.GetLoginQRCode(loginUrl.Data.Url); }));
                Core.Utils.Debugging.Console.PrintLine(loginUrl.Data.Url + "\n");
                LogManager.Debug(Tag, loginUrl.Data.Url);

                GetLoginStatus(loginUrl.Data.OauthKey);
            }
            catch (Exception e)
            {
                Core.Utils.Debugging.Console.PrintLine("Login()发生异常: {0}", e);
                LogManager.Error(Tag, e);
            }
        }
コード例 #2
0
        private void ChangeQRLogin()
        {
            SDKClient.SDKClient.Instance.NewDataRecv -= Instance_NewDataRecv;
            SDKClient.SDKClient.Instance.ConnState   -= Instance_ConnState;
            var loginQR = new LoginQR();

            loginQR.RefVM    = this;
            QRContentControl = loginQR;
        }
コード例 #3
0
 private void ChangeLoginAccount(object para)
 {
     IsQuickLogin = false;
     //QRContentControl = new LoginQR();
     App.Current.Dispatcher.Invoke(() =>
     {
         SDKClient.SDKClient.Instance.NewDataRecv -= Instance_NewDataRecv;
         SDKClient.SDKClient.Instance.ConnState   -= Instance_ConnState;
         var loginQR      = new LoginQR();
         loginQR.RefVM    = this;
         QRContentControl = loginQR;
     });
 }
コード例 #4
0
        /// <summary>
        /// 循环查询登录状态
        /// </summary>
        /// <param name="oauthKey"></param>
        private void GetLoginStatus(string oauthKey)
        {
            CancellationToken cancellationToken = tokenSource.Token;

            while (true)
            {
                Thread.Sleep(1000);
                var loginStatus = LoginQR.GetLoginStatus(oauthKey);
                if (loginStatus == null)
                {
                    continue;
                }

                Core.Utils.Debugging.Console.PrintLine(loginStatus.Code + "\n" + loginStatus.Message + "\n" + loginStatus.Url + "\n");

                switch (loginStatus.Code)
                {
                case -1:
                    // 没有这个oauthKey

                    // 发送通知
                    eventAggregator.GetEvent <MessageEvent>().Publish(DictionaryResource.GetString("LoginKeyError"));
                    LogManager.Info(Tag, DictionaryResource.GetString("LoginKeyError"));

                    // 取消任务
                    tokenSource.Cancel();

                    // 创建新任务
                    PropertyChangeAsync(new Action(() => { Task.Run(Login, (tokenSource = new CancellationTokenSource()).Token); }));
                    break;

                case -2:
                    // 不匹配的oauthKey,超时或已确认的oauthKey

                    // 发送通知
                    eventAggregator.GetEvent <MessageEvent>().Publish(DictionaryResource.GetString("LoginTimeOut"));
                    LogManager.Info(Tag, DictionaryResource.GetString("LoginTimeOut"));

                    // 取消任务
                    tokenSource.Cancel();

                    // 创建新任务
                    PropertyChangeAsync(new Action(() => { Task.Run(Login, (tokenSource = new CancellationTokenSource()).Token); }));
                    break;

                case -4:
                    // 未扫码
                    break;

                case -5:
                    // 已扫码,未确认
                    PropertyChangeAsync(new Action(() =>
                    {
                        LoginQRCodeStatus  = Visibility.Visible;
                        LoginQRCodeOpacity = 0.3;
                    }));
                    break;

                case 0:
                    // 确认登录

                    // 发送通知
                    eventAggregator.GetEvent <MessageEvent>().Publish(DictionaryResource.GetString("LoginSuccessful"));
                    LogManager.Info(Tag, DictionaryResource.GetString("LoginSuccessful"));

                    // 保存登录信息
                    try
                    {
                        bool isSucceed = LoginHelper.SaveLoginInfoCookies(loginStatus.Url);
                        if (!isSucceed)
                        {
                            eventAggregator.GetEvent <MessageEvent>().Publish(DictionaryResource.GetString("LoginFailed"));
                            LogManager.Error(Tag, DictionaryResource.GetString("LoginFailed"));
                        }
                    }
                    catch (Exception e)
                    {
                        Core.Utils.Debugging.Console.PrintLine("PageLogin 保存登录信息发生异常: {0}", e);
                        LogManager.Error(e);
                        eventAggregator.GetEvent <MessageEvent>().Publish(DictionaryResource.GetString("LoginFailed"));
                    }

                    // TODO 其他操作


                    // 取消任务
                    Thread.Sleep(3000);
                    PropertyChangeAsync(new Action(() => { ExecuteBackSpace(); }));
                    break;
                }

                // 判断是否该结束线程,若为true,跳出while循环
                if (cancellationToken.IsCancellationRequested)
                {
                    Core.Utils.Debugging.Console.PrintLine("停止Login线程,跳出while循环");
                    LogManager.Debug(Tag, "登录操作结束");
                    break;
                }
            }
        }