Пример #1
0
        public AtomicUser GetUserInformation(int userId)
        {
            try {
                var user = new AtomicUser(userId);
                var rawUserPage = GetRawAtomicUserData(user.ProfileUrl);

                var enc = new ASCIIEncoding();
                var userPage = new HtmlDocument();
                userPage.Load(new StreamReader(new MemoryStream(enc.GetBytes(rawUserPage))));
                var root = userPage.DocumentNode;

                // Extract user information from the page.
                //<div class='pp-name'>
                //    <table cellpadding='0' cellspacing='0' width='100%'>
                //    <tr>
                //        <td width='1%'><img src='http://forums.atomicmpc.com.au/uploads/av-40858.jpg' border='0' width='78' height='78' alt='' /></td>
                //        <td width='98%' style='padding-left:10px'>
                //            <h3 style='font-size:20px'>Jeruselem</h3>
                //            <strong>Atomican</strong>
                //            <p></p>
                //        </td>

                //    </tr>
                //    </table>
                //</div>
                var userDetailsNode = root.SelectSingleNode("//div[@class='pp-name']");
                if (userDetailsNode != null) {
                    // Don't need to have an avatar.
                    var imgNode = userDetailsNode.Descendants("img").FirstOrDefault();
                    if (imgNode != null) user.ImageUrl = imgNode.GetAttributeValue("src", "");

                    var nameNode = userDetailsNode.Descendants("h3").FirstOrDefault();
                    if (nameNode != null) user.Name = nameNode.InnerText;

                    var specialRankNode = userDetailsNode.Descendants("strong").FirstOrDefault();
                    if (specialRankNode != null) user.SpecialRank = specialRankNode.InnerText;
                }

                //<!-- Personal Info -->
                //<div class='subtitle'>Personal Info</div>
                //<div class='row1' style='padding:6px; padding-left:10px'>Jeruselem</div>
                //<div class='row1' style='padding:6px; padding-left:10px'>Champion</div>
                var info = root.SelectNodes("//comment()");
                foreach (HtmlNode node in info) {
                    if (node.InnerHtml == "<!-- Personal Info -->") {
                        user.Rank =
                            node.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
                    }
                }

                return user;
            } catch {}

            return null;
        }
Пример #2
0
        public static AtomicUserViewModel Create(AtomicUser user)
        {
            var userViewModel = new AtomicUserViewModel
            {
                ImageUrl = user.ImageUrl,
                UserId = user.UserId,
                Name = user.Name,
                Rank = user.Rank,
                SpecialRank = user.SpecialRank,
                ProfileUrl = user.ProfileUrl
            };

            return userViewModel;
        }