/// <summary>
        /// 页面加载
        /// </summary>
        /// <param name="e"></param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            object[] parameters = e.Parameter as object[];
            if (parameters != null && parameters.Length == 1)
            {
                _user = await UserService.GetUserInfo(parameters[0].ToString());
                if (_user != null)
                {
                    PageTitle.Text = _user.Name + " 的信息";
                    BitmapImage bi = new BitmapImage { UriSource = new Uri(_user.Avatar) };
                    UserAvatar.Source = bi;

                    UserName.Text = _user.Name;
                    Age.Text = _user.Age;
                    Followees.Text = _user.Followees;
                    Followers.Text = _user.Followers;
                    BlogHome.Content = _user.BlogHome;
                    Loading.IsActive = false;


                    ListFollowees.ItemsSource = _list_followees = new CNFolloweeList(_user.BlogApp);
                    ListFollowers.ItemsSource = _list_followers = new CNFollowerList(_user.BlogApp);

                    _list_followees.DataLoaded += _list_followees_DataLoaded;
                    _list_followees.DataLoading += _list_followees_DataLoading;

                    _list_followers.DataLoaded += _list_followers_DataLoaded;
                    _list_followers.DataLoading += _list_followers_DataLoading;
                }
            }
        }
Example #2
0
        /// <summary>
        /// 获取当前登录用户的信息
        /// </summary>
        /// <returns></returns>
        public async static Task<CNUserInfo> GetCurrentUserInfo()
        {
            try
            {
                string html = await BaseService.SendPostRequest(_url_current_user_info, "");
                if (html != null)
                {
                    CNUserInfo user = new CNUserInfo();
                    user.Avatar = html.Split(new string[] { "src=\\\"" }, StringSplitOptions.None)[1]
                        .Split(new string[] { "\\\" alt" }, StringSplitOptions.None)[0];

                    user.BlogApp = html.Split(new string[] { "href=\\\"/u/" }, StringSplitOptions.None)[1]
                        .Split(new string[] { "/\\\" class=\\\"big bold\\\"" }, StringSplitOptions.None)[0];

                    user.Name = html.Split(new string[] { "class=\\\"big bold\\\"\\u003e" }, StringSplitOptions.None)[1]
                        .Split(new string[] { "\\" }, StringSplitOptions.None)[0];

                    return user;
                }
                else
                {
                    return null;
                }
            }
            catch
            {
                return null;
            }
        } 
 /// <summary>
 /// WebView加载完成
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private async void LogintWebView_LoadCompleted(object sender, NavigationEventArgs e)
 {
     if (e.Uri.AbsoluteUri.StartsWith(_login_url)) //登录页面加载完成
     {
         IsPrimaryButtonEnabled = true;  //可以开始登录
     }
     else if (e.Uri.AbsoluteUri.Equals(_login_success))  //登录成功  主页加载完成
     {
         //登录完成
         //加载用户信息
         User = await UserService.GetCurrentUserInfo();
         if(User != null)
         {
             Hide();
             if ((bool)RemenberMe.IsChecked)
             {
                 SaveLoginInfo();
             }
         }
         else
         {
             Tip.Text = "用户名密码错误!";
             IsPrimaryButtonEnabled = true;
             Logining.Visibility = Visibility.Collapsed;
         }
     }
 }
 /// <summary>
 /// WebView加载完成
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private async void LogintWebView_LoadCompleted(object sender, NavigationEventArgs e)
 {
     if (e.Uri.AbsoluteUri.StartsWith(_login_url)) //登录页面加载完成
     {
         try
         {
             string js = "var o = document.getElementById('LoginCaptcha_CaptchaImage');";
             js += "if(o) o.getAttribute('src');";
             string capt_src = await LogintWebView.InvokeScriptAsync("eval", new string[] { js });
             if (capt_src != null && !capt_src.Equals(""))  //有验证码
             {
                 capt_src = "http://passport.cnblogs.com" + capt_src;
                 CaptchaImg.Source = new BitmapImage { UriSource = new Uri(capt_src) };
                 CaptchaImg.Visibility = Visibility.Visible;
                 CaptchaImg_Input.Visibility = Visibility.Visible;
             }
         }
         finally
         {
             PrimaryButtonText = "登录";
             Logining.IsActive = false;
             IsPrimaryButtonEnabled = true;
         }
     }
     else if (e.Uri.AbsoluteUri.Equals(_login_success))  //登录成功  主页加载完成
     {
         _isChecking = false;
         //登录完成
         //加载用户信息
         User = await UserService.GetCurrentUserInfo();
         if(User != null)
         {
             Hide();
             if ((bool)RemenberMe.IsChecked)
             {
                 SaveLoginInfo();
             }
         }
         else
         {
             Tip.Text = "用户名密码错误!";
             IsPrimaryButtonEnabled = true;
             Logining.Visibility = Visibility.Collapsed;
         }
     }
 }
Example #5
0
        /// <summary>
        /// 获取指定用户信息
        /// </summary>
        /// <param name="blog_app"></param>
        /// <returns></returns>
        public async static Task<CNUserInfo> GetUserInfo(string blog_app)
        {
            try
            {
                string url = string.Format(_url_user_info, blog_app);
                string html = await BaseService.SendGetRequest(url);

                if (html != null)
                {
                    CNUserInfo user = new CNUserInfo();

                    user.GUID = html.Split(new string[] { "var currentUserId = " }, StringSplitOptions.None)[1]
                        .Split(new string[] { "var isLogined = true;" }, StringSplitOptions.None)[0].Trim().Trim(';');

                    string avatar = html.Split(new string[] { "<div class=\"user_avatar\">" }, StringSplitOptions.None)[1]
                        .Split(new string[] { "class=\"img_avatar\">" }, StringSplitOptions.None)[0]
                        .Split(new string[] { "src=\"" }, StringSplitOptions.None)[1]
                        .Split(new string[] { "\" alt=" }, StringSplitOptions.None)[0];

                    user.Avatar = avatar;

                    html = html.Split(new string[] { "<td valign=\"top\">" }, StringSplitOptions.None)[2]
                        .Split(new string[] { "<div class=\"user_intro\">" }, StringSplitOptions.None)[0]
                        .Split(new string[] { "<br>" }, StringSplitOptions.None)[0];

                    html = "<?xml version =\"1.0\" encoding=\"utf - 8\" ?> " + "<result>" + html + "</result>";

                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(html);

                    user.Name = doc.ChildNodes[1].ChildNodes[0].ChildNodes[0].InnerText.Trim();
                    XmlNodeList lis = doc.GetElementsByTagName("li");
                    foreach (XmlNode n in lis)
                    {
                        if (n.ChildNodes.Count == 2)
                        {
                            if (n.ChildNodes[0].InnerText.Contains("园龄"))
                            {
                                user.Age = "园龄 " + n.ChildNodes[1].InnerText;
                            }
                            if (n.ChildNodes[0].InnerText.Contains("博客"))
                            {
                                user.BlogHome = n.ChildNodes[1].InnerText;
                            }
                        }
                    }

                    user.Followees = "关注" + doc.ChildNodes[1].ChildNodes[0].ChildNodes[2].ChildNodes[0].ChildNodes[0].ChildNodes[0].ChildNodes[0].InnerText;

                    user.Followers = "粉丝" + doc.ChildNodes[1].ChildNodes[0].ChildNodes[2].ChildNodes[0].ChildNodes[1].ChildNodes[0].ChildNodes[0].InnerText;

                    user.BlogApp = user.BlogHome.Split('/')[3];

                    return user;
                }
                else
                {
                    return null;
                }
            }
            catch
            {
                return null;
            }
        }
Example #6
0
        /// <summary>
        /// 获取指定用户的关注
        /// </summary>
        /// <param name="blog_app"></param>
        /// <param name="page_index"></param>
        /// <returns></returns>
        public async static Task<List<CNUserInfo>> GetFollowees(string blog_app,int page_index)
        {
            try
            {
                string url = string.Format(_url_user_followees, blog_app, page_index) + "?t=" + DateTime.Now.Millisecond;
                string html = await BaseService.SendGetRequest(url);
                if (html != null)
                {
                    List<CNUserInfo> list_followees = new List<CNUserInfo>();
                    CNUserInfo user;

                    html = html.Split(new string[] { "<div class=\"avatar_list\">" }, StringSplitOptions.None)[1]
                        .Split(new string[] { "<div class=\"clear\"></div>" }, StringSplitOptions.None)[0];
                    html = "<div>" + html.Replace("&amp;", "").Replace("&","");

                    html = "<?xml version =\"1.0\" encoding=\"utf - 8\" ?> " + html.Replace("\"></a>", "\"/></a>");

                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(html);

                    XmlNode ul = doc.ChildNodes[1].ChildNodes[0];

                    foreach (XmlNode node in ul.ChildNodes)
                    {
                        user = new CNUserInfo();

                        user.Avatar = node.ChildNodes[0].ChildNodes[0].ChildNodes[0].Attributes["src"].Value;
                        user.Name = node.ChildNodes[1].ChildNodes[0].InnerText;
                        user.BlogApp = node.ChildNodes[1].ChildNodes[0].Attributes["href"].Value.Split('/')[2];

                        list_followees.Add(user);
                    }

                    return list_followees;
                }
                else
                {
                    return null;
                }
            }
            catch
            {
                return null;
            }
        }