/// <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)
            {
                if(parameters.Length==1 && (parameters[0] as CNBlog)!=null)
                {
                    _blog = parameters[0] as CNBlog;

                    BlogTitle.Text = _blog.Title;
                    AuthorName.Content = _blog.AuthorName;
                    PublishTime.Text = _blog.PublishTime;
                    Views.Text = _blog.Views;
                    Diggs.Text = "["+_blog.Diggs + "]";
                    Comments.Text = _blog.Comments;
                    BitmapImage bi = new BitmapImage { UriSource = new Uri(_blog.AuthorAvator) };
                    Avatar.Source = bi;
                    AuthorName.Tag = _blog.BlogApp;
                    string blog_body = await BlogService.GetBlogContentAsync(_blog.ID);
                    if (blog_body != null)
                    {
                        if (App.Theme == ApplicationTheme.Dark)  //暗主题
                        {
                            blog_body += "<style>body{background-color:black;color:white;}</style>";
                        }
                        BlogContent.NavigateToString(blog_body);
                    }
                    Loading.IsActive = false;
                }
            }
        }
        /// <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)
            {
                _blog = parameters[0] as CNBlog;
                BlogTitle.Text = _blog.Title;
                Author.Content = _blog.AuthorName;
                PubishTime.Text = _blog.PublishTime;

                _totalHtml = ChatBoxTool.BaseChatHtml;
                if (App.Theme == ApplicationTheme.Dark)
                {
                    _totalHtml += "<style>body{background-color:black;color:white;}</style>";
                }
                BlogComment.NavigateToString(_totalHtml);
                List<CNBlogComment> list_comments = await BlogService.GetBlogCommentsAsync(_blog.ID, 1, 199);

                if(list_comments != null)
                {
                    string comments = "";
                    foreach(CNBlogComment comment in list_comments)
                    {
                        if ((App.LoginedUser != null)&&(comment.AuthorName == App.LoginedUser.Name))
                        {
                            comments += ChatBoxTool.Send(comment.AuthorAvatar,
                                comment.AuthorName == _blog.AuthorName ? "[博主]" + _blog.AuthorName : comment.AuthorName,
                                comment.Content, comment.PublishTime);
                        }
                        else
                        {
                            comments += ChatBoxTool.Receive(comment.AuthorAvatar,
                                comment.AuthorName == _blog.AuthorName ? "[博主]" + _blog.AuthorName : comment.AuthorName,
                                comment.Content, comment.PublishTime, comment.ID);
                        }
                    }
                    //comments += "<a id='ok'></a>";

                    _totalHtml = _totalHtml.Replace("<a id='ok'></a>", "") + comments + "<a id='ok'></a>";
                    BlogComment.NavigateToString(_totalHtml);
                    Loading.IsActive = false;
                }
            }
        }
Example #3
0
        static string _url_search_blogs = "http://zzk.cnblogs.com/s?w={0}&t=b&p={1}";  //blog_keywords page_index

        /// <summary>
        /// 搜索博客
        /// </summary>
        /// <param name="keywords"></param>
        /// <param name="page_index"></param>
        /// <returns></returns>
        public async static Task<List<CNBlog>> SearchBlogs(string keywords,int page_index)
        {
            try
            {
                string url = string.Format(_url_search_blogs, keywords, page_index);
                string html = await BaseService.SendGetRequest(url);

                if (html != null)
                {
                    html = html.Split(new string[] { "<div class=\"forflow\">" }, StringSplitOptions.None)[1]
                        .Split(new string[] { "<div class=\"forflow\" id=\"sidebar\">" },StringSplitOptions.None)[0]
                        .Split(new string[] {"<div id=\"paging_block\""},StringSplitOptions.None)[0];
                    html = "<?xml version=\"1.0\" encoding=\"utf - 8\" ?> " + "<result>" + html + "</result>";
                    List<CNBlog> list_blogs = new List<CNBlog>();
                    CNBlog blog;

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

                    XmlNode search_items = doc.ChildNodes[1];
                    if (search_items != null)
                    {
                        foreach (XmlNode node in search_items.ChildNodes)
                        {
                            blog = new CNBlog();
                            blog.Title = node.ChildNodes[0].InnerText;
                            blog.Summary = node.ChildNodes[2].InnerText;
                            blog.AuthorName = node.ChildNodes[4].ChildNodes[0].InnerText;
                            blog.AuthorHome = node.ChildNodes[4].ChildNodes[0].ChildNodes[0].Attributes["href"].Value;
                            blog.BlogApp = blog.AuthorHome.Split('/')[3];
                            blog.PublishTime = node.ChildNodes[4].ChildNodes[1].InnerText;
                            if(node.ChildNodes[4].ChildNodes[2]!=null)
                            {
                                if(node.ChildNodes[4].ChildNodes[2].InnerText.Contains("推荐"))
                                {
                                    blog.Diggs = node.ChildNodes[4].ChildNodes[2].InnerText.Split('(')[1].TrimEnd(')');
                                }
                                if (node.ChildNodes[4].ChildNodes[2].InnerText.Contains("评论"))
                                {
                                    blog.Comments = "[" + node.ChildNodes[4].ChildNodes[2].InnerText.Split('(')[1].TrimEnd(')') + "]";
                                }
                                if(node.ChildNodes[4].ChildNodes[2].InnerText.Contains("浏览"))
                                {
                                    blog.Views = "[" + node.ChildNodes[4].ChildNodes[2].InnerText.Split('(')[1].TrimEnd(')') + "]";
                                }
                            }
                            if (node.ChildNodes[4].ChildNodes[3] != null)
                            {
                                if (node.ChildNodes[4].ChildNodes[3].InnerText.Contains("推荐"))
                                {
                                    blog.Diggs = node.ChildNodes[4].ChildNodes[3].InnerText.Split('(')[1].TrimEnd(')');
                                }
                                if (node.ChildNodes[4].ChildNodes[3].InnerText.Contains("评论"))
                                {
                                    blog.Comments = "[" + node.ChildNodes[4].ChildNodes[3].InnerText.Split('(')[1].TrimEnd(')') + "]";
                                }
                                if (node.ChildNodes[4].ChildNodes[3].InnerText.Contains("浏览"))
                                {
                                    blog.Views = "[" + node.ChildNodes[4].ChildNodes[3].InnerText.Split('(')[1].TrimEnd(')') + "]";
                                }
                            }
                            if (node.ChildNodes[4].ChildNodes[4] != null)
                            {
                                if (node.ChildNodes[4].ChildNodes[4].InnerText.Contains("推荐"))
                                {
                                    blog.Diggs = node.ChildNodes[4].ChildNodes[4].InnerText.Split('(')[1].TrimEnd(')');
                                }
                                if (node.ChildNodes[4].ChildNodes[4].InnerText.Contains("评论"))
                                {
                                    blog.Comments = "[" + node.ChildNodes[4].ChildNodes[4].InnerText.Split('(')[1].TrimEnd(')') + "]";
                                }
                                if (node.ChildNodes[4].ChildNodes[4].InnerText.Contains("浏览"))
                                {
                                    blog.Views = "[" + node.ChildNodes[4].ChildNodes[4].InnerText.Split('(')[1].TrimEnd(')') + "]";
                                }
                            }
                            blog.BlogRawUrl = node.ChildNodes[5].InnerText;
                            blog.AuthorAvator = "http://pic.cnblogs.com/avatar/simple_avatar.gif";

                            string[] strs = blog.BlogRawUrl.Split('/');
                            blog.ID = strs[strs.Length - 1].Split('.')[0];

                            if (blog.Diggs == null)
                            {
                                blog.Diggs = "0";
                            }
                            if (blog.Comments == null)
                            {
                                blog.Comments = "[0]";
                            }
                            list_blogs.Add(blog);
                        }
                    }
                    return list_blogs;
                }
                else
                {
                    return null;
                }
            }
            catch
            {
                return null;
            }
        }
Example #4
0
        /// <summary>
        /// 十天推荐榜
        /// </summary>
        /// <param name="item_count"></param>
        /// <returns></returns>
        public async static Task<List<CNBlog>> Get10TopDiggsAysnc(int item_count)
        {
            try
            {
                string url = string.Format(_url_10_diggs, item_count);
                string xml = await BaseService.SendGetRequest(url);

                if (xml != null)
                {
                    List<CNBlog> list_blogs = new List<CNBlog>();
                    CNBlog cnblog;
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(xml);
                    XmlNode feed = doc.ChildNodes[1];
                    foreach (XmlNode node in feed.ChildNodes)
                    {
                        if (node.Name.Equals("entry"))
                        {
                            cnblog = new CNBlog();
                            foreach (XmlNode node2 in node.ChildNodes)
                            {
                                if (node2.Name.Equals("id"))
                                {
                                    cnblog.ID = node2.InnerText;
                                }
                                if (node2.Name.Equals("title"))
                                {
                                    cnblog.Title = node2.InnerText;
                                }
                                if (node2.Name.Equals("summary"))
                                {
                                    cnblog.Summary = node2.InnerText + "...";
                                }
                                if (node2.Name.Equals("published"))
                                {
                                    DateTime t = DateTime.Parse(node2.InnerText);
                                    cnblog.PublishTime = "发表于 " + t.ToString();
                                }
                                if (node2.Name.Equals("updated"))
                                {
                                    cnblog.UpdateTime = node2.InnerText;
                                }
                                if (node2.Name.Equals("author"))
                                {
                                    cnblog.AuthorName = node2.ChildNodes[0].InnerText;
                                    cnblog.AuthorHome = node2.ChildNodes[1].InnerText;
                                    if (node2.ChildNodes.Count == 3)
                                    {
                                        cnblog.AuthorAvator = node2.ChildNodes[2].InnerText.Equals("") ? "http://pic.cnblogs.com/avatar/simple_avatar.gif" : node2.ChildNodes[2].InnerText;
                                    }
                                    else
                                    {
                                        cnblog.AuthorAvator = "http://pic.cnblogs.com/avatar/simple_avatar.gif";
                                    }
                                }
                                if (node2.Name.Equals("link"))
                                {
                                    cnblog.BlogRawUrl = node2.Attributes["href"].Value;
                                }
                                if (node2.Name.Equals("diggs"))
                                {
                                    cnblog.Diggs = node2.InnerText;
                                }
                                if (node2.Name.Equals("views"))
                                {
                                    cnblog.Views = "[" + node2.InnerText + "]";
                                }
                                if (node2.Name.Equals("comments"))
                                {
                                    cnblog.Comments = "[" + node2.InnerText + "]";
                                }
                            }
                            cnblog.BlogApp = cnblog.AuthorHome.Split('/')[3];
                            list_blogs.Add(cnblog);
                        }
                    }
                    return list_blogs;
                }
                else
                {
                    return null;
                }
            }
            catch
            {
                return null;
            }
        }