/// <summary> /// Creates a thread object by a thread id /// </summary> /// <param name="_threadId">Thread id</param> public Thread(int _threadId) { flags = new Dictionary<string, bool>(5); string xmlFile = $"http://forum.mods.de/bb/xml/thread.php?TID={_threadId}"; var xmlDoc = Helper.LoadXml(xmlFile); currentUserId = Convert.ToInt32(xmlDoc.DocumentElement.Attributes["current-user-id"].Value); title = xmlDoc.DocumentElement.ChildNodes[0].InnerText; subtitle = xmlDoc.DocumentElement.ChildNodes[1].InnerText; numberOfReplies = Convert.ToInt32(xmlDoc.DocumentElement.ChildNodes[2].Attributes["value"].Value); numberOfHits = Convert.ToInt32(xmlDoc.DocumentElement.ChildNodes[3].Attributes["value"].Value); try { numberOfPages = Convert.ToInt32(xmlDoc.DocumentElement.ChildNodes[4].Attributes["value"].Value); } catch (NullReferenceException) { numberOfPages = 0; } foreach (XmlNode item in xmlDoc.DocumentElement.ChildNodes[5].ChildNodes) { int state = Convert.ToInt32(item.Attributes["value"].Value); Flags.Add(item.Name, Convert.ToBoolean(state)); } try { inBoardId = Convert.ToInt32(xmlDoc.DocumentElement.ChildNodes[6].Attributes["id"].Value); } catch (NullReferenceException) { inBoardId = 0; } XmlNode firstPostNode = xmlDoc.DocumentElement.ChildNodes[7].ChildNodes[0]; int threadStarterId; string threadStarterName; try { threadStarterId = Convert.ToInt32(firstPostNode.ChildNodes[0].Attributes["id"].Value); threadStarterName = firstPostNode.ChildNodes[0].InnerText; } catch (NullReferenceException) { threadStarterId = 0; threadStarterName = string.Empty; } author = new User(threadStarterId, threadStarterName); double unixTimeStamp; try { unixTimeStamp = Convert.ToInt64(firstPostNode.ChildNodes[1].Attributes["timestamp"].Value); } catch (NullReferenceException) { unixTimeStamp = 0; } date = Helper.UnixTimeStampToDateTime(unixTimeStamp); threadId = _threadId; try { inBoardId = Convert.ToInt32(firstPostNode.ChildNodes[3].Attributes["id"].Value); } catch (NullReferenceException) { inBoardId = 0; } }
/// <summary> /// Creates a edit object /// </summary> /// <param name="_user">User who wrote the edit</param> /// <param name="_unixTimeStamp">Unix timestamp of the forum</param> public Edit(User _user, double _unixTimeStamp) { user = _user; date = Helper.UnixTimeStampToDateTime(_unixTimeStamp); }
public Post(int _id, int _threadId, int _boardId, int _page, int _offset, User _author, DateTime _creationDate, string _message, string _title, int _editedCount, Edit _lastEdit) { id = _id; inThreadId = _threadId; inBoardId = _boardId; page = _page; offset = _offset; author = _author; date = _creationDate; message = _message; title = _title; editedCount = _editedCount; lastEdit = _lastEdit; }
public static List<Post> GetPostsOfPage(int _threadId, int _pageId) { int inThreadId = _threadId; string xmlFile = $"http://forum.mods.de/bb/xml/thread.php?TID={_threadId}&page={_pageId}"; var xmlDoc = Helper.LoadXml(xmlFile); if (xmlDoc != null) { // if logged in, it's ChildNodes[9], not ChildNodes[8] int page = _pageId; int offset = Convert.ToInt32(xmlDoc.DocumentElement.ChildNodes[8].Attributes["offset"].Value); int inBoardId = Convert.ToInt32(xmlDoc.DocumentElement.ChildNodes[6].Attributes["id"].Value); int postsOnPage = xmlDoc.DocumentElement.ChildNodes[8].ChildNodes.Count; List<Post> posts = new List<Post>(postsOnPage); foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes[8]) { int id = Convert.ToInt32(node.Attributes["id"].Value); bool banned; if (node.ChildNodes[0].Attributes.Count > 2) { try { banned = Convert.ToBoolean(Convert.ToInt32(node.ChildNodes[0].Attributes["locked"].Value)); } catch (NullReferenceException) { banned = false; } } else { banned = false; } int avatarId; string avatarUrl; if (node.ChildNodes[3].Attributes.Count > 0) { try { avatarId = Convert.ToInt32(node.ChildNodes[3].Attributes["id"].Value); avatarUrl = node.ChildNodes[3].InnerText; } catch (NullReferenceException) { avatarId = -1; avatarUrl = String.Empty; } } else { avatarId = -1; avatarUrl = string.Empty; } int authorId = Convert.ToInt32(node.ChildNodes[0].Attributes["id"].Value); int authorGroupId; if (node.ChildNodes[0].Attributes.Count > 1) { try { authorGroupId = Convert.ToInt32(node.ChildNodes[0].Attributes["group-id"].Value); } catch (NullReferenceException) { authorGroupId = -1; } } else { authorGroupId = -1; } string authorName = node.ChildNodes[0].InnerText; Avatar avatar = new Avatar(avatarId, avatarUrl); User author = new User(authorId, authorName, authorGroupId, avatar, banned); double unixTimeStamp = Convert.ToInt32(node.ChildNodes[1].Attributes["timestamp"].Value); DateTime creationDate = Helper.UnixTimeStampToDateTime(unixTimeStamp); int editedCount = Convert.ToInt32(node.ChildNodes[2].ChildNodes[0].Attributes["count"].Value); string message = node.ChildNodes[2].ChildNodes[1].InnerText; string title = node.ChildNodes[2].ChildNodes[2].InnerText; if (editedCount > 0) { string editUserName = node.ChildNodes[2].ChildNodes[0].ChildNodes[0].ChildNodes[0].InnerText; int editUserId = Convert.ToInt32( node.ChildNodes[2].ChildNodes[0].ChildNodes[0].ChildNodes[0].Attributes["id"].Value); double editTimeStamp = Convert.ToInt32( node.ChildNodes[2].ChildNodes[0].ChildNodes[0].ChildNodes[1].Attributes["timestamp"].Value); User editUser = new User(editUserId, editUserName); Edit lastEdit = new Edit(editUser, editTimeStamp); posts.Add(new Post(id, inThreadId, inBoardId, page, offset, author, creationDate, message, title, editedCount, lastEdit)); } else { posts.Add(new Post(id, inThreadId, inBoardId, page, offset, author, creationDate, message, title, editedCount)); } } return posts; } return null; }
public Post(int _id, int _threadId) { id = _id; inThreadId = _threadId; string xmlFile = $"http://forum.mods.de/bb/xml/thread.php?TID={_threadId}&PID={_id}"; var xmlDoc = Helper.LoadXml(xmlFile); if (xmlDoc != null) { // if logged in, it's ChildNodes[9], not ChildNodes[8] page = Convert.ToInt32(xmlDoc.DocumentElement.ChildNodes[8].Attributes["page"].Value); offset = Convert.ToInt32(xmlDoc.DocumentElement.ChildNodes[8].Attributes["offset"].Value); inBoardId = Convert.ToInt32(xmlDoc.DocumentElement.ChildNodes[6].Attributes["id"].Value); foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes[8]) { if (_id == Convert.ToInt32(node.Attributes["id"].Value)) { bool banned; try { banned = Convert.ToBoolean(Convert.ToInt32(node.ChildNodes[0].Attributes["locked"].Value)); } catch (NullReferenceException) { banned = false; } int avatarId = Convert.ToInt32(node.ChildNodes[3].Attributes["id"].Value); string avatarUrl = node.ChildNodes[3].InnerText; int authorId = Convert.ToInt32(node.ChildNodes[0].Attributes["id"].Value); int authorGroupId = Convert.ToInt32(node.ChildNodes[0].Attributes["group-id"].Value); string authorName = node.ChildNodes[0].InnerText; Avatar avatar = new Avatar(avatarId, avatarUrl); author = new User(authorId, authorName, authorGroupId, avatar, banned); double unixTimeStamp = Convert.ToInt32(node.ChildNodes[1].Attributes["timestamp"].Value); date = Helper.UnixTimeStampToDateTime(unixTimeStamp); editedCount = Convert.ToInt32(node.ChildNodes[2].ChildNodes[0].Attributes["count"].Value); if (EditedCount > 0) { string editUserName = node.ChildNodes[2].ChildNodes[0].ChildNodes[0].ChildNodes[0].InnerText; int editUserId = Convert.ToInt32( node.ChildNodes[2].ChildNodes[0].ChildNodes[0].ChildNodes[0].Attributes["id"].Value); double editTimeStamp = Convert.ToInt32( node.ChildNodes[2].ChildNodes[0].ChildNodes[0].ChildNodes[1].Attributes["timestamp"] .Value); User editUser = new User(editUserId, editUserName); lastEdit = new Edit(editUser, editTimeStamp); } message = node.ChildNodes[2].ChildNodes[1].InnerText; title = node.ChildNodes[2].ChildNodes[2].InnerText; break; } } } }