Esempio n. 1
0
        public async Task <List <ForumUserSearchEntity> > GetUsernames(string username)
        {
            // Gets the fake 'JSON' html
            WebManager.Result result = await _webManager.GetData(string.Format(Constants.SEARCH_URL, username));

            // TODO: if result fails, alert the user!
            string fakeJsonHtml = result.Document.DocumentNode.OuterHtml;

            // Parses the fake json into an array of string. We will parse this further into search user objects.
            string[] userList = fakeJsonHtml.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
            // Now parse the user list into the username and ID.
            var userAndIdList = userList.Select(node => node.Split(new string[] { "<>" }, StringSplitOptions.None));

            // Convert it into a list of ForumUserSearch entities.
            // TODO: Handle errors if we don't get the expected list.
            return((from user in userAndIdList where user.Length == 2 && !string.IsNullOrEmpty(user[0]) && !string.IsNullOrEmpty(user[1]) select new ForumUserSearchEntity(user[0], Convert.ToInt64(user[1]))).ToList());
        }
Esempio n. 2
0
        public async Task <string> GetPost(int postId)
        {
            try
            {
                string            url    = string.Format(Constants.SHOW_POST, postId);
                WebManager.Result result = await _webManager.GetData(url);

                HtmlDocument doc        = result.Document;
                HtmlNode     threadNode =
                    doc.DocumentNode.Descendants("div")
                    .FirstOrDefault(node => node.GetAttributeValue("id", string.Empty).Contains("thread"));
                HtmlNode postNode =
                    threadNode.Descendants("table")
                    .FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("post"));
                var post = new ForumPostEntity();
                post.Parse(postNode);
                return(await HtmlFormater.FormatPostHtml(post));
            }
            catch (Exception)
            {
                return(null);
            }
        }