/// <summary> /// TODO : Add summary here. /// </summary> /// <param name="request"></param> /// <param name="result"></param> public bool SendEditFolderRequest(PrivateMessageFolderEditor request) { string url = string.Format("{0}/{1}", CoreConstants.BASE_URL, CoreConstants.PRIVATE_MESSAGE_URI); string postData = request.GenerateRequestData(); return(this.SendPost(postData, url)); }
/// <summary> /// TODO : Add summary here. /// </summary> /// <param name="result"></param> public PrivateMessageFolderEditor BeginEditFolderRequest() { var web = new AwfulWebClient(); var url = string.Format("{0}/{1}?action=editfolders", CoreConstants.BASE_URL, CoreConstants.PRIVATE_MESSAGE_URI); var doc = web.FetchHtml(url).ToHtmlDocument(); PrivateMessageFolderEditor editor = null; if (doc != null) { editor = PrivateMessageParser.ParseEditFolderPage(doc); } return(editor); }
/// <summary> /// /// </summary> /// <param name="htmlDocument"></param> /// <returns></returns> public static PrivateMessageFolderEditor ParseEditFolderPage(HtmlDocument htmlDocument) { PrivateMessageFolderEditor request = null; var top = htmlDocument.DocumentNode; var inputArray = top.Descendants("input"); if (inputArray != null) { request = new PrivateMessageFolderEditor(); int highest = 0; var highestNode = inputArray .Where(node => node.GetAttributeValue("name", "").Equals("highest")) .FirstOrDefault(); if (highestNode != null) { int.TryParse(highestNode.GetAttributeValue("value", ""), out highest); } request.HighestIndex = highest; var folderArray = inputArray.Where(node => node.GetAttributeValue("name", "").Contains("folderlist")); if (folderArray != null) { int maxFolderListIndex = 0; foreach (var item in folderArray) { string keyString = item.GetAttributeValue("name", ""); string value = item.GetAttributeValue("value", ""); keyString = keyString.Replace("folderlist", ""); keyString = keyString.Replace("[", ""); keyString = keyString.Replace("]", ""); int key = 0; int.TryParse(keyString, out key); request.FolderTable.Add(key, value); maxFolderListIndex = Math.Max(maxFolderListIndex, key); } request.NewFolderFieldIndex = maxFolderListIndex; } } return(request); }
/// <summary> /// /// </summary> /// <param name="htmlDocument"></param> /// <returns></returns> public static PrivateMessageFolderEditor ParseEditFolderPage(HtmlDocument htmlDocument) { PrivateMessageFolderEditor request = null; var top = htmlDocument.DocumentNode; var inputArray = top.Descendants("input"); if (inputArray != null) { request = new PrivateMessageFolderEditor(); int highest = 0; var highestNode = inputArray .Where(node => node.GetAttributeValue("name", "").Equals("highest")) .FirstOrDefault(); if (highestNode != null) { int.TryParse(highestNode.GetAttributeValue("value", ""), out highest); } request.HighestIndex = highest; var folderArray = inputArray.Where(node => node.GetAttributeValue("name", "").Contains("folderlist")); if (folderArray != null) { int maxFolderListIndex = 0; foreach (var item in folderArray) { string keyString = item.GetAttributeValue("name", ""); string value = item.GetAttributeValue("value", ""); keyString = keyString.Replace("folderlist", ""); keyString = keyString.Replace("[", ""); keyString = keyString.Replace("]", ""); int key = 0; int.TryParse(keyString, out key); request.FolderTable.Add(key, value); maxFolderListIndex = Math.Max(maxFolderListIndex, key); } request.NewFolderFieldIndex = maxFolderListIndex; } } return request; }
/// <summary> /// TODO : Add summary here. /// </summary> /// <param name="request"></param> /// <param name="result"></param> public bool SendEditFolderRequest(PrivateMessageFolderEditor request) { string url = string.Format("{0}/{1}", CoreConstants.BASE_URL, CoreConstants.PRIVATE_MESSAGE_URI); string postData = request.GenerateRequestData(); return this.SendPost(postData, url); }