public bool WriteComment(DCInsideArticle article, string text, CancellationToken ct) { if (article.CommentUserID.Length == 0) { // 한번만 더 시도하고, (이전에 로그인을 안했을 수도 있으므로) string dummyText; if (!GetArticleText(article, ct, out dummyText)) { return(false); } // 그래도 commentUserID를 얻지 못했다면 if (article.CommentUserID.Length == 0) { return(false); } } DCViewWebClient webClient = new DCViewWebClient(); webClient.Headers["Content-Type"] = "application/x-www-form-urlencoded"; webClient.Headers["Referer"] = string.Format("http://m.dcinside.com/view.php?id={0}&no={1}", id, article.ID); string data = string.Format( "id={0}&no={1}&comment_memo={2}&mode=comment&user_no={3}", HttpUtility.UrlEncode(id), HttpUtility.UrlEncode(article.ID), HttpUtility.UrlEncode(text), article.CommentUserID ); var result = webClient.UploadStringAsyncTask(new Uri("http://m.dcinside.com/_option_write.php", UriKind.Absolute), "POST", data, ct).GetResult(); return(true); }
private bool GetCodeAndMobileKey(CancellationToken ct, out string code, out string mobileKey) { code = null; mobileKey = null; // 일단 code와 mobile_key를 얻는다 DCViewWebClient client = new DCViewWebClient(); client.Headers["Referer"] = string.Format("http://m.dcinside.com/list.php?id={0}", id); string response = client.DownloadStringAsyncTask( new Uri("http://m.dcinside.com/write.php?id=windowsphone&mode=write", UriKind.Absolute), ct).GetResult(); StringEngine se = new StringEngine(response); Match match; if (!se.Next(DCRegexManager.WriteCode, out match)) { return(false); } code = match.Groups[1].Value; if (!se.Next(DCRegexManager.WriteMobileKey, out match)) { return(false); } mobileKey = match.Groups[1].Value; return(true); }
public bool GetArticleList(int page, bool bRecommend, CancellationToken ct, out IEnumerable <DCInsideArticle> articles) { // 현재 페이지에 대해서 DCViewWebClient webClient = new DCViewWebClient(); // 접속할 사이트 string url; if (bRecommend) { url = string.Format("http://m.dcinside.com/list.php?id={0}&recommend=1&page={1}&nocache={2}", id, page + 1, DateTime.Now.Ticks); } else { url = string.Format("http://m.dcinside.com/list.php?id={0}&page={1}&nocache={2}", id, page + 1, DateTime.Now.Ticks); } // 페이지를 받고 string result = webClient.DownloadStringAsyncTask(new Uri(url, UriKind.Absolute), ct).GetResult(); // 결과스트링에서 게시물 목록을 뽑아낸다. articles = GetArticleListFromString(result); return(true); }
bool ISite.Refresh(Action <string, int> OnStatusChanged) { try { DCViewWebClient client = new DCViewWebClient(); client.DownloadProgressChanged += (obj, args) => { OnStatusChanged( string.Format("다운로드 중... {0}/{1} ", args.BytesReceived, args.TotalBytesToReceive), (int)(args.ProgressPercentage * 0.8)); }; CancellationTokenSource cts = new CancellationTokenSource(); var result = client.DownloadStringAsyncTask(new Uri("http://m.dcinside.com/category_gall_total.html", UriKind.Absolute), cts.Token).GetResult(); OnStatusChanged("결과 분석중입니다", 80); Regex regex = new Regex("<a href=\"http://m\\.dcinside\\.com/list\\.php\\?id=(\\w+)\">([^<]+)((</a>)|(<div class='icon_19'></div></a>))"); var results = from match in regex.Matches(result).OfType <Match>() let id = match.Groups[1].Value let name = match.Groups[2].Value let adult = (match.Groups[5].Value != String.Empty) where !adult select new DCInsideBoard(this, id, name); OnStatusChanged("리스트를 저장합니다", 90); // 3. 변경된 내용을 파일에 저장하면서 갤러리 초기화 boards.Clear(); var storage = IsolatedStorageFile.GetUserStoreForApplication(); using (var writer = new StreamWriter(storage.OpenFile("/DCView_list.txt", FileMode.Create))) { foreach (DCInsideBoard board in results) { writer.WriteLine(board.ID); writer.WriteLine(board.Name); writer.WriteLine(0); // Adult 인지 여부인데.. 없죠 boards.Add(board); } } } catch { return(false); } return(true); }
public static string Update() { try { var settings = IsolatedStorageSettings.ApplicationSettings; DCViewWebClient client = new DCViewWebClient(); // 버전 확인 var verString = client.DownloadStringAsyncTask(new Uri( string.Format("http://ioklo.byus.net/dcview/pattern_version.txt?nocache={0}", DateTime.Now.Ticks), UriKind.Absolute), new CancellationTokenSource().Token).GetResult(); var reader = new StringReader(verString); int updateVer = int.Parse(reader.ReadLine()); int localVer; if (!settings.TryGetValue("dcview.pattern_version", out localVer)) { return("실패 - 패턴 버전을 가져올 수 없습니다"); } // 현재 버전이 더 높으면 업데이트 안함 if (updateVer <= localVer) { return("지금 패턴이 최신입니다"); } client = new DCViewWebClient(); var result = client.DownloadStringAsyncTask(new Uri( string.Format("http://ioklo.byus.net/dcview/pattern_dc.txt?nocache={0}", DateTime.Now.Ticks), UriKind.Absolute), new CancellationTokenSource().Token).GetResult(); var storage = IsolatedStorageFile.GetUserStoreForApplication(); using (var writer = new StreamWriter(storage.OpenFile("/pattern_dc.txt", FileMode.Create), Encoding.UTF8)) { writer.Write(result); } // 업데이트가 잘 끝나면 버전 기록 settings["dcview.pattern_version"] = updateVer; settings.Save(); // 로딩 Load(); return("패턴이 업데이트 되었습니다"); } catch { Reset(); return("실패 - 패턴을 처음 상태로 되돌립니다"); } }
public bool WriteCommentNonmember(DCInsideArticle article, string text, CancellationToken ct) { DCViewWebClient webClient = new DCViewWebClient(); webClient.Headers["Content-Type"] = "application/x-www-form-urlencoded"; webClient.Headers["Referer"] = string.Format("http://m.dcinside.com/view.php?id={0}&no={1}", id, article.ID); string data = string.Format( "id={0}&no={1}&comment_nick={2}&comment_pw={3}&comment_memo={4}&mode=comment_nonmember", HttpUtility.UrlEncode(id), HttpUtility.UrlEncode(article.ID), HttpUtility.UrlEncode("testid"), HttpUtility.UrlEncode("testpw"), HttpUtility.UrlEncode(text) ); webClient.UploadStringAsyncTask(new Uri("http://m.dcinside.com/_option_write.php", UriKind.Absolute), "POST", data, ct).GetResult(); return(true); }
public bool GetArticleText(DCInsideArticle article, CancellationToken ct, out string text) { DCViewWebClient webClient = new DCViewWebClient(); string url = string.Format("http://m.dcinside.com/view.php?id={0}&no={1}&nocache={2}", id, article.ID, DateTime.Now.Ticks); string result = webClient.DownloadStringAsyncTask(new Uri(url, UriKind.Absolute), ct).GetResult(); List <Picture> pictures; List <DCInsideComment> comments; string commentUserID; if (!UpdateArticleTextAndComments(result, out pictures, out comments, out commentUserID, out text)) { return(false); // 파싱 에러 } article.Pictures = pictures; article.CachedComments = comments; article.CommentUserID = commentUserID; return(true); }
public bool GetArticleList(CancellationToken ct, out IEnumerable <DCInsideArticle> articles) { // 현재 페이지에 대해서 DCViewWebClient webClient = new DCViewWebClient(); string serposStr = serpos != 0 ? serpos.ToString() : string.Empty; // 접속할 사이트 string url = string.Format("http://m.dcinside.com/list.php?id={0}&page={1}&serVal={2}&s_type={3}&ser_pos={4}&nocache={5}", board.ID, page + 1, searchText, GetSearchTypeText(searchType), serposStr, DateTime.Now.Ticks); // 페이지를 받고 string result = webClient.DownloadStringAsyncTask(new Uri(url, UriKind.Absolute), ct).GetResult(); // 결과스트링에서 게시물 목록을 뽑아낸다. articles = GetArticleListFromString(result); // 마지막 리스트였다면 int nextSearchPos; if (IsLastSearch(result, out nextSearchPos)) { page = 0; serpos = nextSearchPos; } else { // 페이지 하나 증가시키고 page++; } return(true); }
private async Task <bool> DoLogin(CancellationToken token) { Status = LoginStatus.MemberConnecting; DCViewWebClient client = new DCViewWebClient(); client.Headers["Content-Type"] = "application/x-www-form-urlencoded"; client.Headers["Referer"] = "http://m.dcinside.com/login.php?r_url=%2F"; string data = string.Format( "user_id={0}&user_pw={1}&r_url=%2F", HttpUtility.UrlEncode(MemberID), HttpUtility.UrlEncode(MemberPassword)); try { string result = await client.UploadStringAsyncTask(new Uri("http://dcid.dcinside.com/join/mobile_login_ok.php", UriKind.Absolute), "POST", data, token); var cookies = DCViewWebClient.CookieContainer.GetCookies(new Uri("http://gall.dcinside.com")); if (result.IndexOf("parent.location.href='http://m.dcinside.com/'") == -1) { Status = LoginStatus.MemberNoLogin; return(false); } else { Status = LoginStatus.MemberLogin; return(true); } } catch { Status = LoginStatus.MemberNoLogin; } return(false); }
public void Logout() { Status = LoginStatus.MemberNoLogin; DCViewWebClient.ResetCookie(); // 쿠키값 리셋 }