Пример #1
0
 public static Blogger Load(XElement element, int index)
 {
     if (element == null) throw new ArgumentNullException("element");
     Blogger blogger = new Blogger();
     blogger.Index = index;
     //blogger.Id = element.Element("id")?.Value;
     blogger.Name = element.Element("title")?.Value;
     blogger.Updated = Convert.ToDateTime(element?.Element("updated")?.Value);
     blogger.BloggerHome = element?.Element("link")?.Attribute("href")?.Value;
     blogger.BlogApp = element.Element("blogapp")?.Value;
     blogger.IconName = element?.Element("avatar")?.Value;
     if (blogger.IconName.IsNullOrEmpty()) blogger.IconName = Configuration.DefalutImagePath;
     blogger.PostCount = Convert.ToInt32(element?.Element("postcount")?.Value);
     blogger.IsRecomment = true;
     return blogger;
 }
Пример #2
0
        public static Blogger Load(XElement element, int index)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }
            Blogger blogger = new Blogger();

            blogger.Index = index;
            //blogger.Id = element.Element("id")?.Value;
            blogger.Name        = element.Element("title")?.Value;
            blogger.Updated     = Convert.ToDateTime(element?.Element("updated")?.Value);
            blogger.BloggerHome = element?.Element("link")?.Attribute("href")?.Value;
            blogger.BlogApp     = element.Element("blogapp")?.Value;
            blogger.IconName    = element?.Element("avatar")?.Value;
            if (blogger.IconName.IsNullOrEmpty())
            {
                blogger.IconName = Configuration.DefalutImagePath;
            }
            blogger.PostCount   = Convert.ToInt32(element?.Element("postcount")?.Value);
            blogger.IsRecomment = true;
            return(blogger);
        }
Пример #3
0
 public LoginUserInfo()
 {
     Cookies = new CookieCollection();
     Blogger = new Blogger();
 }
Пример #4
0
        public async static Task<Blogger> LoadCurrentUserBlogAppAsync()
        {
            try
            {
                string url = string.Format(WcfApiUrlConstants.CurrentUserBlogApp);
                string html = await HttpHelper.GetAsync(url);
                Match match = Regex.Match(html, @"<a\shref\=\""/u/([^\/]+)");//匹配<a href="/u/开始的串,后面即位blogpp,<a href="/u/Jack-Blog/"
                if (!match.Success) return null;
                Blogger blogger = new Blogger();
                blogger.BlogApp = match.Groups[1].Value;
                match = Regex.Match(html, @"<img.*?src=(['""]?)(?<url>[^'"" ]+)(?=\1)[^>]*>");//匹配<a href="/u/开始的串,后面即位blogpp,<a href="/u/Jack-Blog/"
                if (match.Success)
                {
                    blogger.IconName = match.Groups["url"].Value;
                    if (blogger.IconName.StartsWith("//"))
                    {
                        blogger.IconName = "http://" + blogger.IconName.TrimStart('/');
                    }
                };
                return blogger;
                #region sample
                /// < h1 id = "header_user_left" >
                //         欢迎你,杰哥很忙
                // </ h1 >

                // < div id = "header_user_right" >

                //          < a href = "/u/Jack-Blog/" >< img class="pfs" src="//pic.cnblogs.com/face/sample_face.gif" alt=""
                ///></a>
                //        <a href = "/u/Jack-Blog/" > 杰哥很忙 </ a >
                //            · <a href = "http://www.cnblogs.com/Jack-Blog/" > 我的博客 </ a >
                //        · <a href = "//home.cnblogs.com/set/account/" > 设置 </ a >
                //        · <a href = "javascript:void;" onclick="return logout();">退出</a>
                //</div>
                #endregion
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.WriteLine(exception.Message);
                return null;
            }
        }
Пример #5
0
 public static async Task<Blogger> LoadCurrentUserInfoAsync(string blogApp)
 {
     try
     {
         string url = string.Format(WcfApiUrlConstants.UserInfo, blogApp);
         string html = await HttpHelper.GetAsync(url);
         //获取名字,注册时间,粉丝数,关注数
         Match match = Regex.Match(html, @"昵称:<a[\s\S]+?>([\S\s]*?)</a>");//匹配<a href="/u/开始的串,后面即位blogpp,<a href="/u/Jack-Blog/"
         Blogger blogger = new Blogger();
         if (match.Success)
         {
             blogger.Name = match.Groups[1].Value;
         }
         match = Regex.Match(html, "时间:(.*?)\"");
         if (match.Success)
         {
             blogger.RegiestDate = DateTime.ParseExact(match.Groups[1].Value, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture);
         }
         match = Regex.Match(html, @"荣誉:<a[\s\S]+?>([\S\s]*?)</a>");
         if (match.Success)
         {
             if (match.Groups[1].Value == "推荐博客")
             {
                 blogger.IsRecomment = true;
             }
         }
         match = Regex.Match(html, @"followers/"">([\S\s]*?)</a>");
         if (match.Success)
         {
             blogger.FollowerAmount = Convert.ToInt32(match.Groups[1].Value);
         }
         match = Regex.Match(html, @"followees/"">([\S\s]*?)</a>");
         if (match.Success)
         {
             blogger.FolloweeAmount = Convert.ToInt32(match.Groups[1].Value);
         }
         //获取guid
         match = Regex.Match(html, @"\('([^\'].*?)'\)");//匹配('b5f14557-3d97-e411-b908-9dcfd8948a71')以('开始的串')结束的串
         if (match.Success)
         {
             blogger.Guid = match.Groups[1].Value;
         }
         return blogger;
         #region sample
         /// <div id="profile_block">昵称:<a href="http://home.cnblogs.com/u/Mangues/">mangues</a><br/>园龄:<a href="http
         //://home.cnblogs.com/u/Mangues/" title="入园时间:2015-01-08">1年9个月</a><br/>粉丝:<a href="http://home.cnblogs
         //.com/u/Mangues/followers/">4</a><br/>关注:<a href="http://home.cnblogs.com/u/Mangues/followees/">1</a>
         //<div id = "p_b_follow" ></ div >< script > getFollowStatus('b5f14557-3d97-e411-b908-9dcfd8948a71') </ script ><
         // div >
         #endregion
     }
     catch (Exception exception)
     {
         System.Diagnostics.Debug.WriteLine(exception.Message);
         return null;
     }
 }
Пример #6
0
 public void UpdateLoginBlogger(Blogger blogger)
 {
     LoginUserInfo.Blogger = blogger;
     ApplicationDataCompositeValue composite;
     if (!_setting.GetSetting(nameof(LoginUserInfo), out composite))
     {
         composite = new ApplicationDataCompositeValue();
     }
     composite[nameof(LoginUserInfo.Blogger.BlogApp)] = LoginUserInfo.Blogger.BlogApp;
     composite[nameof(LoginUserInfo.Blogger.Guid)] = LoginUserInfo.Blogger.Guid;
     _setting.SetSetting(nameof(LoginUserInfo), composite);
 }