Exemplo n.º 1
0
 private void UpdateImage(object sender, NotifyCollectionChangedEventArgs e)
 {
     foreach (WXUserViewModel item in e.NewItems)
     {
         Task.Run(() =>
         {
             var iconBytes = item.UserName.Contains("@@")
                 ? WXLogin.WXService.Instance.GetHeadImg(item.UserName)
                 : WXLogin.WXService.Instance.GetIcon(item.UserName);
             item.BitMapImage = InternalHelp.ConvertByteToBitmapImage(iconBytes);
         });
     }
 }
Exemplo n.º 2
0
        private async Task <bool> InitLoginAsync()
        {
            this.loginLable.Content = "二维码获取中...";

            await Task.Run(() =>
            {
                // start login
                var ls = new LoginService();

                if (ls.LoginCheck() == null)
                {
                    this.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        this.codeImage.Source   = InternalHelp.ConvertByteToBitmapImage(ls.GetQRCode());
                        this.loginLable.Content = "请扫描二维码";
                    }));
                }

                // if the user scan and click login button
                while (true)
                {
                    var loginResult = ls.LoginCheck();

                    if (loginResult is byte[])
                    {
                        this.Dispatcher.BeginInvoke(new Action(() =>
                        {
                            this.codeImage.Source   = InternalHelp.ConvertByteToBitmapImage(loginResult as byte[]);
                            this.loginLable.Content = "请点击手机上的登陆按钮!";
                        }));
                    }
                    else if (loginResult is string)
                    {
                        if (ls.GetSidUid(loginResult as string))
                        {
                            break;
                        }

                        MessageBox.Show("当前环境存在异常!登录失败!");
                        Environment.Exit(0);
                    }
                }
            });

            _wxSerivice = WXService.Instance;
            return(_wxSerivice != null);
        }