Exemplo n.º 1
0
        public ArticleWindow(Article art)
        {
            InitializeComponent();
            this.Title = art.Title + " - DC 뷰어";
            this.Owner = MainWindow.Instance;

            art.GetArticleContent();

            tb_title.Text = art.Title;
            tb_writer.Text = art.Writer.UserName;
            wb_content.NavigateToString("<html lang=\"ko\"><head><meta charset=\"UTF-8\"></head><body>" + art.Content + "</body></html>");
            wb_content.Navigated += Wb_content_Navigated;
        }
Exemplo n.º 2
0
        private static Article FindArticle(Article[] list, string num)
        {
            try {
                foreach (Article art in list)
                {
                    if (art.ArticleID == int.Parse(num))
                    {
                        return art;
                    }
                }
            }
            catch
            {

            }

            return null;
        }
Exemplo n.º 3
0
        /// <summary>
        /// 현재 페이지의 글 목록을 반환합니다.
        /// </summary>
        /// <param name="parent">부모 DCInside 객체</param>
        /// <param name="doc">파싱된 HTML 소스를 가진 HtmlDocument 객체</param>
        /// <param name="gallInfo">현재 갤러리의 정보를 가진 GalleryInfo 객체</param>
        /// <returns></returns>
        private static List<Article> BuildArticleList(DCInside parent, HtmlDocument doc, GalleryInfo gallInfo)
        {
            List<Article> articles = new List<Article>();

            // 페이지 내부에 Table 요소는 하나뿐 이므로 하위의 TR만 가져온다. (tr중 class를 포함하지 않으면 테이블 헤더)
            foreach(HtmlNode trow in doc.DocumentNode.SelectNodes("//table//tr").Where(x => x.GetAttributeValue("class", "") == "tb"))
            {
                bool isNotice = false;  // 공지 여부
                int articleId = -1;     // 글 ID
                bool hasPic = false;    // 이미지 있는 글인지 여부
                bool isRec = false;     // 개념글 여부
                UserInfo userInfo = null;   // 사용자 정보 객체
                string title = "";      // 글 제목
                string date = "";       // 글 작성일
                int viewCnt = -1;       // 조회 수
                int commentCnt = 0;     // 댓글 수
                int recommendCnt = -1;  // 추천 수
                
                foreach(HtmlNode td in trow.Descendants("td"))
                {
                    if (isNotice)
                        continue;

                    switch(td.GetAttributeValue("class", "")){
                        case "t_notice":
                            if (td.InnerText != "공지")
                                articleId = int.Parse(td.InnerText);
                            else
                                isNotice = true;
                            break;
                        case "t_subject":
                            foreach(HtmlNode subjectNode in td.Descendants("a").Where(x=>x.GetAttributeValue("class", "") != ""))
                            {
                                title = HttpUtility.HtmlDecode(subjectNode.InnerText);

                                if(subjectNode.GetAttributeValue("class", "") == "icon_pic_n")
                                {
                                    hasPic = true;
                                    isRec = false;
                                }
                                else if(subjectNode.GetAttributeValue("class", "") == "icon_pic_b")
                                {
                                    hasPic = true;
                                    isRec = true;
                                }
                                else if (subjectNode.GetAttributeValue("class", "") == "icon_txt_n")
                                {
                                    hasPic = false;
                                    isRec = false;
                                }
                                else
                                {
                                    hasPic = true;
                                    isRec = true;
                                }
                            }
                            break;
                        case "t_date":
                            date = td.GetAttributeValue("title", "");
                            break;
                        case "t_hits":
                            if (viewCnt < 0)
                            {
                                viewCnt = int.Parse(td.InnerText);
                            }
                            else
                            {
                                recommendCnt = int.Parse(td.InnerText);
                            }
                            break; // 2016-02-12
                        case "t_writer user_layer":
                            string userid = td.GetAttributeValue("user_id", "");
                            if(userid == "") //유동
                            {
                                string user_name = td.GetAttributeValue("user_name", "");
                                userInfo = new UserInfo(user_name);
                            }
                            else // 고닉
                            {
                                HtmlNode imgNode = td.SelectNodes(".//img")[0];
                                string src = imgNode.GetAttributeValue("src", "");
                                string user_name = td.GetAttributeValue("user_name", "").Replace("\u8203", "");
                                string gallogLink = ExtractGallogURL(imgNode.GetAttributeValue("onClick", ""));
                                if (src.Contains("g_default")) // 유동고닉
                                {
                                    userInfo = new UserInfo(user_name, userid, false, gallogLink);
                                }
                                else // 고정닉
                                {
                                    userInfo = new UserInfo(user_name, userid, true, gallogLink);
                                }
                            }
                            break;
                    }
                }

                // 댓글 수를 가져오는 함수
                foreach(HtmlNode em in trow.Descendants("em"))
                {
                    var commentTxt = em.InnerText.Replace("[", "").Replace("]", "");
                    commentTxt = commentTxt.Substring(0, commentTxt.IndexOf("/") == -1 ? commentTxt.Length : commentTxt.IndexOf("/"));
                    commentCnt = int.Parse(commentTxt);
                }

                if (articleId == -1)
                    continue;

                // 새 글 객체를 생성한 후 배열에 넣는다
                Article art = new Article(parent, gallInfo, articleId, hasPic, isRec, title, commentCnt, userInfo, date, viewCnt, recommendCnt);

                articles.Add(art);
            }

            return articles;
        }