Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Net;
- using System.Xml.Linq;
- using System.Xml.XPath;
- namespace SharpDIC.Entities
- {
- /// <summary>
- /// Represents a user on the Dream.In.Code website.
- /// </summary>
- public class User
- {
- /********************************************************************************
- * Some of these attributes aren't even used. The API doesn't provide them yet, *
- * so I'll have to scrape the information from the HTML itself. Still thinking *
- * about how to tackle this. *
- * *
- * Author: Sergio Tapia *
- * Website: http://www.alphaot.com *
- * ******************************************************************************/
- #region "Attributes"
- public string ID { get; set; }
- public string Name { get; set; }
- public string Rating { get; set; }
- public string Photo { get; set; }
- public string LastActive { get; set; }
- public string Location { get; set; }
- public string Birthday { get; set; }
- public string Age { get; set; }
- public string Gender { get; set; }
- public string Email { get; set; }
- public string Title { get; set; }
- public string Reputation { get; set; }
- public string DreamKudos { get; set; }
- public string Group { get; set; }
- public string Posts { get; set; }
- public string PostsPerDay { get; set; }
- public string MostActiveIn { get; set; }
- public string JoinDate { get; set; }
- public string ProfileViews { get; set; }
- public string FavoriteOS { get; set; }
- public string FavoriteBrowser { get; set; }
- public string FavoriteProcessor { get; set; }
- public string FavoriteConsole { get; set; }
- public List<Visitor> Visitors { get; set; }
- public List<Friend> Friends { get; set; }
- public List<Comment> Comments { get; set; }
- public string ProgrammingLanguages { get; set; }
- public string AIM { get; set; }
- public string MSN { get; set; }
- public string Website { get; set; }
- public string ICQ { get; set; }
- public string Yahoo { get; set; }
- public string Jabber { get; set; }
- public string Skype { get; set; }
- public string LinkedIn { get; set; }
- public string Facebook { get; set; }
- public string Twitter { get; set; }
- public string XFire { get; set; }
- #endregion
- /// <summary>
- /// Load a user by providing an ID.
- /// </summary>
- /// <param name="ID">A user's individual ID number.</param>
- public User(string ID)
- {
- XDocument xmlResponse = GetUserXMLResponse(ID);
- LoadGeneralInformation(xmlResponse.Element("ipb").Element("profile"));
- LoadContactInformation(xmlResponse.Element("ipb").Element("profile").Element("contactinformation"));
- LoadLatestVisitors(xmlResponse.Element("ipb").Element("profile").Element("latestvisitors"));
- LoadFriends(xmlResponse.Element("ipb").Element("profile").Element("friends"));
- LoadComments(xmlResponse.Element("ipb").Element("profile").Element("comments"));
- }
- #region "Loading Methods - give them XML and they'll do the job."
- private void LoadGeneralInformation(XElement profileXML)
- {
- this.ID = (string)profileXML.Element("id");
- this.Name = (string)profileXML.Element("name");
- this.Rating = (string)profileXML.Element("rating");
- this.Photo = (string)profileXML.Element("photo");
- this.Reputation = (string)profileXML.Element("reputation");
- this.Group = (string)profileXML.Element("group").Element("span");
- this.Posts = (string)profileXML.Element("posts");
- this.PostsPerDay = (string)profileXML.Element("postsperday");
- this.JoinDate = (string)profileXML.Element("joined");
- this.ProfileViews = (string)profileXML.Element("views");
- this.LastActive = (string)profileXML.Element("lastactive");
- this.Location = (string)profileXML.Element("location");
- this.Title = (string)profileXML.Element("title");
- this.Age = (string)profileXML.Element("age");
- this.Birthday = (string)profileXML.Element("birthday");
- this.Gender = (string)profileXML.Element("gender").Element("gender").Element("value");
- }
- private void LoadContactInformation(XElement contactXML)
- {
- this.AIM = (string)contactXML.XPathSelectElement("contact[title='AIM']/value");
- this.MSN = (string)contactXML.XPathSelectElement("contact[title='MSN']/value");
- this.Website = (string)contactXML.XPathSelectElement("contact[title='Website URL']/value");
- this.ICQ = (string)contactXML.XPathSelectElement("contact[title='ICQ']/value");
- this.Yahoo = (string)contactXML.XPathSelectElement("contact[title='Yahoo']/value");
- this.Jabber = (string)contactXML.XPathSelectElement("contact[title='Jabber']/value");
- this.Skype = (string)contactXML.XPathSelectElement("contact[title='Skype']/value");
- this.LinkedIn = (string)contactXML.XPathSelectElement("contact[title='LinkedIn']/value");
- this.Facebook = (string)contactXML.XPathSelectElement("contact[title='Facebook']/value");
- this.Twitter = (string)contactXML.XPathSelectElement("contact[title='Twitter']/value");
- this.XFire = (string)contactXML.XPathSelectElement("contact[title='Xfire']/value");
- }
- private void LoadLatestVisitors(XElement visitorsXML)
- {
- this.Visitors = (from visitor in visitorsXML.Descendants("user")
- select new Visitor()
- {
- ID = visitor.Element("id").Value,
- Name = visitor.Element("name").Value,
- Url = visitor.Element("url").Value,
- Photo = visitor.Element("photo").Value,
- Visited = visitor.Element("visited").Value,
- }).ToList();
- }
- private void LoadFriends(XElement friendsXML)
- {
- this.Friends = (from friend in friendsXML.Descendants("user")
- select new Friend()
- {
- ID = friend.Element("id").Value,
- Name = friend.Element("name").Value,
- Url = friend.Element("url").Value,
- Photo = friend.Element("photo").Value
- }).ToList();
- }
- private void LoadComments(XElement commentsXML)
- {
- this.Comments = (from comment in commentsXML.Descendants("comment")
- select new Comment()
- {
- ID = comment.Element("id").Value,
- Text = comment.Element("text").Value,
- Date = comment.Element("date").Value,
- UserWhoPosted = new Friend()
- {
- ID = comment.Element("user").Element("id").Value,
- Name = comment.Element("user").Element("name").Value,
- Url = comment.Element("user").Element("url").Value,
- Photo = comment.Element("user").Element("photo").Value
- }
- }).ToList();
- }
- #endregion
- private XDocument GetUserXMLResponse(string ID)
- {
- WebClient webClient = new WebClient();
- string htmlSource = webClient.DownloadString(new Uri(String.Format("http://www.dreamincode.net/forums/xml.php?showuser={0}", ID)));
- return XDocument.Parse(htmlSource);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement