Exemplo n.º 1
0
        public async Task <ArticleInformation> DeleteArticle(ArticleInformation info, bool both)
        {
            // HTTP 요청에 딜레이를 주어 서버 오류 방지
            int delay = 50;

            GallogArticleDeleteParameter delParams = null;

            try
            {
                delParams = await this.GetDeleteArticleInfoAsync(info.DeleteUrl);
            }
            catch (Exception e)
            {
                info.IsGalleryDeleted = false;
                info.IsGallogDeleted  = false;
                info.DeleteMessage    = e.Message;

                return(info);
            }

            info.GalleryDeleteParameter = new GalleryArticleDeleteParameter()
            {
                GalleryId = delParams.GalleryId,
                ArticleID = delParams.ArticleId
            };
            info.GallogDeleteParameter = delParams;

            await Task.Delay(delay);

            return(await DeleteArticle(info, GalleryType.Normal, both));
        }
Exemplo n.º 2
0
        internal static async Task <List <T> > GetItemListAsync <T>(string html)
        {
            if (typeof(T) != typeof(ArticleInformation) && typeof(T) != typeof(CommentInformation))
            {
                throw new NotSupportedException();
            }

            return(await Task.Run(async() =>
            {
                HtmlDocument doc = new HtmlDocument();
                doc.LoadHtml(html);

                List <T> itemList = new List <T>();

                if (typeof(T) == typeof(ArticleInformation))
                {
                    foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//img[@src='http://wstatic.dcinside.com/gallery/skin/gallog/icon_01.gif']"))
                    {
                        if (node.Attributes["onClick"] != null)
                        {
                            string title = node.ParentNode.PreviousSibling.PreviousSibling.PreviousSibling.PreviousSibling.InnerText;
                            title = HttpUtility.HtmlDecode(title).Trim();
                            string url = await GetAbsoulteURL(node.Attributes["onClick"].Value);
                            string date = node.ParentNode.InnerText;

                            object nItem = new ArticleInformation(title, date, url);
                            itemList.Add((T)nItem);
                        }
                    }
                }
                else if (typeof(T) == typeof(CommentInformation))
                {
                    foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//table[@bgcolor='#F2F2F5']/tr"))
                    {
                        if (node.Descendants("td").Count() == 6)
                        {
                            string name = node.SelectSingleNode("./td[1]").InnerText;
                            name = HttpUtility.HtmlDecode(name).Trim();
                            string content = HttpUtility.HtmlDecode(node.SelectSingleNode("./td[3]").InnerText);
                            string date = node.SelectSingleNode("./td[5]").InnerText;

                            string url = await GetAbsoulteURL(node.SelectSingleNode("./td[6]/span").Attributes["onClick"].Value);

                            object nItem = new CommentInformation(name, content, date, url);
                            itemList.Add((T)nItem);
                        }
                    }
                }

                return itemList;
            }));
        }
Exemplo n.º 3
0
        public async Task <ArticleInformation> DeleteArticle(ArticleInformation info, GalleryType gallType, bool both)
        {
            // HTTP 요청에 딜레이를 주어 서버 오류 방지
            int delay = 50;

            DeleteResult res1 = null;

            try
            {
                if (LoginInfo.IsLoggedIn)
                {
                    res1 = await PostDeleteGalleryArticleAsync(info.GalleryDeleteParameter, gallType, delay);
                }
                else
                {
                    res1 = await PostDeleteGalleryFlowArticleAsync(info.GalleryDeleteParameter, gallType, delay);
                }
            }
            catch (Exception ex)
            {
                info.IsGalleryDeleted = false;
                info.IsGallogDeleted  = false;
                info.DeleteMessage    = "갤러리의 글을 지우는데 실패하였습니다 - [" + ex.Message + "]";

                return(info);
            }

            if (!res1.Success && res1.ErrorMessage != "이미 삭제된 글입니다.")
            {
                info.IsGalleryDeleted = false;
                info.IsGallogDeleted  = false;
                info.DeleteMessage    = "갤러리의 글을 지우는데 실패하였습니다 - [" + res1.ErrorMessage + "]";

                return(info);
            }

            if (both)
            {
                await Task.Delay(delay);

                DeleteResult res2 = null;

                try
                {
                    res2 = await PostDeleteGallogArticleAsync(info.GallogDeleteParameter, delay);
                }
                catch (Exception ex)
                {
                    info.IsGalleryDeleted = true;
                    info.IsGallogDeleted  = false;
                    info.DeleteMessage    = "갤로그의 글을 지우는데 실패하였습니다 - [" + ex.Message + "]";

                    return(info);
                }

                if (!res2.Success)
                {
                    info.IsGalleryDeleted = true;
                    info.IsGallogDeleted  = false;
                    info.DeleteMessage    = "갤로그의 글을 지우는데 실패하였습니다 - [" + res2.ErrorMessage + "]";

                    return(info);
                }
            }

            info.IsGalleryDeleted = true;
            info.IsGallogDeleted  = true;
            return(info);
        }
Exemplo n.º 4
0
        GetSearchedArticleList(string searchedHtml, string gall_id, string searchNick, GalleryType gallType, bool isFixed, int searchPos)
        {
            return(await Task.Run(() =>
            {
                HtmlDocument doc = new HtmlDocument();
                doc.LoadHtml(searchedHtml);

                int maxPage = 0;

                List <ArticleInformation> searchedList = new List <ArticleInformation>();

                string baseUrl = "http://gall.dcinside.com/";

                HtmlNode pageList = doc.GetElementbyId("dgn_btn_paging");
                if (pageList == null)
                {
                    throw new Exception("알 수 없는 오류입니다.");
                }

                HtmlNode lastChild = pageList.Descendants("a").Last();

                if (lastChild.InnerText != "다음검색")
                {
                    searchPos = -1;
                }
                else
                {
                    string src = lastChild.GetAttributeValue("href", "");
                    if (string.IsNullOrWhiteSpace(src))
                    {
                        throw new Exception("알 수 없는 오류입니다.");
                    }

                    src = baseUrl + src.Substring(1);

                    Uri nextSearchUri = new Uri(src);
                    int.TryParse(HttpUtility.ParseQueryString(nextSearchUri.Query).Get("search_pos"), out searchPos);
                }

                HtmlNode lastPage = pageList.Descendants("span").Where(n => n.GetAttributeValue("class", "") == "arrow_2").FirstOrDefault();
                if (lastPage == null)
                {
                    if (lastChild.InnerText != "다음검색")
                    {
                        int.TryParse(lastChild.InnerText, out maxPage);
                    }
                    else
                    {
                        lastPage = lastChild.PreviousSibling;
                        int.TryParse(lastPage.InnerText, out maxPage);
                    }
                }
                else
                {
                    string src = lastPage.ParentNode.GetAttributeValue("href", "");
                    if (string.IsNullOrWhiteSpace(src))
                    {
                        throw new Exception("알 수 없는 오류입니다.");
                    }

                    src = baseUrl + src.Substring(1);

                    Uri maxPageUri = new Uri(src);
                    int.TryParse(HttpUtility.ParseQueryString(maxPageUri.Query).Get("page"), out maxPage);
                }

                string deleteBasePath = null;

                if (gallType == GalleryType.Normal)
                {
                    deleteBasePath = "http://gall.dcinside.com/mgallery/board/delete/?id=" + gall_id;
                }
                else if (gallType == GalleryType.Minor)
                {
                    deleteBasePath = "http://gall.dcinside.com/board/delete/?id=" + gall_id;
                }

                if (deleteBasePath == null)
                {
                    throw new Exception("예상치 못한 갤러리 형식입니다.");
                }

                foreach (HtmlNode article in doc.DocumentNode.Descendants("tr").Where(n => n.GetAttributeValue("class", "") == "tb"))
                {
                    HtmlNode noticeNode = article.Descendants("td").Where(n => n.GetAttributeValue("class", "") == "t_notice").First();
                    if (noticeNode.InnerText == "공지")
                    {
                        continue;
                    }

                    HtmlNode userNode = article.Descendants("td").Where(n => n.GetAttributeValue("class", "").Contains("t_writer")).First();
                    string user_id = userNode.GetAttributeValue("user_id", "");
                    if (user_id == "" && isFixed)
                    {
                        continue;
                    }
                    else if (user_id != "" && !isFixed)
                    {
                        continue;
                    }

                    string nick = userNode.Descendants("span").First().InnerText;
                    if (nick != searchNick)
                    {
                        continue;
                    }

                    HtmlNode subjectNode = article.Descendants("td").Where(n => n.GetAttributeValue("class", "").Contains("t_subject")).First();

                    string title = subjectNode.InnerText;

                    string articleUrl = subjectNode.Descendants("a").First().GetAttributeValue("href", "");
                    if (string.IsNullOrWhiteSpace(articleUrl))
                    {
                        throw new Exception("알 수 없는 오류입니다.");
                    }

                    articleUrl = baseUrl + articleUrl.Substring(1);

                    Uri subjectUri = new Uri(articleUrl);
                    string articleNo = HttpUtility.ParseQueryString(subjectUri.Query).Get("no");

                    string date, url;
                    date = article.Descendants("td").Where(n => n.GetAttributeValue("class", "").Contains("t_date")).First().InnerText;
                    url = deleteBasePath + "&no=" + articleNo;
                    ArticleInformation info = new ArticleInformation(HttpUtility.HtmlDecode(title), date, url);
                    info.GalleryDeleteParameter = new GalleryArticleDeleteParameter()
                    {
                        GalleryId = gall_id,
                        ArticleID = articleNo
                    };

                    searchedList.Add(info);
                }

                return new Tuple <List <ArticleInformation>, int, int>(searchedList, searchPos, maxPage);
            }));
        }