Exemple #1
0
        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);
        }
Exemple #2
0
        private async Task OnCarOptionSelected(IDialogContext context, IAwaitable<string> result)
        {
            try
            {
                
                string optionSelected = await result; // одна из машин
                string carNumber = StringEngine.ExtractFromBrackets(optionSelected);
                //await context.PostAsync(optionSelected);
                await context.PostAsync("Дата ТО - " + Convert.ToString(Querys.GetTIDate(carNumber)));
                context.Done<object>(null);
                //context.Call(new RootDialog(), this.ResumeAfterOptionDialog);
                //switch (optionSelected)
                //{

                //    //case result[0]:
                //    //    context.Call(new CarDialog(), this.ResumeAfterOptionDialog);
                //    //    break;

                //    //case CallMaster:
                //    //    context.Call(new MasterDialog(), this.ResumeAfterOptionDialog);
                //    //    break;
                //}
            }
            catch (TooManyAttemptsException ex)
            {
                await context.PostAsync($"Упс! Слишком много попыток :( Но не волнуйтесь, я обрабатываю это исключение, и вы можете попробовать еще раз!" + ex);

                //context.Wait(this.MessageReceivedAsync);
            }
        }
Exemple #3
0
 private async Task GetCarInfo(IDialogContext context)
 {
     string carNumber = StringEngine.ExtractFromBrackets(Querys.GetCarByChatId(RootDialog.chatId));
     //await context.PostAsync(optionSelected);
     await context.PostAsync("Дата ТО - " + Convert.ToString(Querys.GetTIDate(carNumber)));
     context.Done<object>(null);
 }
Exemple #4
0
        /// <summary>
        /// Gets the round.
        /// </summary>
        /// <param name="location">The location.</param>
        /// <returns></returns>
        private async Task <Round> GetRound(string location)
        {
            if (_disposing)
            {
                return(null);
            }

            LilaRequest roundReq = new LilaRequest(new Uri(location, UriKind.Relative), Culture);

            roundReq.Cookies.Add(lobbyCon.GetCookies());
            if (anonymous)
            {
                roundReq.Cookies.Add(new Cookie("rk2", location.Substring(9), "/", "lichess.org")); //add anoncookie
            }

            LilaResponse roundRes = await roundReq.Get(LilaRequest.ContentType.Html);

            if (roundRes == null)
            {
                log.Error("Failed to join round at {0}", location);
                return(null);
            }

            string html = await roundRes.ReadAsync();

            const string id = "LichessRound.boot(";

            int roundBootIndex = html.IndexOf(id);

            if (roundBootIndex == -1)
            {
                return(null);
            }

            string json = StringEngine.GetInside(html, roundBootIndex + id.Length);

            if (json == null)
            {
                log.Error("Failed to parse game json data.");
                return(null);
            }

            return(JsonConvert.DeserializeObject <Round>(json, jsonSettings));
        }
Exemple #5
0
        /// <summary>
        /// Gets the tournament.
        /// </summary>
        /// <param name="tournamentId">The tournament identifier.</param>
        /// <returns></returns>
        private async Task <Tournament> GetTournament(string tournamentId)
        {
            if (_disposing)
            {
                return(null);
            }

            LilaRequest tournamentReq = new LilaRequest(new Uri(string.Format("/tournament/{0}", tournamentId), UriKind.Relative), Culture);

            tournamentReq.Cookies.Add(lobbyCon.GetCookies());

            LilaResponse roundRes = await tournamentReq.Get(LilaRequest.ContentType.Html);

            if (roundRes == null)
            {
                log.Error("Failed to join tournament at {0}", tournamentId);
                return(null);
            }

            string html = await roundRes.ReadAsync();

            const string id = "lichess.tournament = ";

            int roundBootIndex = html.IndexOf(id);

            if (roundBootIndex == -1)
            {
                return(null);
            }

            string json = StringEngine.GetInside(html, roundBootIndex + id.Length);

            if (json == null)
            {
                log.Error("Failed to parse tournament json data.");
                return(null);
            }

            return(JsonConvert.DeserializeObject <Tournament>(json, jsonSettings));
        }
Exemple #6
0
            public bool Next(System.Threading.CancellationToken ct, out System.Collections.Generic.IEnumerable <IArticle> elems)
            {
                WebClientEx client = new WebClientEx();

                string result = client.DownloadStringAsyncTask(
                    new Uri(string.Format("http://clien.career.co.kr/cs2/bbs/board.php?bo_table={0}&page={1}&{2}", id, page + 1, DateTime.Now.Ticks), UriKind.Absolute),
                    ct).GetResult();

                StringEngine se = new StringEngine(result);

                List <IArticle> articles = new List <IArticle>();
                bool            curBool  = true;

                while (true)
                {
                    Match match;
                    if (!se.Next(new Regex("<tr class=\"mytr\">"), out match))
                    {
                        break;
                    }

                    string line;
                    if (!se.GetNextLine(out line))
                    {
                        continue;
                    }

                    match = Regex.Match(line, @"<td>(\d+)</td>");
                    if (!match.Success)
                    {
                        continue;
                    }

                    string articleID    = match.Groups[1].Value;
                    int    curArticleID = int.Parse(articleID);

                    if (recentArticle <= curArticleID)
                    {
                        continue;
                    }

                    recentArticle = curArticleID;

                    ClienArticle article = new ClienArticle(board, articleID);

                    article.HasImage = curBool;
                    curBool          = !curBool;

                    // 글 제목과 댓글 개수
                    if (!se.GetNextLine(out line))
                    {
                        continue;
                    }
                    match = Regex.Match(line, @"<a[^>]*?>(.*?)</a>\s*(<span>\[(\d+)\]</span>)?");
                    if (!match.Success)
                    {
                        continue;
                    }

                    article.Title = match.Groups[1].Value;
                    if (match.Groups[3].Success)
                    {
                        article.CommentCount = int.Parse(match.Groups[3].Value);
                    }
                    else
                    {
                        article.CommentCount = 0;
                    }

                    // 이름
                    if (!se.GetNextLine(out line))
                    {
                        continue;
                    }
                    match = Regex.Match(line, @"<span class='member'>(.*?)</span>");
                    if (match.Success)
                    {
                        article.Name = match.Groups[1].Value;
                    }
                    else
                    {
                        match = Regex.Match(line, @"<img src='/cs2/data/member/.*?/(.*?).gif");
                        if (!match.Success)
                        {
                            continue;
                        }

                        article.Name = match.Groups[1].Value;
                    }

                    // 시간
                    if (!se.GetNextLine(out line))
                    {
                        continue;
                    }
                    match = Regex.Match(line, "<span title=\"([^\"]*?)\">");
                    if (!match.Success)
                    {
                        continue;
                    }

                    article.Date = DateTime.Parse(match.Groups[1].Value);



                    articles.Add(article);
                }

                elems = articles;
                page++;
                return(true);
            }
Exemple #7
0
        // 글의 텍스트와 코멘트를 읽어서 채워넣는다
        private bool UpdateArticleTextAndComments(string input, out List <Picture> pictures, out List <DCInsideComment> comments, out string commentUserID, out string text)
        {
            text          = string.Empty;
            pictures      = new List <Picture>();
            comments      = new List <DCInsideComment>();
            commentUserID = string.Empty;

            // 1. 이미지들을 찾는다
            // <img id='dc_image_elm_*.. src="()"/> 이미지
            // <img  id=dc_image_elm0 src='http://dcimg1.dcinside.com/viewimage.php?id=windowsphone&no=29bcc427b78a77a16fb3dab004c86b6fc3a0be4a5f9fd1a8cc77865e83c2029da6f5d553d560d273a5d0802458ed844942b60ffcef4cc95a9e820f3d0eb76388a4ded971bc29b6cc1fd6a780e7e52f627fdf1b9b6a40491c7fa25f4acaa4663f080794f8abd4e01cc6&f_no=7bee837eb38760f73f8081e240847d6ecaa51e16c7795ecc2584471ef43a7f730867c7d42ef66cf9f0827af5263d'width=550  /></a><br/> <br/>        </p>

            StringEngine se = new StringEngine(input);

            Match match;

            while (se.Next(DCRegexManager.TextImage, out match))
            {
                string url       = match.Groups[1].Value;
                string browseurl = url;

                int fIdx = url.IndexOf("&f_no=");
                if (fIdx != -1)
                {
                    url = url.Substring(0, fIdx);
                }

                pictures.Add(
                    new Picture(url, browseurl, "http://gall.dcinside.com"));
            }

            // div를 개수를 세서 안에 있는 div
            if (!se.Next(DCRegexManager.TextStart, out match))
            {
                return(false);
            }

            int start = se.Cursor;
            int count = 1;

            while (count > 0)
            {
                if (!se.Next(DCRegexManager.TextDIV, out match))
                {
                    break;
                }

                if (match.Groups[1].Value.Length != 0)
                {
                    count++;
                }
                else
                {
                    count--;
                    if (count == 0)
                    {
                        break;
                    }
                }
            }

            if (count != 0)
            {
                text = input.Substring(start).Trim();
                return(true);
            }
            else
            {
                text = input.Substring(start, match.Index - start).Trim();
            }

            comments.Clear();

            // 댓글 가져오기
            while (se.Next(DCRegexManager.CommentStart, out match))
            {
                string line;

                if (!se.GetNextLine(out line))
                {
                    continue;
                }
                match = DCRegexManager.CommentName.Match(line);
                if (!match.Success)
                {
                    continue;
                }

                var cmt = new DCInsideComment();
                cmt.Level = 0;
                cmt.Name  = match.Groups[2].Value.Trim();

                if (line.Contains("gallercon.gif"))
                {
                    cmt.MemberStatus = MemberStatus.Fix;
                }
                else if (line.Contains("gallercon1.gif"))
                {
                    cmt.MemberStatus = MemberStatus.Default;
                }
                else
                {
                    cmt.MemberStatus = MemberStatus.Anonymous;
                }

                // 내용
                if (!se.Next(DCRegexManager.CommentText, out match))
                {
                    continue;
                }
                cmt.Text = match.Groups[1].Value.Trim();

                comments.Add(cmt);
            }

            // CommentUserID 얻기
            if (se.Next(DCRegexManager.TextCommentUserID, out match))
            {
                commentUserID = match.Groups[1].Value;
            }

            return(true);
        }
Exemple #8
0
        public bool GetText(System.Threading.CancellationToken ct, out string text)
        {
            text = string.Empty;
            WebClientEx client = new WebClientEx();

            var result = client.DownloadStringAsyncTask(
                new Uri(string.Format("http://clien.career.co.kr/cs2/bbs/board.php?bo_table={0}&wr_id={1}", board.ID, id), UriKind.Absolute),
                ct).GetResult();

            StringEngine se = new StringEngine(result);

            Match match;

            pictures.Clear();

            if (se.Next(new Regex("<div class=\"attachedImage\"><img.*?src=(?<quote>'|\")(?<url>.*?)\\k<quote>"), out match))
            {
                Picture pic = new Picture(string.Format("http://clien.career.co.kr/cs2/bbs/{0}", match.Groups["url"].Value), Uri.ToString());

                pictures.Add(pic);
                HasImage = true;
            }


            var textRegex = new Regex("<span id=\"writeContents\"(.*?)>");


            if (!se.Next(textRegex, out match))
            {
                return(false);
            }

            int start    = se.Cursor;
            int count    = 1;
            var divRegex = new Regex("(<\\s*span[^>]*>)|(<\\s*/\\s*span\\s*>)", RegexOptions.IgnoreCase); // div 또는 /div

            while (count > 0)
            {
                if (!se.Next(divRegex, out match))
                {
                    break;
                }

                if (match.Groups[1].Value.Length != 0)
                {
                    count++;
                }
                else
                {
                    count--;
                    if (count == 0)
                    {
                        break;
                    }
                }
            }

            if (count != 0)
            {
                text = result.Substring(start).Trim();
                return(true);
            }
            else
            {
                text = result.Substring(start, match.Index - start).Trim();
            }

            comments.Clear();

            // 댓글 파트
            while (se.Next(new Regex("<ul class=\"reply_info\">"), out match))
            {
                string line;
                if (!se.GetNextLine(out line))
                {
                    continue;
                }

                ClienComment comment = new ClienComment();

                comment.Level = 0;

                if (line.Contains("<img src=\"../skin/board/cheditor/img/blet_re2.gif\">"))
                {
                    comment.Level = 1;
                }

                match = Regex.Match(line, "<img src='/cs2/data/member/.*?/(.*?).gif");
                if (match.Success)
                {
                    comment.Name = match.Groups[1].Value;
                }
                else
                {
                    match = Regex.Match(line, @"<span class='member'>(.*?)</span>");
                    if (match.Success)
                    {
                        comment.Name = match.Groups[1].Value;
                    }
                    else
                    {
                        continue;
                    }
                }

                if (!se.Next(new Regex("<div class=\"reply_content\">"), out match))
                {
                    continue;
                }

                StringBuilder sb = new StringBuilder();

                while (se.GetNextLine(out line))
                {
                    match = Regex.Match(line, "(.*?)<span id='edit");
                    if (match.Success)
                    {
                        sb.Append(match.Groups[1].Value);
                        break;
                    }

                    sb.Append(line);
                }

                comment.Text = sb.ToString().Trim();
                comments.Add(comment);
            }

            return(true);
        }