コード例 #1
0
ファイル: Extention.cs プロジェクト: crazyants/WeChatRobot
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var userName = value as string;

            Debug.Assert(userName != null, "userName != null");
            var iconBytes = userName.Contains("@@")
                ? WXLogin.WXService.Instance.GetHeadImg(userName)
                : WXLogin.WXService.Instance.GetIcon(userName);

            return(InternalHelp.ConvertByteToBitmapImage(iconBytes));
        }
コード例 #2
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);
         });
     }
 }
コード例 #3
0
        private async Task <bool> InitLoginAsync()
        {
            this.loginLable.Content = "get the wechat code...";

            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 = "please scan the code";
                    }));
                }

                // 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 = "please click login button in you phone!";
                        }));
                    }
                    else if (loginResult is string)
                    {
                        if (ls.GetSidUid(loginResult as string))
                        {
                            break;
                        }

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

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