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)); }
internal static async Task <GallogArticleDeleteParameter> GetDeleteGallogArticleParameterAsync(string pageHtml) { return(await Task.Run(() => { GallogArticleDeleteParameter newParams = new GallogArticleDeleteParameter(); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(pageHtml); HtmlNode parentNode = doc.GetElementbyId("dTp").ParentNode; HtmlNode gallNode = parentNode.SelectSingleNode(".//input[@name='id']"); HtmlNode cidNode = parentNode.SelectSingleNode(".//input[@name='cid']"); HtmlNode artNode = parentNode.SelectSingleNode(".//input[@name='pno']"); HtmlNode logNode = parentNode.SelectSingleNode(".//input[@name='logNo']"); HtmlNode dcc_keyNode = doc.DocumentNode.SelectSingleNode("//input[@name='dcc_key']"); int inputCnt = doc.DocumentNode.Descendants("input").Count(); HtmlNode randomKeyNode = doc.DocumentNode.SelectSingleNode("//input[" + (inputCnt - 1) + "]"); newParams.GalleryId = gallNode.Attributes["value"].Value; newParams.GalleryNo = cidNode.Attributes["value"].Value; newParams.ArticleId = artNode.Attributes["value"].Value; newParams.LogNo = logNode.Attributes["value"].Value; newParams.DCCKey = dcc_keyNode.Attributes["value"].Value; newParams.AdditionalParameter.Push(randomKeyNode.Attributes["name"].Value, randomKeyNode.Attributes["value"].Value); return newParams; })); }
private async Task <GallogArticleDeleteParameter> GetDeleteArticleInfoAsync(string url) { string galHtml = await GetDeleteGallogArticlePageAsync(url, user_id); GallogArticleDeleteParameter retParams = await HtmlParser.GetDeleteGallogArticleParameterAsync(galHtml); retParams.UserId = user_id; return(retParams); }
private async Task <DeleteResult> PostDeleteGallogArticleAsync(GallogArticleDeleteParameter param, int delay) { string reqURL = _gallogURL + "/inc/_deleteArticle.php"; string referer = _gallogURL + "/inc/_deleteLog.php?gid=" + param.UserId; using (HttpClientHandler handler = new HttpClientHandler() { CookieContainer = cookies }) using (HttpClient client = new HttpClient(handler)) { client.DefaultRequestHeaders.Accept.ParseAdd(_defaultAcceptString); client.DefaultRequestHeaders.Referrer = new Uri(referer); client.DefaultRequestHeaders.UserAgent.ParseAdd(_userAgent); client.Timeout = new TimeSpan(0, 0, 0, 0, _defaultTimeout); string reqData = "rb=&dTp=1&gid=" + param.UserId + "&cid=" + param.GalleryNo + "&pno=" + param.ArticleId + "&no=" + param.ArticleId + "&logNo=" + param.LogNo + "&id=" + param.GalleryId + "&nate=&dcc_key=" + param.DCCKey + (param.AdditionalParameter["dcc_key"] != null ? "" : ("&" + param.AdditionalParameter.ToString())); using (HttpResponseMessage res = await client.PostAsync(reqURL, new StringContent(reqData, Encoding.UTF8, "application/x-www-form-urlencoded"))) { res.EnsureSuccessStatusCode(); using (HttpContent content = res.Content) { string result = await content.ReadAsStringAsync(); // 성공 또는 이미 삭제된 경우 if (result.Contains("GidMgr.resetGalleryData(2);") || result.Contains("해당정보가 없습니다")) { return(new DeleteResult(true, "")); } else { return(new DeleteResult(false, "알 수 없는 오류입니다.")); } } } } }