コード例 #1
0
        /// <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)
            {
                _news = parameters[0] as CNNews;

                BlogTitle.Text = _news.Title;
                NewsSource.Text = _news.SourceName;
                PublishTime.Text = _news.PublishTime;
                Diggs.Text = "[" + _news.Diggs + "]";
                Views.Text = _news.Views;
                Comments.Text = _news.Comments;

                string news_content = await NewsService.GetNewsContentAsync(_news.ID);

                if(news_content != null)
                {
                    if (App.Theme == ApplicationTheme.Dark)  //暗主题
                    {
                        news_content += "<style>body{background-color:black;color:white;}</style>";
                    }
                    NewsContent.NavigateToString(news_content);
                }
                Loading.IsActive = false;
            }
        }
コード例 #2
0
        /// <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)
            {
                _news = parameters[0] as CNNews;

                NewsTitle.Text = _news.Title;
                NewsInfo.Text = _news.SourceName + " " + _news.PublishTime;

                _totalHtml = ChatBoxTool.BaseChatHtml;
                if (App.Theme == ApplicationTheme.Dark)
                {
                    _totalHtml += "<style>body{background-color:black;color:white;}</style>";
                }
                NewsComment.NavigateToString(_totalHtml);

                List<CNNewsComment> refresh_comments = await NewsService.GetNewsCommentsAysnc(_news.ID, 1, 200);

                if (refresh_comments != null)
                {
                    string comments = "";
                    foreach (CNNewsComment comment in refresh_comments)
                    {
                        if ((App.LoginedUser != null) && (App.LoginedUser.Name == comment.AuthorName))
                        {
                            comments += ChatBoxTool.Send(comment.AuthorAvatar,
                                comment.AuthorName, comment.Content, comment.PublishTime);
                        }
                        else
                        {
                            comments += ChatBoxTool.Receive(comment.AuthorAvatar,
                            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>";

                    NewsComment.NavigateToString(_totalHtml);
                    Loading.IsActive = false;
                } 
            }
        }
コード例 #3
0
ファイル: NewsService.cs プロジェクト: BourbonShi/CNBlogs.UWP
        static string _url_news_comment = "http://wcf.open.cnblogs.com/news/item/{0}/comments/{1}/{2}";  //news_id page_index page_size

        /// <summary>
        /// 获取首页新闻
        /// </summary>
        /// <param name="page_index"></param>
        /// <param name="page_size"></param>
        /// <returns></returns>
        public async static Task<List<CNNews>> GetRecentNewsAsync(int page_index,int page_size)
        {
            try
            {
                string url = string.Format(_url_recent_news, page_index, page_size);
                string xml = await BaseService.SendGetRequest(url);

                if (xml != null)
                {
                    List<CNNews> list_news = new List<CNNews>();
                    CNNews news;

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

                    XmlNode feed = doc.ChildNodes[1];

                    foreach (XmlNode node in feed.ChildNodes)
                    {
                        if (node.Name.Equals("entry"))
                        {
                            news = new CNNews();
                            foreach (XmlNode node2 in node.ChildNodes)
                            {
                                if (node2.Name.Equals("id"))
                                {
                                    news.ID = node2.InnerText;
                                }
                                if (node2.Name.Equals("title"))
                                {
                                    news.Title = node2.InnerText;
                                }
                                if (node2.Name.Equals("summary"))
                                {
                                    news.Summary = node2.InnerText;
                                }
                                if (node2.Name.Equals("published"))
                                {
                                    DateTime t = DateTime.Parse(node2.InnerText);
                                    news.PublishTime = t.ToString();
                                }
                                if (node2.Name.Equals("updated"))
                                {
                                    news.UpdateTime = node2.InnerText;
                                }
                                if (node2.Name.Equals("link"))
                                {
                                    news.NewsRawUrl = node2.Attributes["href"].Value;
                                }
                                if (node2.Name.Equals("diggs"))
                                {
                                    news.Diggs = node2.InnerText;
                                }
                                if (node2.Name.Equals("views"))
                                {
                                    news.Views = node2.InnerText;
                                }
                                if (node2.Name.Equals("comments"))
                                {
                                    news.Comments = node2.InnerText;
                                }
                                if (node2.Name.Equals("topic"))
                                {
                                    if (node2.HasChildNodes)
                                    {
                                        news.TopicName = node2.InnerText;
                                    }
                                    else
                                    {
                                        news.TopicName = "";
                                    }
                                }
                                if (node2.Name.Equals("topicIcon"))
                                {
                                    if (node2.HasChildNodes)
                                    {
                                        news.TopicIcon = node2.InnerText;
                                    }
                                    else
                                    {
                                        news.TopicIcon = "http://static.cnblogs.com/images/logo_small.gif";
                                    }
                                }
                                if (node2.Name.Equals("sourceName"))
                                {
                                    news.SourceName = node2.InnerText;
                                }
                            }
                            list_news.Add(news);
                        }
                    }
                    return list_news;
                }
                else
                {
                    return null;
                }
            }
            catch
            {
                return null;
            }
        }